コード例 #1
0
def test_filter_assertions():
    executor = MagicMock()
    generator = ag.AssertionGenerator(executor)
    test_case = MagicMock()
    with mock.patch.object(generator, "_filter_failing_assertions") as filt:
        generator.filter_failing_assertions([test_case])
        filt.assert_called_with(test_case)
コード例 #2
0
def test__filter_failing_assertions(generator_setup):
    test_case, executor, statement, _ = generator_setup

    statement.assertions = {MagicMock}
    generator = ag.AssertionGenerator(executor)
    generator._filter_failing_assertions(test_case)
    assert statement.assertions == set()
コード例 #3
0
def test_add_assertions():
    executor = MagicMock()
    generator = ag.AssertionGenerator(executor)
    test_case = MagicMock()
    with mock.patch.object(generator, "_add_assertions") as add:
        generator.add_assertions([test_case])
        add.assert_called_with(test_case)
コード例 #4
0
def test__add_assertions_long(generator_setup):
    test_case, executor, statement, _ = generator_setup
    test_case.size_with_assertions.return_value = 3
    config.INSTANCE.max_length_test_case = 2

    generator = ag.AssertionGenerator(executor)
    generator._add_assertions(test_case)
    statement.add_assertion.assert_not_called()
コード例 #5
0
def test__add_assertions_short(generator_setup):
    test_case, executor, statement, assertion = generator_setup
    test_case.size_with_assertions.return_value = 1
    config.configuration.max_length_test_case = 2

    generator = ag.AssertionGenerator(executor)
    generator._add_assertions(test_case)
    statement.add_assertion.assert_called_with(assertion)
コード例 #6
0
ファイル: generator.py プロジェクト: marwahejazi/pynguin
        generation_result = algorithm.generate_tests()
        _LOGGER.info("Stop generating sequences using %s",
                     config.configuration.algorithm)
        algorithm.send_statistics()

        with Timer(name="Re-execution time", logger=None):
            stat.track_output_variable(RuntimeVariable.Coverage,
                                       generation_result.get_coverage())

        if config.configuration.post_process:
            postprocessor = pp.ExceptionTruncation()
            generation_result.accept(postprocessor)
            # TODO(fk) add more postprocessing stuff.

        if config.configuration.generate_assertions:
            generator = ag.AssertionGenerator(executor)
            generation_result.accept(generator)

        with Timer(name="Export time", logger=None):
            converter = cc.ChromosomeConverter()
            generation_result.accept(converter)
            failing = converter.failing_test_suite
            passing = converter.passing_test_suite
            written_to = _export_test_cases(
                [t.test_case for t in passing.test_case_chromosomes])
            _LOGGER.info(
                "Export %i successful test cases to %s",
                passing.size(),
                written_to,
            )
            written_to = _export_test_cases(
コード例 #7
0
def test_init():
    executor = MagicMock()
    ag.AssertionGenerator(executor)
    assert executor.add_observer.call_count == 2