Esempio n. 1
0
def sfinit(tmpdir, copy_par_file):
    """
    Re-used function that will initate a SeisFlows3 working environment in
    sys modules
    :return:
    """
    copy_par_file
    os.chdir(tmpdir)
    with patch.object(sys, "argv", ["seisflows"]):
        sf = SeisFlows()
        sf._register(force=True)
    config.init_seisflows(check=False)

    return sf
Esempio n. 2
0
def test_register(tmpdir, par_file_dict, copy_par_file):
    """
    Test that the register function, which reads in PATHS and PARAMETERS
    works as expected, returning paths and parameters that we can read
    """
    copy_par_file
    os.chdir(tmpdir)

    with patch.object(sys, "argv", ["seisflows"]):
        sf = SeisFlows()
        assert (sf._paths is None)
        assert (sf._parameters is None)
        sf._register(force=True)

    # Check that paths and parameters have been set in sys.modules
    paths = sys.modules["seisflows_paths"]
    parameters = sys.modules["seisflows_parameters"]

    # Check one or two parameters have been set correctly
    assert (par_file_dict.LBFGSMAX == parameters.LBFGSMAX)
    path_check_full = os.path.abspath(par_file_dict.PATHS["SCRATCH"])
    assert (path_check_full == paths.SCRATCH)
Esempio n. 3
0
def test_config_logging(tmpdir, copy_par_file):
    """
    Test logging configuration to make sure we can print to file
    :param tmpdir:
    :return:
    """
    # Run init first to create a working state
    os.chdir(tmpdir)
    copy_par_file

    msg = "This is an example log that will be checked for test purposes"
    with patch.object(sys, "argv", ["seisflows"]):
        sf = SeisFlows()
        sf._register(force=True)
        sf._config_logging()
        logger.debug(msg)

    # Check that we created the log file and wrote the message in
    assert (os.path.exists(CFGPATHS.LOGFILE))
    with open(CFGPATHS.LOGFILE, "r") as f:
        lines = f.read()
    assert (msg in lines)
    assert ("DEBUG" in lines)  # levelname
    assert ("test_config_logging()" in lines)  # funcName