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
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"
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))
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
def test_package_dependency_fill_non_missing_version(): pd = PackageDependency("mymod", "1.2.3rc4") pd.fill_missing_version() assert pd.version == "1.2.3rc4"
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
def test_package_dependency_get_version_heuristic_VERSION(version, expected): mod = mock.Mock(spec=[], VERSION=version) assert PackageDependency.get_version_heuristic(mod) == expected
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
def test_package_dependency_repr(): pd = PackageDependency("pytest", "12.4") assert repr(pd) == "<PackageDependency: pytest=12.4>"
def test_package_dependency_fill_missing_version(): pd = PackageDependency('pytest', None) pd.fill_missing_version() assert pd.version == pytest.__version__
def test_package_dependency_fill_missing_version_unknown(): pd = PackageDependency('mymod', None) pd.fill_missing_version() assert pd.version == '<unknown>'
def test_package_dependency_fill_non_missing_version(): pd = PackageDependency('mymod', '1.2.3rc4') pd.fill_missing_version() assert pd.version == '1.2.3rc4'
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')
def test_package_dependency_repr(): pd = PackageDependency('pytest', '12.4') assert repr(pd) == '<PackageDependency: pytest=12.4>'
def test_package_dependency_fill_missing_version_unknown(): pd = PackageDependency("mymod", None) pd.fill_missing_version() assert pd.version == None
def test_package_dependency_fill_missing_version(): pd = PackageDependency("pytest", None) pd.fill_missing_version() assert pd.version == pytest.__version__
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'
def test_add_package_dependency(ing): ing.add_package_dependency('django', '1.8.2') assert PackageDependency('django', '1.8.2') in ing.dependencies
def test_add_package_dependency(ing): ing.add_package_dependency("django", "1.8.2") assert PackageDependency("django", "1.8.2") in ing.dependencies