示例#1
0
def test_gather_sources_and_dependencies():
    from tests.dependency_example import some_func

    main, sources, deps = gather_sources_and_dependencies(
        some_func.__globals__)
    assert isinstance(main, Source)
    assert isinstance(sources, set)
    assert isinstance(deps, set)
    assert main == Source.create(
        os.path.join(TEST_DIRECTORY, "dependency_example.py"))
    expected_sources = {
        Source.create(os.path.join(TEST_DIRECTORY, "__init__.py")),
        Source.create(os.path.join(TEST_DIRECTORY, "dependency_example.py")),
        Source.create(os.path.join(TEST_DIRECTORY, "foo", "__init__.py")),
        Source.create(os.path.join(TEST_DIRECTORY, "foo", "bar.py")),
    }
    assert sources == expected_sources

    assert PackageDependency.create(pytest) in deps
    assert PackageDependency.create(mock) in deps
    # If numpy is installed on the test system it will automatically be added
    # as an additional dependency, so test for that:
    if opt.has_numpy:
        assert PackageDependency.create(opt.np) in deps
        assert len(deps) == 3
    else:
        assert len(deps) == 2
示例#2
0
def test_gather_sources_and_dependencies(discover_sources, expected_sources):
    from tests.dependency_example import some_func
    from sacred import SETTINGS

    SETTINGS.DISCOVER_SOURCES = discover_sources

    main, sources, deps = gather_sources_and_dependencies(
        some_func.__globals__, save_git_info=False)
    assert isinstance(main, Source)
    assert isinstance(sources, set)
    assert isinstance(deps, set)
    assert main == Source.create(
        os.path.join(TEST_DIRECTORY, "dependency_example.py"))
    assert sources == expected_sources

    assert PackageDependency.create(pytest) in deps
    assert PackageDependency.create(mock) in deps
    # If numpy is installed on the test system it will automatically be added
    # as an additional dependency, so test for that:
    if opt.has_numpy:
        assert PackageDependency.create(opt.np) in deps
        assert len(deps) == 3
    else:
        assert len(deps) == 2

    # Reset to default to prevent side-effects
    SETTINGS.DISCOVER_SOURCES = "imported"
示例#3
0
def test_gather_sources_and_dependencies():
    from tests.dependency_example import some_func
    sources, deps = gather_sources_and_dependencies(some_func.__globals__)
    assert isinstance(sources, set)
    assert isinstance(deps, set)
    expected_sources = {
        Source.create('tests/__init__.py'),
        Source.create('tests/dependency_example.py'),
        Source.create('tests/foo/__init__.py'),
        Source.create('tests/foo/bar.py')
    }
    assert sources == expected_sources

    assert PackageDependency.create(pytest) in deps
    assert PackageDependency.create(mock) in deps
    # If numpy is installed on the test system it will automatically be added
    # as an additional dependency, so test for that:
    if opt.has_numpy:
        assert PackageDependency.create(opt.np) in deps
        assert len(deps) == 3
    else:
        assert len(deps) == 2
示例#4
0
def test_package_dependency_create_no_version():
    mod = mock.Mock(spec=[], __name__="testmod")
    pd = PackageDependency.create(mod)
    assert pd.name == "testmod"
    assert pd.version is None
示例#5
0
def test_package_dependency_create():
    mod = mock.Mock(spec=[], __version__='0.1.2', __name__='testmod')
    pd = PackageDependency.create(mod)
    assert pd.name == 'testmod'
    assert pd.version == '0.1.2'
示例#6
0
def test_package_dependency_to_tuple():
    mod = mock.Mock(spec=[], __version__='3.2.1', __name__='testmod')
    pd = PackageDependency.create(mod)
    assert pd.to_tuple() == ('testmod', '3.2.1')