Skip to content

Commit 9b8c85b

Browse files
pytest: increase coverage to more than 50 percent (outpost-os#24)
Add initial per submodule test suites Using single fixture to load the sample dts file from sources Closes issue outpost-os#15
2 parents 1c7ee3a + e64fc62 commit 9b8c85b

File tree

5 files changed

+113
-8
lines changed

5 files changed

+113
-8
lines changed

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# flake8: noqa
6+
7+
import pathlib
8+
import dts_utils
9+
import pytest
10+
11+
12+
class Dts:
13+
def __init__(self):
14+
self.dts = dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts")
15+
16+
17+
@pytest.fixture(scope="module")
18+
def dts_file():
19+
return Dts()

tests/test_dump.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# flake8: noqa
6+
7+
import dts_utils
8+
import dts_utils.dump
9+
10+
11+
def test_dump(dts_file):
12+
usart1_info = dts_utils.dump.dump(dts_file.dts, "usart1", True)

tests/test_filters.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# flake8: noqa
6+
7+
import dts_utils
8+
import dts_utils.filters
9+
10+
11+
def test_filter_enabled(dts_file):
12+
pinctrl_list = dts_utils.filters.f_peripherals(dts_file.dts.soc.pinctrl)
13+
enabled_gpios = dts_utils.filters.f_enabled(pinctrl_list)
14+
assert len(enabled_gpios) == 7
15+
16+
17+
def test_filter_enabled_exceptions(dts_file):
18+
try:
19+
enabled_gpios = dts_utils.filters.f_enabled(dts_file.dts)
20+
assert False
21+
except dts_utils.exceptions.InvalidTemplateValueType:
22+
assert True
23+
24+
25+
def test_filter_owner(dts_file):
26+
i2c1 = dts_file.dts.i2c1
27+
assert dts_utils.filters.f_owner(i2c1) == 0xBABE
28+
29+
30+
def test_filter_owner_exceptions(dts_file):
31+
try:
32+
enabled_gpios = dts_utils.filters.f_owner(dts_file.dts)
33+
assert False
34+
except dts_utils.exceptions.InvalidTemplateValueType:
35+
assert True
36+
37+
38+
def test_filter_has_property(dts_file):
39+
i2c1 = dts_file.dts.i2c1
40+
assert dts_utils.filters.f_has_property(i2c1, "outpost,owner")
41+
42+
43+
def test_filter_has_property_exception(dts_file):
44+
try:
45+
dts_utils.filters.f_has_property(dts_file.dts, "outpost,owner")
46+
assert False
47+
except dts_utils.exceptions.InvalidTemplateValueType:
48+
assert True
49+
50+
51+
def test_filter_with_property(dts_file):
52+
dev_list = dts_utils.filters.f_peripherals(dts_file.dts.root)
53+
assert len(dts_utils.filters.f_with_property(dev_list, "outpost,owner")) == 1
54+
55+
56+
def test_filter_with_property_exception(dts_file):
57+
try:
58+
dts_utils.filters.f_with_property(dts_file.dts, "outpost,owner")
59+
assert False
60+
except dts_utils.exceptions.InvalidTemplateValueType:
61+
assert True
62+
try:
63+
dts_utils.filters.f_with_property(dts_file.dts.usart1, "outpost,owner")
64+
assert False
65+
except dts_utils.exceptions.InvalidTemplateValueType:
66+
assert True

tests/test_load.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
# flake8: noqa
66

7-
import pathlib
87
import dts_utils
98

109

11-
def test_dtsload():
12-
dts = dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts")
13-
14-
15-
def test_socload():
16-
dts = dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts")
17-
soc = dts.soc
10+
def test_socload(dts_file):
11+
soc = dts_file.dts.soc
12+
assert soc != None

tests/test_node.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# SPDX-FileCopyrightText: 2023 - 2024 Ledger SAS
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# flake8: noqa
6+
7+
import dts_utils
8+
9+
10+
def test_node_id(dts_file):
11+
usart1 = dts_file.dts.usart1
12+
assert usart1.label == "usart1"
13+
assert usart1.name == "serial@40013800"

0 commit comments

Comments
 (0)