Skip to content

Commit cc94c59

Browse files
issue #58 add GitHub Actions workflow for tests and coverage
1 parent c8ef721 commit cc94c59

5 files changed

Lines changed: 184 additions & 1 deletion

File tree

.github/workflows/test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install pytest pytest-cov
28+
pip install -e .
29+
30+
- name: Run tests with coverage
31+
run: |
32+
pytest tests.py --cov=cyrtranslit --cov-report=xml --cov-report=term-missing
33+
34+
- name: Generate coverage report
35+
uses: irongut/CodeCoverageSummary@v1.3.0
36+
with:
37+
filename: coverage.xml
38+
badge: true
39+
format: markdown
40+
output: both
41+
42+
- name: Add coverage to job summary
43+
run: |
44+
cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
'Programming Language :: Python :: 3.9',
3535
'Programming Language :: Python :: 3.10',
3636
'Programming Language :: Python :: 3.11',
37-
'Programming Language :: Python :: 3.12'],
37+
'Programming Language :: Python :: 3.12',
38+
'Programming Language :: Python :: 3.13',
39+
'Programming Language :: Python :: 3.14'],
3840
entry_points={
3941
"console_scripts": [
4042
"cyrtranslit=cyrtranslit.cyrtranslit:main",

tests.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,138 @@ def test_file_transliteration_preserve_accents_true(self):
673673
self.assertIn('ì e tuk', result)
674674

675675

676+
class TestCLI(unittest.TestCase):
677+
''' Test command-line interface functionality. '''
678+
679+
def test_invalid_language_code(self):
680+
''' Test that invalid language code produces error. '''
681+
import subprocess
682+
import sys
683+
684+
# Try to use an invalid language code
685+
result = subprocess.run(
686+
[sys.executable, '-m', 'cyrtranslit.cyrtranslit', '-l', 'xx', '-i', 'tests/sr.txt'],
687+
capture_output=True,
688+
text=True
689+
)
690+
691+
# Should fail
692+
self.assertNotEqual(result.returncode, 0)
693+
694+
# Should show error message
695+
self.assertIn('not supported', result.stderr)
696+
697+
def test_output_file_creation(self):
698+
''' Test that output file is created correctly. '''
699+
import subprocess
700+
import sys
701+
import os
702+
import tempfile
703+
704+
# Create a temporary output file path
705+
with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt') as tmp:
706+
output_file = tmp.name
707+
708+
try:
709+
# Run CLI with output file
710+
result = subprocess.run(
711+
[sys.executable, '-m', 'cyrtranslit.cyrtranslit', '-l', 'sr', '-i', 'tests/sr.txt', '-o', output_file],
712+
capture_output=True,
713+
text=True
714+
)
715+
716+
# Should succeed
717+
self.assertEqual(result.returncode, 0, f"Command failed with: {result.stderr}")
718+
719+
# Output file should exist
720+
self.assertTrue(os.path.exists(output_file))
721+
722+
# Read and verify content
723+
with open(output_file, 'r', encoding='utf-8') as f:
724+
content = f.read()
725+
# Should contain transliterated Serbian text
726+
self.assertIn('a', content.lower())
727+
728+
finally:
729+
# Clean up
730+
if os.path.exists(output_file):
731+
os.remove(output_file)
732+
733+
def test_reverse_transliteration_flag(self):
734+
''' Test -c flag for Latin to Cyrillic transliteration. '''
735+
import subprocess
736+
import sys
737+
738+
# Run CLI with -c flag on Latin text
739+
result = subprocess.run(
740+
[sys.executable, '-m', 'cyrtranslit.cyrtranslit', '-l', 'sr', '-c', '-i', 'tests/sr_latinica.txt'],
741+
capture_output=True,
742+
text=True,
743+
encoding='utf-8'
744+
)
745+
746+
# Should succeed
747+
self.assertEqual(result.returncode, 0, f"Command failed with: {result.stderr}")
748+
749+
# Output should contain Cyrillic characters
750+
# Check for common Serbian Cyrillic letters
751+
self.assertTrue(any(ord(c) >= 0x0400 and ord(c) <= 0x04FF for c in result.stdout),
752+
"Output should contain Cyrillic characters")
753+
754+
def test_preserve_accents_flag(self):
755+
''' Test -p flag for preserving accents. '''
756+
import subprocess
757+
import sys
758+
759+
# Run CLI with -p flag on Macedonian text with accents
760+
result = subprocess.run(
761+
[sys.executable, '-m', 'cyrtranslit.cyrtranslit', '-l', 'mk', '-p', '-i', 'tests/mk_accented.txt'],
762+
capture_output=True,
763+
text=True,
764+
encoding='utf-8'
765+
)
766+
767+
# Should succeed
768+
self.assertEqual(result.returncode, 0, f"Command failed with: {result.stderr}")
769+
770+
# Output should contain Latin letters with grave accents
771+
self.assertIn('ì', result.stdout)
772+
773+
def test_combined_flags(self):
774+
''' Test combining -c and -p flags. '''
775+
import subprocess
776+
import sys
777+
778+
# Run CLI with both -c and -p flags
779+
result = subprocess.run(
780+
[sys.executable, '-m', 'cyrtranslit.cyrtranslit', '-l', 'mk', '-c', '-p', '-i', 'tests/mk_accented_latin.txt'],
781+
capture_output=True,
782+
text=True,
783+
encoding='utf-8'
784+
)
785+
786+
# Should succeed
787+
self.assertEqual(result.returncode, 0, f"Command failed with: {result.stderr}")
788+
789+
# Output should contain Cyrillic with accents
790+
self.assertIn('ѝ', result.stdout)
791+
792+
def test_file_not_found(self):
793+
''' Test error handling when input file doesn't exist. '''
794+
import subprocess
795+
import sys
796+
797+
# Try to read non-existent file
798+
result = subprocess.run(
799+
[sys.executable, '-m', 'cyrtranslit.cyrtranslit', '-l', 'sr', '-i', 'nonexistent_file.txt'],
800+
capture_output=True,
801+
text=True
802+
)
803+
804+
# Should fail
805+
self.assertNotEqual(result.returncode, 0)
806+
807+
676808
if __name__ == '__main__':
677809
# Run all tests.
678810
unittest.main()

tests/mk_accented_latin.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ì e tuka
2+
nè sme tamu

tests/sr_latinica.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dobar dan
2+
Kako si?
3+
Ovo je test fajl.

0 commit comments

Comments
 (0)