def mocked_feature_extractor(
        test_file_settings: OverhaveFileSettings) -> FeatureExtractor:
    extractor_mock = mock.MagicMock()
    extractor_mock.feature_type_to_dir_mapping = {
        feature_type: test_file_settings.features_dir / feature_type
        for feature_type, path in
        get_test_feature_extractor().feature_type_to_dir_mapping.items()
    }
    return extractor_mock
def test_file_manager(
    test_project_settings: OverhaveProjectSettings,
    test_file_settings: OverhaveFileSettings,
    test_scenario_compiler: ScenarioCompiler,
) -> FileManager:
    return FileManager(
        project_settings=test_project_settings,
        file_settings=test_file_settings,
        feature_extractor=get_test_feature_extractor(),
        scenario_compiler=test_scenario_compiler,
    )
def test_scenario_parser(
    test_compilation_settings: OverhaveScenarioCompilerSettings,
    language_settings: OverhaveLanguageSettings,
    task_links_keyword: Optional[str],
) -> ScenarioParser:
    return ScenarioParser(
        compilation_settings=test_compilation_settings,
        language_settings=language_settings,
        feature_extractor=get_test_feature_extractor(),
        task_links_keyword=task_links_keyword,
    )
def test_feature() -> FeatureModel:
    return FeatureModel(
        id=1,
        name="feature",
        author="keks",
        type_id=1,
        task=["OVERHAVE-1"],
        last_edited_by="overlord",
        released=False,
        feature_type=FeatureTypeModel(
            id=1, name=get_test_feature_extractor().feature_types[0]),
        feature_tags=[
            TagsTypeModel(id=1,
                          value="tag1",
                          created_by="qqq",
                          created_at=get_current_time())
        ],
        file_path="my_folder/my_feature",
    )
Beispiel #5
0
class TestFeatureExtractor:
    """ Unit tests for :class:`FeatureExtractor`. """
    @pytest.mark.parametrize("test_file_settings",
                             [get_incorrect_test_file_settings()],
                             indirect=True)
    def test_feature_type_extraction_error(
            self, test_file_settings: OverhaveFileSettings) -> None:
        with pytest.raises(FeatureTypeExtractionError):
            FeatureExtractor(
                file_settings=test_file_settings)._extract_project_data()

    @pytest.mark.parametrize("test_file_settings",
                             [get_incorrect_test_file_settings()],
                             indirect=True)
    def test_scenarios_test_file_not_found_error(
            self, test_file_settings: OverhaveFileSettings,
            faker: Faker) -> None:
        extractor = FeatureExtractor(file_settings=test_file_settings)
        extractor._feature_types = [faker.word()]
        with pytest.raises(ScenariosTestFileNotFound):  # noqa: PT012
            extractor._check_pytest_bdd_scenarios_test_files()

    @pytest.mark.parametrize("test_feature_extractor",
                             [get_test_feature_extractor()],
                             indirect=True)
    def test_feature_extractor_properties(
            self, test_feature_extractor: FeatureExtractor,
            test_feature_containers: Sequence[FeatureTestContainer]) -> None:
        assert set(test_feature_extractor.feature_types) == {
            feature.type
            for feature in test_feature_containers
        }
        assert test_feature_extractor.feature_type_to_dir_mapping == {
            feature.type: feature.project_path.parent
            for feature in test_feature_containers
        }
def test_reviewers_mapping(faker: Faker) -> Mapping[FeatureTypeName, List[str]]:
    return {
        feature_type: cast(List[str], faker.words(faker.random.randint(1, 10)))
        for feature_type in get_test_feature_extractor().feature_types
    }