Пример #1
0
def test_setup_executor_failed():
    generator = gen.Pynguin(configuration=MagicMock(log_file=None))
    with mock.patch(
            "pynguin.testcase.execution.testcaseexecutor.TestCaseExecutor.__init__"
    ) as exec_mock:
        exec_mock.side_effect = ModuleNotFoundError()
        assert generator._setup_executor(MagicMock()) is None
Пример #2
0
def test_setup_executor_success():
    generator = gen.Pynguin(configuration=MagicMock(log_file=None))
    with mock.patch(
            "pynguin.testcase.execution.testcaseexecutor.TestCaseExecutor.__init__"
    ) as exec_mock:
        exec_mock.return_value = None
        assert generator._setup_executor(MagicMock())
Пример #3
0
def test_run(tmp_path):
    generator = gen.Pynguin(
        configuration=MagicMock(log_file=None, project_path=tmp_path / "nope")
    )
    with mock.patch.object(gen.Pynguin, "_run") as run_mock:
        generator.run()
        run_mock.assert_called_once()
Пример #4
0
def test_setup_hook():
    module_name = "test_module"
    generator = gen.Pynguin(
        configuration=MagicMock(log_file=None, module_name=module_name)
    )
    with mock.patch.object(gen, "install_import_hook") as hook_mock:
        assert generator._setup_import_hook()
        hook_mock.assert_called_once()
Пример #5
0
def test_setup_path_and_hook_valid_dir(tmp_path):
    module_name = "test_module"
    generator = gen.Pynguin(configuration=MagicMock(
        log_file=None, project_path=tmp_path, module_name=module_name))
    with mock.patch.object(gen, "install_import_hook") as hook_mock:
        with mock.patch("sys.path") as path_mock:
            assert generator._setup_path_and_hook()
            hook_mock.assert_called_once()
            path_mock.insert.assert_called_with(0, tmp_path)
Пример #6
0
def test_setup_path_valid_dir(tmp_path):
    module_name = "test_module"
    generator = gen.Pynguin(
        configuration=MagicMock(
            log_file=None, project_path=tmp_path, module_name=module_name
        )
    )
    with mock.patch("sys.path") as path_mock:
        assert generator._setup_path() is True
        path_mock.insert.assert_called_with(0, tmp_path)
Пример #7
0
def test_setup_test_cluster_not_empty():
    generator = gen.Pynguin(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 generator._setup_test_cluster()
Пример #8
0
def test_init_without_params():
    with pytest.raises(ConfigurationException) as exception:
        gen.Pynguin(None)
    assert (
        exception.value.args[0] == "Cannot initialise test generator without "
        "proper configuration.")
Пример #9
0
def test_init_with_configuration():
    conf = MagicMock(log_file=None)
    gen.Pynguin(configuration=conf)
    assert config.INSTANCE == conf
Пример #10
0
def test_setup_path_and_hook_invalid_dir(tmp_path):
    generator = gen.Pynguin(
        configuration=MagicMock(log_file=None, project_path=tmp_path / "nope"))
    assert generator._setup_path_and_hook() is None
Пример #11
0
def test__load_sut_success():
    generator = gen.Pynguin(configuration=MagicMock(log_file=None))
    with mock.patch("importlib.import_module"):
        assert generator._load_sut()
Пример #12
0
def test__load_sut_failed():
    generator = gen.Pynguin(
        configuration=MagicMock(log_file=None, module_name="this.does.not.exist")
    )
    assert generator._load_sut() is False