From 70c5825fcb10385a619c122b8bf6e72c6044803d Mon Sep 17 00:00:00 2001 From: kosdmit Date: Thu, 12 Sep 2024 17:39:54 +0300 Subject: [PATCH 1/6] Init tests module --- tests/__init__.py | 0 tests/test_detector.py | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/test_detector.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_detector.py b/tests/test_detector.py new file mode 100644 index 0000000..038840b --- /dev/null +++ b/tests/test_detector.py @@ -0,0 +1,19 @@ +import pytest + +from pytrovich.detector import PetrovichGenderDetector +from pytrovich.enums import Gender + + +@pytest.fixture(scope='session') +def gender_detector(): + return PetrovichGenderDetector() + + +class TestPetrovichGenderDetector: + @pytest.mark.parametrize('middlename,expected_gender', ( + ('Иванович', Gender.MALE), + ('Ильинична', Gender.FEMALE), + pytest.param('Блаблабла', Gender.ANDROGYNOUS, marks=pytest.mark.xfail(reason='Issue #6')), + )) + def test_detect_by_middlename(self, gender_detector, middlename, expected_gender): + assert gender_detector.detect(middlename=middlename) == expected_gender From 725f4bee8ba1a9ecd6b92f3e32ccd22885bcd129 Mon Sep 17 00:00:00 2001 From: kosdmit Date: Thu, 12 Sep 2024 17:40:20 +0300 Subject: [PATCH 2/6] Added github actions CI config --- .github/workflows/main.yml | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e5bc7b5 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: + - main + - tests + pull_request: + +jobs: + tests: + name: Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + python-version: + - '3.6' + - '3.7' + - '3.8' + - '3.9' + - '3.10' + - '3.11' + - '3.12' + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Run Tests + run: | + pip install pytest + pytest + From 635d0dfd1234cda9ad722169ad45e40434b42e43 Mon Sep 17 00:00:00 2001 From: kosdmit Date: Fri, 13 Sep 2024 10:26:17 +0300 Subject: [PATCH 3/6] Added tests for declination common names --- tests/test_maker.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/test_maker.py diff --git a/tests/test_maker.py b/tests/test_maker.py new file mode 100644 index 0000000..04d1d21 --- /dev/null +++ b/tests/test_maker.py @@ -0,0 +1,44 @@ +import pytest + +from pytrovich.enums import Case, NamePart, Gender +from pytrovich.maker import PetrovichDeclinationMaker + + +@pytest.fixture(scope='session') +def maker() -> PetrovichDeclinationMaker: + return PetrovichDeclinationMaker() + + +class TestPetrovichDeclinationMaker: + @pytest.mark.parametrize('name_part,gender,case_to_use,original_name,expected_result', ( + # firstnames + (NamePart.FIRSTNAME, Gender.FEMALE, Case.GENITIVE, 'Мария', 'Марии'), + (NamePart.FIRSTNAME, Gender.MALE, Case.DATIVE, 'Василий', 'Василию'), + (NamePart.FIRSTNAME, Gender.FEMALE, Case.ACCUSATIVE, 'Ксюша', 'Ксюшу'), + (NamePart.FIRSTNAME, Gender.MALE, Case.INSTRUMENTAL, 'Паша', 'Пашой'), + (NamePart.FIRSTNAME, Gender.FEMALE, Case.PREPOSITIONAL, 'Елена', 'Елене'), + # middlenames + (NamePart.MIDDLENAME, Gender.FEMALE, Case.GENITIVE, 'Геннадиевна', 'Геннадиевны'), + (NamePart.MIDDLENAME, Gender.MALE, Case.DATIVE, 'Васильевич', 'Васильевичу'), + (NamePart.MIDDLENAME, Gender.FEMALE, Case.ACCUSATIVE, 'Васильевна', 'Васильевну'), + (NamePart.MIDDLENAME, Gender.MALE, Case.INSTRUMENTAL, 'Павлович', 'Павловичем'), + (NamePart.MIDDLENAME, Gender.FEMALE, Case.PREPOSITIONAL, 'Павловна', 'Павловне'), + # lastnames + (NamePart.LASTNAME, Gender.FEMALE, Case.GENITIVE, 'Цветаева', 'Цветаевой'), + (NamePart.LASTNAME, Gender.MALE, Case.DATIVE, 'Толстой', 'Толстому'), + (NamePart.LASTNAME, Gender.FEMALE, Case.ACCUSATIVE, 'Ахматова', 'Ахматову'), + (NamePart.LASTNAME, Gender.MALE, Case.INSTRUMENTAL, 'Лермонтов', 'Лермонтовым'), + (NamePart.LASTNAME, Gender.FEMALE, Case.PREPOSITIONAL, 'Баркова', 'Барковой'), + )) + def test_common_names( + self, + maker: PetrovichDeclinationMaker, + name_part: NamePart, + gender: Gender, + case_to_use: Case, + original_name: str, + expected_result: str + ) -> None: + + assert maker.make(name_part, gender, case_to_use, original_name) == expected_result + From 1dfdbc3e79dc9a0304569789fb2d9e5b1ab43e41 Mon Sep 17 00:00:00 2001 From: kosdmit Date: Fri, 13 Sep 2024 10:36:47 +0300 Subject: [PATCH 4/6] Dropped python 3.6 from test matrix --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e5bc7b5..6147d6d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,6 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] python-version: - - '3.6' - '3.7' - '3.8' - '3.9' From 86b249f039eabf636f19f6cd8b5d2d7d3ae613e9 Mon Sep 17 00:00:00 2001 From: kosdmit Date: Fri, 13 Sep 2024 10:41:35 +0300 Subject: [PATCH 5/6] Run CI tests with coverage --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6147d6d..492dee6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,6 +33,6 @@ jobs: - name: Run Tests run: | - pip install pytest - pytest + pip install pytest pytest-cov + pytest --cov From 0e140c71c64e7c827d0ef846866e9db66e7bbdda Mon Sep 17 00:00:00 2001 From: kosdmit Date: Fri, 13 Sep 2024 10:49:11 +0300 Subject: [PATCH 6/6] Updated CI run condition --- .github/workflows/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 492dee6..58438ec 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,7 +4,6 @@ on: push: branches: - main - - tests pull_request: jobs: