Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added github actions CI workflow with unit tests #7

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
push:
branches:
- main
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.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-cov
pytest --cov

Empty file added tests/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions tests/test_detector.py
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions tests/test_maker.py
Original file line number Diff line number Diff line change
@@ -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