Skip to content

Commit 2bce9d0

Browse files
committed
test: separate timing test
1 parent 1ab04c6 commit 2bce9d0

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ push: ## Push commits and tags
3232
schemas: ## Update schemas
3333
cd iuliia/schemas && git submodule update --init --recursive && cd ../..
3434

35-
test: ## Run tests
35+
test: ## Run functional tests
3636
python -m pytest -ra
37+
38+
timing: ## Run performance tests
39+
TEST_TIMING=1 python -m pytest -s tests/test_timing.py

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ lint Lint and static-check code
118118
pull Pull code and schemas
119119
push Push commits and tags
120120
schemas Update schemas
121-
test Run tests
121+
test Run functional tests
122+
timing Run performance tests
122123
```
123124

124125
## Contributing

tests/test_timing.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
import timeit
3+
import pytest
4+
import iuliia
5+
6+
7+
@pytest.mark.skipif(
8+
os.getenv("TEST_TIMING") is None, reason="skip timing test until explicitly requested"
9+
)
10+
def test_timing():
11+
source = "Юлия, съешь ещё этих мягких французских булок из Йошкар-Олы, да выпей алтайского чаю"
12+
iter_count = 10000
13+
max_sec = 1.0
14+
print(f"#iterations={iter_count}")
15+
for schema in [iuliia.GOST_779, iuliia.ICAO_DOC_9303, iuliia.MOSMETRO, iuliia.WIKIPEDIA]:
16+
elapsed_sec = timeit.timeit(lambda: schema.translate(source), number=10000)
17+
print(f"{schema.name}: elapsed={elapsed_sec:.3f} sec")
18+
assert elapsed_sec < max_sec

tests/test_translate.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import os
2-
import timeit
3-
import pytest
41
import iuliia
52
from iuliia.schema import TranslitSchema
63

@@ -41,15 +38,3 @@ def test_short_word():
4138
def test_empty_word():
4239
schema = TranslitSchema(name="test", mapping={})
4340
assert schema.translate("") == ""
44-
45-
46-
@pytest.mark.skipif(
47-
os.getenv("TEST_TIMING") is None, reason="skip timing test until explicitly requested"
48-
)
49-
def test_timing():
50-
mapping = {chr(i): chr(i) for i in range(ord("a"), ord("z"))}
51-
schema = TranslitSchema(name="test", mapping=mapping)
52-
source = "The quick brown fox jumps over the lazy dog"
53-
elapsed_sec = timeit.timeit(lambda: schema.translate(source), number=10000)
54-
max_sec = 1.0
55-
assert elapsed_sec < max_sec

0 commit comments

Comments
 (0)