Skip to content

Commit dfe3676

Browse files
committed
replace nose with pytest
Signed-off-by: mohapatr3 <[email protected]>
1 parent 192c309 commit dfe3676

28 files changed

+328
-283
lines changed

.github/workflows/generator.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,21 @@ 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: Dependencies
18+
uses: astral-sh/setup-uv@v6
1719
- name: Install
1820
run: |
1921
cd flatdata-generator
2022
# runtime requirements
2123
pip install -r requirements.txt
2224
# CI requirements
23-
pip install nose pylint
25+
pip install pylint
2426
- name: Run tests
2527
run: |
2628
cd flatdata-generator
27-
python -m nose
29+
uv run --with pytest pytest
2830
pip install .
2931
flatdata-generator --help

.github/workflows/py.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ 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: Dependencies
18+
uses: astral-sh/setup-uv@v6
1719
- name: Install
1820
run: |
1921
pip install ./flatdata-generator
2022
cd flatdata-py
2123
# runtime requirements
2224
pip install -r requirements.txt
2325
# CI requirements
24-
pip install nose pylint
26+
pip install pylint
2527
- name: Run tests
2628
run: |
2729
cd flatdata-py
28-
python -m nose
30+
uv run --with pytest --with ../flatdata-generator pytest
2931
pip install .
3032
flatdata-inspector --help

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/flatdata/generator/engine.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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

@@ -61,14 +61,15 @@ def render(self, generator_name):
6161
output_content = generator.render(self.tree)
6262
return output_content
6363

64-
def render_python_module(self, module_name=None, archive_name=None):
64+
def render_python_module(self, module_name=None, archive_name=None, root_namespace=None):
6565
"""
6666
Render python module.
6767
:param module_name: Module name to use. If none, root namespace name is used.
6868
:param archive_name: Archive name to lookup,
6969
if specified, archive type is returned along with the model
70+
:param root_namespace: Root namespace to pick in case of multiple top level namespaces.
7071
"""
71-
root_namespace = self._find_root_namespace(self.tree)
72+
root_namespace = self._find_root_namespace(self.tree, root_namespace)
7273
module_code = self.render("py")
7374
module = types.ModuleType(module_name if module_name is not None else root_namespace.name)
7475
#pylint: disable=exec-used
@@ -89,14 +90,20 @@ def _create_generator(cls, name):
8990
return generator_type()
9091

9192
@staticmethod
92-
def _find_root_namespace(tree):
93+
def _find_root_namespace(tree, root_namespace=None):
9394
root_children = tree.root.children
9495
root_namespaces = [
9596
child for child in root_children
9697
if isinstance(child, Namespace) and "builtin" not in child.name
9798
]
9899
if not root_namespaces:
99100
raise RuntimeError("No root namespace found.")
101+
elif root_namespace:
102+
for namespace in root_namespaces:
103+
if namespace.name == root_namespace:
104+
return namespace
105+
raise RuntimeError("Invalid root namespace provided. Could not find root namespace in archive.")
100106
elif len(root_namespaces) > 1:
101107
raise RuntimeError("Ambiguous root namespace. Could not find root archive.")
108+
102109
return root_namespaces[0]

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: 4 additions & 2 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()
@@ -21,4 +23,4 @@ def generate_and_compare(test_case):
2123

2224
def test_against_expectations():
2325
for x in schemas_and_expectations(generator='cpp', extension='h'):
24-
yield generate_and_compare, x
26+
generate_and_compare(x)

flatdata-generator/tests/generators/test_dot_generator.py

Lines changed: 4 additions & 2 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"
@@ -33,4 +35,4 @@ def generate_and_compare(test_case):
3335

3436
def test_against_expectations():
3537
for x in schemas_and_expectations(generator='dot', extension='dot'):
36-
yield generate_and_compare, x
38+
generate_and_compare(x)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
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
2020

2121
def test_against_expectations():
2222
for i in schemas_and_expectations(generator='flatdata', extension='flatdata'):
23-
yield generate_and_compare, i
23+
generate_and_compare((i[1], i[1]))
2424

2525
def test_normalization_is_fixed_point():
2626
for i in schemas_and_expectations(generator='flatdata', extension='flatdata'):
27-
yield generate_and_compare, (i[1], i[1])
27+
generate_and_compare((i[1], i[1]))

flatdata-generator/tests/generators/test_go_generator.py

Lines changed: 5 additions & 6 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,13 @@ def generate_and_compare(test_case):
2423

2524

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

2928

3029
def test_against_expectations():
3130
for x in schemas_and_expectations(generator='go', extension='go'):
3231
# Go does not yet support namespaces, enums, ranges, or constants, skip those tests
3332
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
33+
generate_and_compare(x)
3534
else:
36-
yield skip, x
35+
skip(x)

flatdata-generator/tests/generators/test_python_generator.py

Lines changed: 5 additions & 5 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,12 @@ 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

2727
def test_against_expectations():
2828
for x in schemas_and_expectations(generator='py', extension='py'):
2929
# Python does not yet support enums or constants, skip those tests
3030
if "enums" not in x[0] and "constants" not in x[0]:
31-
yield generate_and_compare, x
31+
generate_and_compare(x)
3232
else:
33-
yield skip, x
33+
skip(x)

0 commit comments

Comments
 (0)