Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
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
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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