Updated test_w_assign to not use mock.patch
-import argparse
import shutil
from h5diff import H5Diff
-from westpa.cli.tools.w_assign import entry_point
-from unittest import mock
+from westpa.cli.tools import w_assign
+
+
+# Placeholder class that will set all kwargs as attributes
+class MockArgs:
+ def __init__(self, **kwargs):
+ self.__dict__.update(kwargs)
class Test_W_Assign:
def test_run_w_assign(self, ref_50iter):
- with mock.patch(
- target='argparse.ArgumentParser.parse_args',
- return_value=argparse.Namespace(
+ args = MockArgs(
verbosity='debug',
rcfile=self.cfg_filepath,
max_queue_length=None,
@@ -23,9 +25,24 @@ class Test_W_Assign:
subsample=None,
config_from_file=True,
scheme='TEST',
- ),
- ):
- entry_point()
+ )
+
+ # This basically some logic that's wrapped up in WESTTool.main() for convenience.
+ # It needs to be explicitly called like this because the args are captured and set in make_parser_and_process()
+ # which we don't want to call, because we don't want to make a parser.
+ # We just want to process the args that "would've" been captured if called from CLI.
+ tool = w_assign.WAssign()
+
+ # Prepare and instantiate work manager
+ tool.wm_env.process_wm_args(args)
+ tool.work_manager = tool.wm_env.make_work_manager()
+
+ tool.process_all_args(args)
+ with tool.work_manager:
+ if tool.work_manager.is_master:
+ tool.go()
+ else:
+ tool.work_manager.run()
diff = H5Diff('./assign_ref.h5', './ANALYSIS/TEST/assign.h5')
diff.check()
