def test_build_flow_method_in_scripts(self): """Testing build_flow method in all scripts in abipy/data/runs""" parser = flowtk.build_flow_main_parser() import importlib count, errors = 0, [] for fname in os.listdir(root): if not (fname.endswith(".py") and fname.startswith("run_")): continue count += 1 s = "abipy.data.runs." + fname.replace(".py", "") module = importlib.import_module(s) # flow will be produced in a temporary workdir. workdir = tempfile.mkdtemp(prefix='flow_' + os.path.basename(fname)) options = parser.parse_args(["--workdir", workdir]) # Instantiate the manager. options.manager = flowtk.TaskManager.as_manager(options.manager) try: flow = module.build_flow(options) assert flow is not None flow.build_and_pickle_dump() except Exception: errors.append("file %s\n %s" % (s, self.straceback())) print("Tested ", count, "scripts") assert count > 0 if errors: for i, e in enumerate(errors): print(80 * "*") print(i, e) print(80 * "*") assert not errors
def test_build_flow_method_in_scripts(self): """Testing build_flow method in all scripts in abipy/data/runs""" parser = flowtk.build_flow_main_parser() import importlib count, errors = 0, [] for fname in os.listdir(root): if not (fname.endswith(".py") and fname.startswith("run_")): continue print("Testing:", fname) count += 1 s = "abipy.examples.flows." + fname.replace(".py", "") module = importlib.import_module(s) if hasattr(module, "exclude_py_versions"): if sys.version[0:3] in module.exclude_py_versions: warnings.warn("%s excludes python versions %s" % (s, str(module.exclude_py_versions))) continue # flow will be produced in a temporary workdir. workdir = tempfile.mkdtemp(prefix='flow_' + os.path.basename(fname)) options = parser.parse_args(["--workdir", workdir]) # Instantiate the manager. options.manager = flowtk.TaskManager.as_manager(options.manager) # Check if flow has requirements on the Abinit version. if hasattr(module, "minimum_abinit_version"): if not options.manager.abinit_build.version_ge( module.minimum_abinit_version): warnings.warn("%s requires %s but Abinit version: %s" % (s, module.minimum_abinit_version, options.manager.abinit_build.version)) continue try: flow = module.build_flow(options) assert flow is not None flow.build_and_pickle_dump() flow.show_status() #flow.make_scheduler().start() except Exception: errors.append("file %s\n %s" % (s, self.straceback())) print("Tested ", count, "scripts") assert count > 0 if errors: for i, e in enumerate(errors): print(80 * "*", file=sys.stderr) print(i, e, file=sys.stderr) print(80 * "*", file=sys.stderr) assert not errors
def test_build_flow_method_in_scripts(self): """Testing build_flow method in all scripts in abipy/data/runs""" parser = flowtk.build_flow_main_parser() import importlib count, errors = 0, [] for fname in os.listdir(root): if not (fname.endswith(".py") and fname.startswith("run_")): continue print("Testing:", fname) count += 1 s = "abipy.examples.flows." + fname.replace(".py", "") module = importlib.import_module(s) if hasattr(module, "exclude_py_versions"): if sys.version[0:3] in module.exclude_py_versions: warnings.warn("%s excludes python versions %s" % (s, str(module.exclude_py_versions))) continue # flow will be produced in a temporary workdir. workdir = tempfile.mkdtemp(prefix='flow_' + os.path.basename(fname)) options = parser.parse_args(["--workdir", workdir]) # Instantiate the manager. options.manager = flowtk.TaskManager.as_manager(options.manager) # Check if flow has requirements on the Abinit version. if hasattr(module, "minimum_abinit_version"): if not options.manager.abinit_build.version_ge(module.minimum_abinit_version): warnings.warn("%s requires %s but Abinit version: %s" % (s, module.minimum_abinit_version, options.manager.abinit_build.version)) continue try: flow = module.build_flow(options) assert flow is not None flow.build_and_pickle_dump() flow.show_status() #flow.make_scheduler().start() except Exception: errors.append("file %s\n %s" % (s, self.straceback())) print("Tested ", count, "scripts") assert count > 0 if errors: for i, e in enumerate(errors): print(80 * "*", file=sys.stderr) print(i, e, file=sys.stderr) print(80 * "*", file=sys.stderr) assert not errors
def test_flow_main(self): """Testing flow_main decorator.""" parser = flowtk.build_flow_main_parser() assert parser is not None #parser.parse_args("--help") @flowtk.flow_main def main(options): return flowtk.Flow.temporary_flow() mock = self.get_mock_module() with mock.patch('sys.argv', ["test_main.py", "prof", "--help"]): with self.assertRaises(SystemExit) as cm: main() assert cm.exception.code == 0
def test_flow_main(self): """Testing flow_main decorator.""" parser = flowtk.build_flow_main_parser() assert parser is not None #parser.parse_args("--help") @flowtk.flow_main def main(options): return flowtk.Flow.temporary_flow() mock = self.get_mock_module() with mock.patch('sys.argv', ["test_main.py", "prof", "--help"]): with self.assertRaises(SystemExit) as cm: main() assert cm.exception.code == 0
# Initialize the flow flow = flowtk.Flow(options.workdir, manager=options.manager) # Register the task. flow.register_relax_task(relax_inp) return flow # This block generates the thumbnails in the Abipy gallery. # You can safely REMOVE this part if you are using this script for production runs. if os.getenv("READTHEDOCS", False): __name__ = None import tempfile options = flowtk.build_flow_main_parser().parse_args( ["-w", tempfile.mkdtemp()]) #build_flow(options).plot_networkx(with_edge_labels=True, tight_layout=True) build_flow(options).graphviz_imshow() @flowtk.flow_main def main(options): """ This is our main function that will be invoked by the script. flow_main is a decorator implementing the command line interface. Command line args are stored in `options`. """ return build_flow(options) if __name__ == "__main__":
multi[1].set_vars( iscf=-2, tolwfr=1e-12, ) multi[1].set_kpath(ndivsm=8) gs_inp, nscf_inp = multi.split_datasets() return flowtk.BandStructureWork(gs_inp, nscf_inp) # This block generates the thumbnails in the Abipy gallery. # You can safely REMOVE this part if you are using this script for production runs. if os.getenv("GENERATE_SPHINX_GALLERY", False): __name__ = None import tempfile options = flowtk.build_flow_main_parser().parse_args(["-w", tempfile.mkdtemp()]) build_flow(options).plot_networkx(tight_layout=True) @flowtk.flow_main def main(options): """ This is our main function that will be invoked by the script. flow_main is a decorator implementing the command line interface. Command line args are stored in `options`. """ return build_flow(options) if __name__ == "__main__": sys.exit(main())
def get_options(self): from abipy.flowtk import build_flow_main_parser parser = build_flow_main_parser() return parser.parse_args("")