Пример #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 add_package_dependency(self, package_name, version):
        """
        Add a package to the list of dependencies.

        :param package_name: The name of the package dependency
        :type package_name: str
        :param version: The (minimum) version of the package
        :type version: str
        """
        if not PEP440_VERSION_PATTERN.match(version):
            raise ValueError('Invalid Version: "{}"'.format(version))
        self.dependencies.add(PackageDependency(package_name, version))
Пример #4
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
Пример #5
0
def test_package_dependency_fill_non_missing_version():
    pd = PackageDependency("mymod", "1.2.3rc4")
    pd.fill_missing_version()
    assert pd.version == "1.2.3rc4"
Пример #6
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
Пример #7
0
def test_package_dependency_get_version_heuristic_VERSION(version, expected):
    mod = mock.Mock(spec=[], VERSION=version)
    assert PackageDependency.get_version_heuristic(mod) == expected
Пример #8
0
import datetime
import os
import numba
from numba.core.errors import NumbaWarning
import warnings
warnings.simplefilter('ignore', category=NumbaWarning)
import SpringBox
from SpringBox.integrator import integrate_one_timestep
from SpringBox.activation import *
from SpringBox.post_run_hooks import post_run_hooks
from SpringBox.measurements import do_measurements, do_one_timestep_correlation_measurement

ex = Experiment('SpringBox')
#ex.observers.append(MongoObserver.create())
ex.observers.append(FileStorageObserver.create(f'data/'))
ex.dependencies.add(PackageDependency("SpringBox", SpringBox.__version__))


@ex.config
def cfg():
    ## Simulation parameters
    sweep_experiment = False
    run_id = 0
    savefreq_fig = 3
    savefreq_data_dump = 500
    # Speeds up the computation somewhat, but incurs an error due to oversmoothing of fluids (which could however be somewhat physical)
    use_interpolated_fluid_velocities = False
    dt = .05
    T = 10
    particle_density = 310
    MAKE_VIDEO = True
Пример #9
0
def test_package_dependency_repr():
    pd = PackageDependency("pytest", "12.4")
    assert repr(pd) == "<PackageDependency: pytest=12.4>"
Пример #10
0
def test_package_dependency_get_version_heuristic_VERSION(version, expected):
    mod = mock.Mock(spec=[], VERSION=version)
    assert PackageDependency.get_version_heuristic(mod) == expected
Пример #11
0
def test_package_dependency_fill_missing_version():
    pd = PackageDependency('pytest', None)
    pd.fill_missing_version()
    assert pd.version == pytest.__version__
Пример #12
0
def test_package_dependency_fill_missing_version_unknown():
    pd = PackageDependency('mymod', None)
    pd.fill_missing_version()
    assert pd.version == '<unknown>'
Пример #13
0
def test_package_dependency_fill_non_missing_version():
    pd = PackageDependency('mymod', '1.2.3rc4')
    pd.fill_missing_version()
    assert pd.version == '1.2.3rc4'
Пример #14
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')
Пример #15
0
def test_package_dependency_repr():
    pd = PackageDependency('pytest', '12.4')
    assert repr(pd) == '<PackageDependency: pytest=12.4>'
Пример #16
0
def test_package_dependency_fill_missing_version_unknown():
    pd = PackageDependency("mymod", None)
    pd.fill_missing_version()
    assert pd.version == None
Пример #17
0
def test_package_dependency_fill_missing_version():
    pd = PackageDependency("pytest", None)
    pd.fill_missing_version()
    assert pd.version == pytest.__version__
Пример #18
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'
Пример #19
0
def test_add_package_dependency(ing):
    ing.add_package_dependency('django', '1.8.2')
    assert PackageDependency('django', '1.8.2') in ing.dependencies
Пример #20
0
def test_add_package_dependency(ing):
    ing.add_package_dependency("django", "1.8.2")
    assert PackageDependency("django", "1.8.2") in ing.dependencies