added and simplified test_w_assign.py
+import unittest
+import argparse
import os
import shutil
+
from h5diff import H5Diff
-import unittest
+
+from westpa.cli.tools.w_assign import entry_point
+from unittest import mock
-class Test_W_Assign(unittest.TestCase):
+class Test_W_Assign:
- test_name = 'W_ASSIGN'
+ def test_run_w_assign(self, ref_50iter):
- def test_run_w_assign(self):
- '''Testing if w_assign runs as expected and the assign.h5 file looks good.'''
+ with mock.patch(
+ target='argparse.ArgumentParser.parse_args',
+ return_value=argparse.Namespace(
+ verbosity='debug',
+ rcfile=self.cfg_filepath,
+ max_queue_length=None,
+ we_h5filename=self.h5_filepath,
+ construct_dataset=None,
+ dsspecs=None,
+ output='assign.h5',
+ subsample=None,
+ config_from_file=True,
+ scheme='TEST',
+ ),
+ ):
+ entry_point()
- ref_dir = os.path.join(os.path.dirname(__file__), '../refs')
- shutil.copy2(os.path.join(ref_dir, 'west_ref.cfg'), './west.cfg')
- shutil.copy2(os.path.join(ref_dir, 'west_ref.h5'), './west.h5')
- os.system('w_assign -W ./west.h5 --config-from-file --scheme TEST')
- assert os.path.isfile('./ANALYSIS/TEST/assign.h5'), "The assign.h5 file was not generated."
- diff = H5Diff(os.path.join(ref_dir, 'assign_ref.h5'), './ANALYSIS/TEST/assign.h5')
+ diff = H5Diff('./assign_ref.h5', './ANALYSIS/TEST/assign.h5')
diff.check()
+ # clean up
shutil.rmtree('ANALYSIS')
- os.remove('west.h5')
- os.remove('west.cfg')
