コード例 #1
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_setup_path_valid_dir(tmp_path):
    module_name = "test_module"
    gen.set_configuration(configuration=MagicMock(
        log_file=None, project_path=tmp_path, module_name=module_name))
    with mock.patch("sys.path") as path_mock:
        assert gen._setup_path() is True
        path_mock.insert.assert_called_with(0, tmp_path)
コード例 #2
0
ファイル: cli.py プロジェクト: atksh/pynguin
def main(argv: List[str] = None) -> int:
    """Entry point for the CLI of the Pynguin automatic unit test generation framework.

    This method behaves like a standard UNIX command-line application, i.e.,
    the return value `0` signals a successful execution.  Any other return value
    signals some errors.  This is, e.g., the case if the framework was not able
    to generate one successfully running test case for the class under test.

    Args:
        argv: List of command-line arguments

    Returns:
        An integer representing the success of the program run.  0 means
        success, all non-zero exit codes indicate errors.
    """
    install()
    if argv is None:
        argv = sys.argv
    if len(argv) <= 1:
        argv.append("--help")
    argv = _expand_arguments_if_necessary(argv[1:])

    argument_parser = _create_argument_parser()
    parsed = argument_parser.parse_args(argv)
    _setup_output_path(parsed.config.output_path)
    _setup_logging(parsed.verbosity, parsed.log_file)

    set_configuration(parsed.config)
    with console.status("Running Pynguin..."):
        return run_pynguin().value
コード例 #3
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_setup_hook():
    module_name = "test_module"
    gen.set_configuration(
        configuration=MagicMock(log_file=None, module_name=module_name))
    with mock.patch.object(gen, "install_import_hook") as hook_mock:
        assert gen._setup_import_hook()
        hook_mock.assert_called_once()
コード例 #4
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_setup_test_cluster_not_empty():
    gen.set_configuration(configuration=MagicMock(
        log_file=None,
        type_inference_strategy=config.TypeInferenceStrategy.TYPE_HINTS,
    ))
    with mock.patch(
            "pynguin.setup.testclustergenerator.TestClusterGenerator.generate_cluster"
    ) as gen_mock:
        tc = MagicMock()
        tc.num_accessible_objects_under_test.return_value = 1
        gen_mock.return_value = tc
        assert gen._setup_test_cluster()
コード例 #5
0
def test_generator_with_init_pop_seeding(rand_mock, clear_ips_instance,
                                         seed_modules_path,
                                         dummy_test_cluster):
    rand_mock.return_value = 2
    ips.initialpopulationseeding.test_cluster = dummy_test_cluster
    config.configuration.module_name = "primitiveseed"
    config.configuration.initial_population_seeding = True
    config.configuration.initial_population_data = seed_modules_path
    gen.set_configuration(config.configuration)
    gen._setup_initial_population_seeding(dummy_test_cluster)
    seeded_testcase = ips.initialpopulationseeding.seeded_testcase
    assert ips.initialpopulationseeding.has_tests
    assert (next(iter(
        seeded_testcase.statements[2].assertions)).value == "Bools are equal!")
コード例 #6
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_integrate(tmp_path):
    project_path = Path(".").absolute()
    if project_path.name == "tests":
        project_path /= ".."  # pragma: no cover
    project_path = project_path / "docs" / "source" / "_static"
    configuration = config.Configuration(
        algorithm=config.Algorithm.MOSA,
        budget=1,
        module_name="example",
        output_path=str(tmp_path),
        project_path=str(project_path),
        report_dir=str(tmp_path),
        statistics_backend=config.StatisticsBackend.NONE,
    )
    gen.set_configuration(configuration)
    result = gen.run_pynguin()
    assert result == gen.ReturnCode.OK
コード例 #7
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_run(tmp_path):
    gen.set_configuration(
        configuration=MagicMock(log_file=None, project_path=tmp_path / "nope"))
    with mock.patch("pynguin.generator._run") as run_mock:
        gen.run_pynguin()
        run_mock.assert_called_once()
コード例 #8
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_setup_path_invalid_dir(tmp_path):
    gen.set_configuration(
        configuration=MagicMock(log_file=None, project_path=tmp_path / "nope"))
    assert gen._setup_path() is False
コード例 #9
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test__load_sut_success():
    gen.set_configuration(configuration=MagicMock(log_file=None))
    with mock.patch("importlib.import_module"):
        assert gen._load_sut(MagicMock())
コード例 #10
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test__load_sut_failed():
    gen.set_configuration(configuration=MagicMock(
        log_file=None, module_name="this.does.not.exist"))
    assert gen._load_sut(MagicMock()) is False
コード例 #11
0
ファイル: test_generator.py プロジェクト: marwahejazi/pynguin
def test_init_with_configuration():
    conf = MagicMock(log_file=None)
    gen.set_configuration(configuration=conf)
    assert config.configuration == conf