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_code_change_init(self):
"""Test initialization of :class:`orion.core.evc.adapters.CodeChange`
with valid change types
"""
code_change_adapter = CodeChange(CodeChange.NOEFFECT)
assert code_change_adapter.change_type == CodeChange.NOEFFECT
code_change_adapter = CodeChange(CodeChange.BREAK)
assert code_change_adapter.change_type == CodeChange.BREAK
def test_code_change_init(self):
"""Test initialization of :class:`orion.core.evc.adapters.CodeChange`
with valid change types
"""
code_change_adapter = CodeChange(CodeChange.NOEFFECT)
assert code_change_adapter.change_type == CodeChange.NOEFFECT
code_change_adapter = CodeChange(CodeChange.BREAK)
assert code_change_adapter.change_type == CodeChange.BREAK
def test_code_change_backward_break(self, trials):
"""Test :meth:`orion.core.evc.adapters.CodeChange.backward` with change type BREAK"""
code_change_adapter = CodeChange(CodeChange.BREAK)
adapted_trials = code_change_adapter.backward(trials)
assert len(adapted_trials) == 0
def test_code_change(self, parent_config, changed_code_config):
"""Test if giving a proper change-type solves the code conflict"""
conflicts = detect_conflicts(parent_config, changed_code_config)
branch_builder = ExperimentBranchBuilder(conflicts, {'manual_resolution': True})
assert len(conflicts.get()) == 2
assert len(conflicts.get_resolved()) == 1
branch_builder.set_code_change_type(evc.adapters.CodeChange.types[0])
assert len(conflicts.get()) == 2
assert len(conflicts.get_resolved()) == 2
conflict = conflicts.get_resolved()[0]
assert conflict.is_resolved
assert isinstance(conflict, CodeConflict)
def test_code_change_forward_break(self, trials):
"""Test :meth:`orion.core.evc.adapters.CodeChange.forward` with change type BREAK"""
code_change_adapter = CodeChange(CodeChange.BREAK)
adapted_trials = code_change_adapter.forward(trials)
assert len(adapted_trials) == 0
def test_try_resolve(self, code_conflict):
"""Verify that resolution is achievable with valid code change-type input"""
assert not code_conflict.is_resolved
resolution = code_conflict.try_resolve(evc.adapters.CodeChange.UNSURE)
assert isinstance(resolution, code_conflict.CodeResolution)
assert code_conflict.is_resolved
assert resolution.conflict is code_conflict
assert resolution.type == evc.adapters.CodeChange.UNSURE
def test_try_resolve_twice(self, code_conflict):
"""Verify that conflict cannot be resolved twice"""
assert not code_conflict.is_resolved
assert isinstance(code_conflict.try_resolve(evc.adapters.CodeChange.BREAK),
code_conflict.CodeResolution)
assert code_conflict.is_resolved
assert code_conflict.try_resolve() is None
def test_code_change_backward_noeffect(self, trials):
"""Test :meth:`orion.core.evc.adapters.CodeChange.backward` with change type NOEFFECT"""
code_change_adapter = CodeChange(CodeChange.NOEFFECT)
adapted_trials = code_change_adapter.backward(trials)
assert len(adapted_trials) == len(trials)
assert adapted_trials[0] is trials[0]
assert adapted_trials[-1] is trials[-1]
def get_adapters(self):
"""Return CodeChange adapter"""
return [adapters.CodeChange(self.type)]