def test_load_modules(tmpdir, copy_par_file): """ Test if module loading from sys.modules works :param tmpdir: :return: """ # Run init first to create a working state os.chdir(tmpdir) copy_par_file # Create necessary paths to get past some assertion errors parameters = loadyaml("parameters.yaml") paths = parameters.pop("PATHS") for key in ["MODEL_INIT", "MODEL_TRUE"]: os.mkdir(paths[key]) with patch.object(sys, "argv", ["seisflows"]): sf = SeisFlows() sf.init() # Check a random parameter and then set it to something different preprocess = sys.modules["seisflows_preprocess"] assert (preprocess.misfit is None) preprocess.misfit = 1 # See if we can load modules and restore previous working state which # overwrites the previous operation sf._load_modules() assert (sys.modules["seisflows_preprocess"].misfit != 1)
def test_cmd_init(tmpdir, copy_par_file): """ Test 'seisflows init' command which instantiates a working directory and saves the active working state as pickle files :return: """ os.chdir(tmpdir) copy_par_file # Create necessary paths to get past some assertion errors parameters = loadyaml("parameters.yaml") paths = parameters.pop("PATHS") for key in ["MODEL_INIT", "MODEL_TRUE"]: os.mkdir(paths[key]) with patch.object(sys, "argv", ["seisflows"]): sf = SeisFlows() sf.init() for name in NAMES: assert (os.path.exists( os.path.join(paths["OUTPUT"], f"seisflows_{name}.p")))