Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
atom-tr committed Sep 16, 2024
1 parent 4575509 commit e8fc520
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions test_fias_record.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e8fc520

Please sign in to comment.