Skip to content

Commit d75bc69

Browse files
authored
replace nose with pytest (#253)
* Replace usage of `nose` with `pytest` * Update Ubuntu to use `latest` * Properly `pytest.mark.parametrize` earlier `yield` based tests as `pytest` does not support `yield` in tests. * Fix rust build errors related to "error: hiding a lifetime that's elided elsewhere is confusing" Signed-off-by: mohapatr3 <[email protected]>
1 parent 192c309 commit d75bc69

25 files changed

+401
-348
lines changed

.github/workflows/generator.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,14 @@ env:
1111

1212
jobs:
1313
Build:
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- name: Install
18-
run: |
19-
cd flatdata-generator
20-
# runtime requirements
21-
pip install -r requirements.txt
22-
# CI requirements
23-
pip install nose pylint
17+
- name: Dependencies
18+
uses: astral-sh/setup-uv@v6
2419
- name: Run tests
2520
run: |
2621
cd flatdata-generator
27-
python -m nose
22+
uv run --with pytest pytest -v
2823
pip install .
2924
flatdata-generator --help

.github/workflows/py.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@ env:
1111

1212
jobs:
1313
Build:
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v2
17-
- name: Install
18-
run: |
19-
pip install ./flatdata-generator
20-
cd flatdata-py
21-
# runtime requirements
22-
pip install -r requirements.txt
23-
# CI requirements
24-
pip install nose pylint
17+
- name: Dependencies
18+
uses: astral-sh/setup-uv@v6
2519
- name: Run tests
2620
run: |
2721
cd flatdata-py
28-
python -m nose
22+
uv run --with pytest --with ../flatdata-generator pytest -v
2923
pip install .
30-
flatdata-inspector --help
24+
flatdata-inspector --help
25+

flatdata-cpp/ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN apk --no-cache add \
1616
breathe \
1717
sphinx \
1818
jinja2 \
19-
nose \
19+
pytest \
2020
pandas \
2121
pyparsing
2222

flatdata-generator/pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ include = [
3333

3434
[tool.hatch.build.targets.wheel]
3535
packages = ["flatdata"]
36+
37+
[tool.pytest.ini_options]
38+
testpaths = [ "tests" ]
39+
python_files = [ "test_*.py" ]
40+
python_classes = [ "Test*" ]
41+
python_functions = [ "test_*" ]

flatdata-generator/tests/generators/test_cpp_generator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'''
2-
Copyright (c) 2019 HERE Europe B.V.
2+
Copyright (c) 2025 HERE Europe B.V.
33
See the LICENSE file in the root of this project for license details.
44
'''
55
import glob
6+
import pytest
67

78
from flatdata.generator.generators.cpp import CppGenerator
89
from .assertions import generate_and_assert_in
910
from .schemas import schemas_and_expectations
1011

12+
1113
def generate_and_compare(test_case):
1214
with open(test_case[0], 'r') as test_file:
1315
test = test_file.read()
@@ -19,6 +21,12 @@ def generate_and_compare(test_case):
1921

2022
generate_and_assert_in(test, CppGenerator, *expectations)
2123

22-
def test_against_expectations():
24+
def get_test_cases():
25+
test_cases = []
2326
for x in schemas_and_expectations(generator='cpp', extension='h'):
24-
yield generate_and_compare, x
27+
test_cases.append(x)
28+
return test_cases
29+
30+
@pytest.mark.parametrize("case", get_test_cases())
31+
def test_against_expectations(case):
32+
generate_and_compare(case)

flatdata-generator/tests/generators/test_dot_generator.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
'''
2-
Copyright (c) 2017 HERE Europe B.V.
2+
Copyright (c) 2025 HERE Europe B.V.
33
See the LICENSE file in the root of this project for license details.
44
'''
55
import glob
6+
import pytest
67

78
from flatdata.generator.generators.dot import DotGenerator
89
from .assertions import generate_and_assert_in
910
from .schemas import schemas_and_expectations
1011

12+
1113
def test_structures_outside_of_archives_are_not_represented():
1214
unexpected_lines = [
1315
"_n_S"
@@ -31,6 +33,12 @@ def generate_and_compare(test_case):
3133

3234
generate_and_assert_in(test, DotGenerator, *expectations)
3335

34-
def test_against_expectations():
36+
def get_test_cases():
37+
test_cases = []
3538
for x in schemas_and_expectations(generator='dot', extension='dot'):
36-
yield generate_and_compare, x
39+
test_cases.append(x)
40+
return test_cases
41+
42+
@pytest.mark.parametrize("case", get_test_cases())
43+
def test_against_expectations(case):
44+
generate_and_compare(case)
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
'''
2-
Copyright (c) 2018 HERE Europe B.V.
2+
Copyright (c) 2025 HERE Europe B.V.
33
See the LICENSE file in the root of this project for license details.
44
'''
5-
from nose.tools import assert_equal
5+
import pytest
66

77
from flatdata.generator.generators.flatdata import FlatdataGenerator
88
from flatdata.generator.tree.builder import build_ast
99
from .schemas import schemas_and_expectations
1010

11+
1112
def generate_and_compare(test_case):
1213
with open(test_case[0], 'r') as test_file:
1314
test = test_file.read()
1415
with open(test_case[1], 'r') as expectation_file:
1516
expectation = expectation_file.read()
1617
tree = build_ast(definition=test)
1718
contents = FlatdataGenerator().render(tree)
18-
assert_equal.__self__.maxDiff = None
19-
assert_equal(expectation, contents, test_case)
19+
assert expectation == contents
20+
21+
def get_test_cases():
22+
test_cases = []
23+
for x in schemas_and_expectations(generator='flatdata', extension='flatdata'):
24+
test_cases.append(x)
25+
return test_cases
2026

21-
def test_against_expectations():
22-
for i in schemas_and_expectations(generator='flatdata', extension='flatdata'):
23-
yield generate_and_compare, i
27+
@pytest.mark.parametrize("case", get_test_cases())
28+
def test_against_expectations(case):
29+
generate_and_compare(case)
2430

25-
def test_normalization_is_fixed_point():
26-
for i in schemas_and_expectations(generator='flatdata', extension='flatdata'):
27-
yield generate_and_compare, (i[1], i[1])
31+
@pytest.mark.parametrize("case", get_test_cases())
32+
def test_normalization_is_fixed_point(case):
33+
generate_and_compare((case[1], case[1]))
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
'''
2-
Copyright (c) 2017 HERE Europe B.V.
2+
Copyright (c) 2025 HERE Europe B.V.
33
See the LICENSE file in the root of this project for license details.
44
'''
55
import glob
6+
import pytest
67

78
from flatdata.generator.generators.go import GoGenerator
89
from .assertions import generate_and_assert_in
910
from .schemas import schemas_and_expectations
1011

11-
from nose.plugins.skip import SkipTest
12-
1312

1413
def generate_and_compare(test_case):
1514
with open(test_case[0], 'r') as test_file:
@@ -24,13 +23,18 @@ def generate_and_compare(test_case):
2423

2524

2625
def skip(test_case):
27-
raise SkipTest("Test %s is skipped" % test_case[0])
28-
26+
raise pytest.skip("Test %s is skipped" % test_case[0])
2927

30-
def test_against_expectations():
28+
def get_test_cases():
29+
test_cases = []
3130
for x in schemas_and_expectations(generator='go', extension='go'):
32-
# Go does not yet support namespaces, enums, ranges, or constants, skip those tests
33-
if "enums" not in x[0] and "constants" not in x[0] and "namespaces" not in x[0] and "ranges" not in x[0]:
34-
yield generate_and_compare, x
35-
else:
36-
yield skip, x
31+
test_cases.append(x)
32+
return test_cases
33+
34+
@pytest.mark.parametrize("test_case", get_test_cases())
35+
def test_against_expectations(test_case):
36+
# Go does not yet support namespaces, enums, ranges, or constants, skip those tests
37+
if "enums" not in test_case[0] and "constants" not in test_case[0] and "namespaces" not in test_case[0] and "ranges" not in test_case[0]:
38+
generate_and_compare(test_case)
39+
else:
40+
skip(test_case)
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
'''
2-
Copyright (c) 2017 HERE Europe B.V.
2+
Copyright (c) 2025 HERE Europe B.V.
33
See the LICENSE file in the root of this project for license details.
44
'''
55
import glob
6+
import pytest
67

78
from flatdata.generator.generators.python import PythonGenerator
89
from .assertions import generate_and_assert_in
910
from .schemas import schemas_and_expectations
1011

11-
from nose.plugins.skip import SkipTest
1212

1313
def generate_and_compare(test_case):
1414
with open(test_case[0], 'r') as test_file:
@@ -22,12 +22,18 @@ def generate_and_compare(test_case):
2222
generate_and_assert_in(test, PythonGenerator, *expectations)
2323

2424
def skip(test_case):
25-
raise SkipTest("Test %s is skipped" % test_case[0])
25+
raise pytest.skip("Test %s is skipped" % test_case[0])
2626

27-
def test_against_expectations():
27+
def get_test_cases():
28+
test_cases = []
2829
for x in schemas_and_expectations(generator='py', extension='py'):
29-
# Python does not yet support enums or constants, skip those tests
30-
if "enums" not in x[0] and "constants" not in x[0]:
31-
yield generate_and_compare, x
32-
else:
33-
yield skip, x
30+
test_cases.append(x)
31+
return test_cases
32+
33+
@pytest.mark.parametrize("test_case", get_test_cases())
34+
def test_against_expectations(test_case):
35+
# Python does not yet support enums or constants, skip those tests
36+
if "enums" not in test_case[0] and "constants" not in test_case[0]:
37+
generate_and_compare(test_case)
38+
else:
39+
skip(test_case)
Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
'''
2-
Copyright (c) 2019 HERE Europe B.V.
2+
Copyright (c) 2025 HERE Europe B.V.
33
See the LICENSE file in the root of this project for license details.
44
'''
55
import glob
6-
from nose.tools import eq_
6+
import pytest
77

88
from flatdata.generator.generators.rust import RustGenerator
99
from .assertions import generate_and_assert_in
1010
from .schemas import schemas_and_expectations
1111

1212
def test_format_numeric_literals():
13-
eq_(RustGenerator._format_numeric_literal(1), "1")
14-
eq_(RustGenerator._format_numeric_literal(123), "123")
15-
eq_(RustGenerator._format_numeric_literal(-123), "-123")
16-
eq_(RustGenerator._format_numeric_literal(1), "1")
17-
eq_(RustGenerator._format_numeric_literal(10), "10")
18-
eq_(RustGenerator._format_numeric_literal(100), "100")
19-
eq_(RustGenerator._format_numeric_literal(1000), "1_000")
20-
eq_(RustGenerator._format_numeric_literal(10000), "10_000")
21-
eq_(RustGenerator._format_numeric_literal(100000), "100_000")
22-
eq_(RustGenerator._format_numeric_literal(1000000), "1_000_000")
23-
eq_(RustGenerator._format_numeric_literal(-1000000), "-1_000_000")
24-
eq_(RustGenerator._format_numeric_literal(2147483647), "2_147_483_647")
25-
eq_(RustGenerator._format_numeric_literal("hello"), "hello")
26-
eq_(RustGenerator._format_numeric_literal("hello1234"), "hello1234")
27-
eq_(RustGenerator._format_numeric_literal("1234hello"), "1234hello")
13+
assert RustGenerator._format_numeric_literal(1) == "1"
14+
assert RustGenerator._format_numeric_literal(123) == "123"
15+
assert RustGenerator._format_numeric_literal(-123) == "-123"
16+
assert RustGenerator._format_numeric_literal(1) == "1"
17+
assert RustGenerator._format_numeric_literal(10) == "10"
18+
assert RustGenerator._format_numeric_literal(100) == "100"
19+
assert RustGenerator._format_numeric_literal(1000) == "1_000"
20+
assert RustGenerator._format_numeric_literal(10000) == "10_000"
21+
assert RustGenerator._format_numeric_literal(100000) == "100_000"
22+
assert RustGenerator._format_numeric_literal(1000000) == "1_000_000"
23+
assert RustGenerator._format_numeric_literal(-1000000) == "-1_000_000"
24+
assert RustGenerator._format_numeric_literal(2147483647) == "2_147_483_647"
25+
assert RustGenerator._format_numeric_literal("hello") == "hello"
26+
assert RustGenerator._format_numeric_literal("hello1234") == "hello1234"
27+
assert RustGenerator._format_numeric_literal("1234hello") == "1234hello"
2828

2929
def generate_and_compare(test_case):
3030
with open(test_case[0], 'r') as test_file:
@@ -37,6 +37,12 @@ def generate_and_compare(test_case):
3737

3838
generate_and_assert_in(test, RustGenerator, *expectations)
3939

40-
def test_against_expectations():
40+
def get_test_cases():
41+
test_cases = []
4142
for x in schemas_and_expectations(generator='rust', extension='rs'):
42-
yield generate_and_compare, x
43+
test_cases.append(x)
44+
return test_cases
45+
46+
@pytest.mark.parametrize("test_case", get_test_cases())
47+
def test_against_expectations(test_case):
48+
generate_and_compare(test_case)

0 commit comments

Comments
 (0)