Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_add_new(self, parent_config, new_config):
"""Test if adding a new dimension solves the conflict"""
conflicts = detect_conflicts(parent_config, new_config)
branch_builder = ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
branch_builder.add_dimension('w_d')
assert len(conflicts.get()) == 2
assert len(conflicts.get_resolved()) == 2
conflict = conflicts.get_resolved()[1]
assert conflict.is_resolved
assert isinstance(conflict.resolution, conflict.AddDimensionResolution)
def test_remove_missing(self, parent_config, child_config):
"""Test if missing dimension conflict is automatically resolved"""
child_config['metadata']['user_args'][1] = '-x~-'
backward.populate_priors(child_config['metadata'])
conflicts = detect_conflicts(parent_config, child_config)
ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
assert len(conflicts.get()) == 2
assert len(conflicts.get_resolved()) == 2
conflict = conflicts.get_resolved()[1]
assert conflict.is_resolved
assert isinstance(conflict.resolution, conflict.RemoveDimensionResolution)
def test_algo_conflict(self, parent_config, changed_algo_config):
"""Test if algorithm changes are currently detected"""
conflicts = detect_conflicts(parent_config, changed_algo_config)
assert len(conflicts.get()) == 2
conflict = conflicts.get()[0]
assert conflict.is_resolved is False
assert conflict.old_config['algorithms'] == 'random'
assert conflict.new_config['algorithms'] == 'stupid-grid'
assert isinstance(conflict, AlgorithmConflict)
def test_cli_change(self, parent_config, changed_cli_config):
"""Test if giving a proper change-type solves the command line conflict"""
conflicts = detect_conflicts(parent_config, changed_cli_config)
branch_builder = ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
assert len(conflicts.get()) == 2
assert len(conflicts.get_resolved()) == 1
branch_builder.set_cli_change_type(evc.adapters.CommandLineChange.types[0])
assert len(conflicts.get()) == 2
assert len(conflicts.get_resolved()) == 2
conflict = conflicts.get_resolved()[1]
assert conflict.is_resolved
assert isinstance(conflict, CommandLineConflict)
def test_adapter_rename_different_prior(self, parent_config, cl_config):
"""Test if a DimensionRenaming is created when solving a new conflict"""
cl_config['metadata']['user_args'] = ['-x~>w_d', '-w_d~+normal(0,1)']
conflicts = detect_conflicts(parent_config, cl_config)
branch_builder = ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
adapters = branch_builder.create_adapters().adapters
assert len(conflicts.get_resolved()) == 4
assert len(adapters) == 2
assert isinstance(adapters[0], evc.adapters.DimensionRenaming)
assert isinstance(adapters[1], evc.adapters.DimensionPriorChange)
def test_add_bad_default(self, parent_config, new_config):
"""Test if new dimension conflict raises an error if marked with invalid default value"""
new_config['metadata']['user_args'][-1] = '-w_d~+normal(0,1,default_value=\'a\')'
backward.populate_priors(new_config['metadata'])
with pytest.raises(TypeError) as exc:
detect_conflicts(parent_config, new_config)
assert "Parameter \'/w_d\': Incorrect arguments." in str(exc.value)
def test_adapter_add_changed(self, parent_config, cl_config):
"""Test if a DimensionPriorChange is created when solving a new conflict"""
cl_config['metadata']['user_args'] = ['-y~+uniform(0,1)']
conflicts = detect_conflicts(parent_config, cl_config)
branch_builder = ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
adapters = branch_builder.create_adapters().adapters
assert len(conflicts.get_resolved()) == 2
assert len(adapters) == 1
assert isinstance(adapters[0], evc.adapters.DimensionPriorChange)
def test_no_conflicts(self, parent_config, child_config):
"""Test the case where the child is the same as the parent"""
conflicts = detect_conflicts(parent_config, child_config)
assert len(conflicts.get()) == 1
assert isinstance(conflicts.get()[0], ExperimentNameConflict)
def test_cli_conflict(self, parent_config, changed_cli_config):
"""Test if changed command line call is detected as a conflict"""
conflicts = detect_conflicts(parent_config, changed_cli_config)
assert len(conflicts.get()) == 2
assert not conflicts.get([ExperimentNameConflict])[0].is_resolved
assert not conflicts.get([CommandLineConflict])[0].is_resolved
def test_rename_missing_changed(self, parent_config, missing_config):
"""Test if renaming a dimension to another with different prior solves both conflicts but
creates a new one which is not solved
"""
missing_config['metadata']['user_args'].append('-w_d~normal(0,1)')
backward.populate_priors(missing_config['metadata'])
conflicts = detect_conflicts(parent_config, missing_config)
branch_builder = ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
assert len(conflicts.get()) == 4
branch_builder.rename_dimension('x', 'w_d')
assert len(conflicts.get()) == 5
assert conflicts.get([ExperimentNameConflict])[0].is_resolved
assert conflicts.get([NewDimensionConflict])[0].is_resolved
assert conflicts.get([MissingDimensionConflict])[0].is_resolved
assert not conflicts.get([MissingDimensionConflict])[1].is_resolved
assert not conflicts.get([ChangedDimensionConflict])[0].is_resolved
resolved_conflicts = conflicts.get_resolved()
assert len(resolved_conflicts) == 3