def test_guard(): class TestModel: def __init__(self): pass @staticmethod def guard_allow(): return True @staticmethod def step_allow(): pass @staticmethod def step_allow_without_guard(): pass @staticmethod def guard_not_allow(): return False @staticmethod def step_not_allow(): pass osmo = Osmo(TestModel()) osmo.generate() for tc in osmo.history.test_cases: for step in tc.steps_log: assert 'not' not in step.name
def test_step_without_guard(): class TestModel: def __init__(self): pass @staticmethod def step_first(): pass osmo = Osmo(TestModel()) osmo.generate()
def test_empty_model(): class EmptyTestModel: def __init__(self): pass exception = False try: osmo = Osmo(EmptyTestModel()) osmo.generate() except: exception = True if not exception: raise Exception("Osmo did not except empty model")
def test_wrong_config_objects(): osmo = Osmo(OneStepModel()) try: osmo.test_end_condition = RandomAlgorithm() except AttributeError: pass except: raise try: osmo.algorithm = Length(1) except AttributeError: pass except: raise
def test_allow_count(): osmo = Osmo(JustFailModel(AssertionError('Failing test_stop_on_failure'))) osmo.test_end_condition = Length(10) osmo.test_suite_end_condition = Length(10) osmo.test_error_strategy = AllowCount(3) osmo.test_suite_error_strategy = AllowCount(3) try: osmo.generate() except: pass assert osmo.history.total_amount_of_steps == 3 + 1
def test_always_ignore(): osmo = Osmo(JustFailModel(AssertionError('Failing test_always_ignore'))) osmo.test_end_condition = Length(100) osmo.test_suite_end_condition = Length(10) osmo.test_error_strategy = AlwaysIgnore() osmo.test_suite_error_strategy = AlwaysIgnore() try: osmo.generate() except: pass assert osmo.history.total_amount_of_steps == 10 * 100
def test_logical_or(): model = TempModel() osmo = Osmo(model) osmo.test_end_condition = Or(Length(1), Length(2), Length(3)) osmo.test_suite_end_condition = Or(Length(2), Length(3), Length(4)) osmo.generate() assert model.counter == 2
def test_length_end_condition(steps, tests): model = TempModel() osmo = Osmo(model) osmo.test_end_condition = Length(tests) osmo.test_suite_end_condition = Length(steps) osmo.generate() assert model.counter == steps * tests
def test_step_coverage(): model = TempModel() osmo = Osmo(model) osmo.test_end_condition = StepCoverage(100) osmo.test_suite_end_condition = Length(1) osmo.generate() assert osmo.history.get_step_count( osmo.model.get_step_by_name("step_first")) > 0 assert osmo.history.get_step_count( osmo.model.get_step_by_name("step_second")) > 0
def test_exception_raise_effects(): model = OneStepModel() osmo = Osmo(model) osmo.test_end_condition = Length(8) osmo.test_suite_end_condition = Length(1) try: osmo.generate() except TempException: # Osmo is raisin test exception so need to catch it here pass assert model.index == 5
def test_test_suite_time_end_condition(): time_in_sec = 1 osmo = Osmo(TempModel()) osmo.test_end_condition = Length(1) osmo.test_suite_end_condition = Time(time_in_sec) start_time = time.time() osmo.generate() end_time = time.time() duration = end_time - start_time assert duration < time_in_sec + 0.1 assert duration > time_in_sec - 0.1
def test_weighted_algorithm(): class HistoryTest: steps = list() def __init__(self): pass @staticmethod def weight_first(): return 1 def step_first(self): self.steps.append('step_first') @staticmethod def weight_second(): return 2 def step_second(self): self.steps.append('step_second') @staticmethod def weight_third(): return 4 def step_third(self): self.steps.append('step_third') model = HistoryTest() osmo = Osmo(model) osmo.test_end_condition = Length(1) osmo.test_end_condition = Length(100) osmo.algorithm = WeightedAlgorithm() osmo.generate() step_first_count = osmo.history.get_step_count( osmo.model.get_step_by_name("step_first")) step_second_count = osmo.history.get_step_count( osmo.model.get_step_by_name("step_second")) step_third_count = osmo.history.get_step_count( osmo.model.get_step_by_name("step_third")) compare_first = step_first_count * (1.0 / model.weight_first()) compare_second = step_second_count * (1.0 / model.weight_second()) compare_third = step_third_count * (1.0 / model.weight_third()) assert abs(compare_first - compare_second) < 2 assert abs(compare_first - compare_third) < 2
def test_split_model_with_same_name_functions(): class TestModel1: def __init__(self): self.step_execute = False def step_first(self): self.step_execute = True class TestModel2: def __init__(self): self.step_execute = False def step_first(self): self.step_execute = True tm1 = TestModel1() tm2 = TestModel2() osmo = Osmo(tm1) osmo.add_model(tm2) osmo.generate() assert tm1.step_execute, "Osmo did not execute step in first model" assert tm2.step_execute, "Osmo did not execute step in second model"