コード例 #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
ファイル: test_ingredients.py プロジェクト: wecacuee/sacred
def test_add_source_file(ing):
    handle, f_name = tempfile.mkstemp(suffix='.py')
    f = os.fdopen(handle, "w")
    f.write("print('Hello World')")
    f.close()
    ing.add_source_file(f_name)
    assert Source.create(f_name) in ing.sources
    os.remove(f_name)
コード例 #4
0
ファイル: test_ingredients.py プロジェクト: pputzky/sacred
def test_add_source_file(ing):
    handle, f_name = tempfile.mkstemp(suffix='.py')
    f = os.fdopen(handle, "w")
    f.write("print('Hello World')")
    f.close()
    ing.add_source_file(f_name)
    assert Source.create(f_name) in ing.sources
    os.remove(f_name)
コード例 #5
0
    def add_source_file(self, filename):
        """
        Add a file as source dependency to this experiment/ingredient.

        :param filename: filename of the source to be added as dependency
        :type filename: str
        """
        self.sources.add(Source.create(filename))
コード例 #6
0
ファイル: ingredient.py プロジェクト: IDSIA/sacred
    def add_source_file(self, filename):
        """
        Add a file as source dependency to this experiment/ingredient.

        :param filename: filename of the source to be added as dependency
        :type filename: str
        """
        self.sources.add(Source.create(filename))
コード例 #7
0
ファイル: test_dependencies.py プロジェクト: jmrinaldi/sacred
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
コード例 #8
0
def test_custom_base_dir():
    from tests.basedir.my_experiment import some_func
    base_dir = os.path.abspath('tests')
    main, sources, deps = gather_sources_and_dependencies(some_func.__globals__, base_dir)
    assert isinstance(main, Source)
    assert isinstance(sources, set)
    assert isinstance(deps, set)
    assert main == Source.create('tests/basedir/my_experiment.py')
    expected_sources = {
        Source.create('tests/__init__.py'),
        Source.create('tests/basedir/__init__.py'),
        Source.create('tests/basedir/my_experiment.py'),
        Source.create('tests/foo/__init__.py'),
        Source.create('tests/foo/bar.py')
    }
    assert sources == expected_sources
コード例 #9
0
ファイル: test_dependencies.py プロジェクト: wecacuee/sacred
def test_custom_base_dir():
    from tests.basedir.my_experiment import some_func
    main, sources, deps = gather_sources_and_dependencies(
        some_func.__globals__, TEST_DIRECTORY)
    assert isinstance(main, Source)
    assert isinstance(sources, set)
    assert isinstance(deps, set)
    assert main == Source.create(
        os.path.join(TEST_DIRECTORY, 'basedir', 'my_experiment.py'))
    expected_sources = {
        Source.create(os.path.join(TEST_DIRECTORY, '__init__.py')),
        Source.create(os.path.join(TEST_DIRECTORY, 'basedir', '__init__.py')),
        Source.create(
            os.path.join(TEST_DIRECTORY, 'basedir', 'my_experiment.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
コード例 #10
0
def test_source_repr():
    s = Source.create(EXAMPLE_SOURCE)
    assert repr(s) == "<Source: {}>".format(os.path.abspath(EXAMPLE_SOURCE))
コード例 #11
0
ファイル: test_dependencies.py プロジェクト: jmrinaldi/sacred
def test_source_create_py():
    s = Source.create(EXAMPLE_SOURCE)
    assert s.filename == os.path.abspath(EXAMPLE_SOURCE)
    assert s.digest == EXAMPLE_DIGEST
コード例 #12
0
ファイル: test_ingredients.py プロジェクト: pputzky/sacred
def test_create_ingredient(ing):
    assert ing.path == 'tickle'
    assert ing.doc == __doc__
    assert Source.create(__file__) in ing.sources
コード例 #13
0
    pd.fill_missing_version()
    assert pd.version == pytest.__version__


def test_package_dependency_repr():
    pd = PackageDependency("pytest", "12.4")
    assert repr(pd) == "<PackageDependency: pytest=12.4>"


@pytest.mark.parametrize(
    "discover_sources, expected_sources",
    [
        (
            "imported",
            {
                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")),
            },
        ),
        (
            "dir",
            {
                # This list would be too long to explicitly insert here
                Source.create(str(path.resolve()))
                for path in Path(TEST_DIRECTORY).rglob("*.py")
            },
        ),
コード例 #14
0
def test_source_repr():
    s = Source.create(EXAMPLE_SOURCE)
    assert repr(s) == "<Source: {}>".format(os.path.abspath(EXAMPLE_SOURCE))
コード例 #15
0
ファイル: test_dependencies.py プロジェクト: jmrinaldi/sacred
def test_source_create_empty():
    with pytest.raises(ValueError):
        Source.create('')
コード例 #16
0
ファイル: test_dependencies.py プロジェクト: jmrinaldi/sacred
def test_source_create_non_existing():
    with pytest.raises(ValueError):
        Source.create('doesnotexist.py')
コード例 #17
0
def test_source_create_py():
    s = Source.create(EXAMPLE_SOURCE)
    assert s.filename == os.path.abspath(EXAMPLE_SOURCE)
    assert s.digest == EXAMPLE_DIGEST
コード例 #18
0
def test_source_create_empty():
    with pytest.raises(ValueError):
        Source.create("")
コード例 #19
0
def test_source_create_non_existing():
    with pytest.raises(ValueError):
        Source.create("doesnotexist.py")
コード例 #20
0
ファイル: test_dependencies.py プロジェクト: jmrinaldi/sacred
def test_source_to_tuple():
    s = Source.create(EXAMPLE_SOURCE)
    assert s.to_tuple() == (os.path.abspath(EXAMPLE_SOURCE), EXAMPLE_DIGEST)
コード例 #21
0
def test_source_to_json():
    s = Source.create(EXAMPLE_SOURCE)
    assert s.to_json() == (os.path.abspath(EXAMPLE_SOURCE), EXAMPLE_DIGEST)
コード例 #22
0
ファイル: test_ingredients.py プロジェクト: wecacuee/sacred
def test_create_ingredient(ing):
    assert ing.path == 'tickle'
    assert ing.doc == __doc__
    assert Source.create(__file__) in ing.sources