diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml new file mode 100644 index 0000000..336b5e7 --- /dev/null +++ b/.github/workflows/python-tests.yml @@ -0,0 +1,28 @@ +name: Python Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [2.7, 3.7, 3.8, 3.9, '3.10', '3.11', '3.12', '3.13'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + - name: Run tests + run: | + pytest \ No newline at end of file diff --git a/test_fias_record.py b/test_fias_record.py new file mode 100644 index 0000000..9fca0b3 --- /dev/null +++ b/test_fias_record.py @@ -0,0 +1,31 @@ +import pytest +from record import FIASRecord +from exceptions import InvalidRecord, UndefinedRecordType, Ignore + +def test_valid_gi_record(): + record = FIASRecord("GI|G#123|RN101|GNJohn Doe") + assert record.is_valid() + assert record.type == "GI" + assert record.GID == 123 + assert record.RN == "101" + assert record.GN == "John Doe" + +def test_invalid_record(): + with pytest.raises(InvalidRecord): + FIASRecord("InvalidRecord") + +def test_undefined_record_type(): + with pytest.raises(UndefinedRecordType): + record = FIASRecord("XX|G#123|RN101") + record.is_valid(raise_exception=True) + +def test_ignore_record(): + with pytest.raises(Ignore): + record = FIASRecord("DS|SomeData") + record.is_valid(raise_exception=True) + +def test_missing_attributes(): + record = FIASRecord("GI|G#123|RN101") + assert not record.is_valid() + with pytest.raises(InvalidRecord): + record.is_valid(raise_exception=True) \ No newline at end of file