Exemplo n.º 1
0
def test_caching():
    """should cache calls prior to logging"""
    LOGGER = CachingLogger(create_dir=True)
    LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
    assert ("sample-lf.fasta" in LOGGER._messages[-2]
            and "md5sum" in LOGGER._messages[-1])
    LOGGER.log_versions(["numpy"])
    assert "numpy==" in LOGGER._messages[-1]

    LOGGER.log_file_path = LOGFILE_NAME
    LOGGER.shutdown()
    try:
        shutil.rmtree(DIRNAME)
    except OSError:
        pass
Exemplo n.º 2
0
def test_tracks_versions_module():
    """should track version if package is a module"""
    LOGGER = CachingLogger(create_dir=True)
    LOGGER.log_file_path = os.path.join(LOGFILE_NAME)
    import numpy

    expect = "numpy==%s" % numpy.__version__
    LOGGER.log_versions(numpy)
    LOGGER.shutdown()
    del numpy
    with open(LOGFILE_NAME, "r") as infile:
        contents = "".join(infile.readlines())
        for line in contents.splitlines():
            if "version :" in line and "numpy" in line:
                assert expect in line, line
    try:
        os.remove(LOGFILE_NAME)
    except OSError:
        pass
Exemplo n.º 3
0
def test_tracks_versions_string():
    """should track version if package name is a string"""
    LOGGER = CachingLogger(create_dir=True)
    LOGGER.log_file_path = LOGFILE_NAME
    LOGGER.log_versions("numpy")
    LOGGER.shutdown()
    import numpy

    expect = "numpy==%s" % numpy.__version__
    del numpy
    with open(LOGFILE_NAME, "r") as infile:
        contents = "".join(infile.readlines())
        for line in contents.splitlines():
            if "version :" in line and "numpy" in line:
                assert expect in line, line

    try:
        shutil.rmtree(DIRNAME)
    except OSError:
        pass
Exemplo n.º 4
0
def test_tracks_versions_empty():
    """should track version of scitrack"""
    LOGGER = CachingLogger(create_dir=True)
    LOGGER.log_file_path = LOGFILE_NAME
    LOGGER.input_file(TEST_ROOTDIR / "sample-lf.fasta")
    LOGGER.log_versions()
    LOGGER.shutdown()
    contents = LOGFILE_NAME.read_text()
    for label in ["system_details", "python", "user", "command_string"]:
        assert contents.count(f"\t{label}") == 1, (
            label,
            contents.count(label),
        )
    for line in contents.splitlines():
        if "version :" in line:
            assert "==%s" % __version__ in line, line

    try:
        shutil.rmtree(DIRNAME)
    except OSError:
        pass
Exemplo n.º 5
0
def test_tracks_versions():
    """should track versions"""
    LOGGER = CachingLogger(create_dir=True)
    LOGGER.log_file_path = os.path.join(LOGFILE_NAME)
    LOGGER.input_file("sample.fasta")
    LOGGER.log_versions(["numpy"])
    LOGGER.shutdown()
    with open(LOGFILE_NAME, "r") as infile:
        contents = "".join(infile.readlines())
        for label in ["system_details", "python", "user", "command_string"]:
            assert contents.count(label) == 1, (label, contents.count(label))
        for line in contents.splitlines():
            if "version :" in line:
                if "numpy" not in line:
                    assert "==%s" % __version__ in line, line
                else:
                    assert "numpy" in line, line
        print("\n\n", contents)
    try:
        os.remove(LOGFILE_NAME)
    except OSError:
        pass