Skip to content

Commit 8c423b3

Browse files
pytest: increase coverage to more than 50 percent
1 parent 1c7ee3a commit 8c423b3

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

tests/test_dump.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 dts_utils.dump
10+
import dts_utils.filters
11+
12+
13+
def _get_dtsload() -> dts_utils.Dts:
14+
return dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts")
15+
16+
17+
def test_dump():
18+
dts = _get_dtsload()
19+
usart1_info = dts_utils.dump.dump(dts, "usart1", True)

tests/test_filters.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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 dts_utils.filters
10+
11+
12+
def _get_dtsload() -> dts_utils.Dts:
13+
return dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts")
14+
15+
16+
def test_filter_enabled():
17+
dts = _get_dtsload()
18+
pinctrl_list = dts_utils.filters.f_peripherals(dts.soc.pinctrl)
19+
enabled_gpios = dts_utils.filters.f_enabled(pinctrl_list)
20+
assert len(enabled_gpios) == 7
21+
22+
23+
def test_filter_enabled_exceptions():
24+
dts = _get_dtsload()
25+
try:
26+
enabled_gpios = dts_utils.filters.f_enabled(dts)
27+
assert False
28+
except dts_utils.exceptions.InvalidTemplateValueType:
29+
assert True
30+
31+
32+
def test_filter_owner():
33+
dts = _get_dtsload()
34+
i2c1 = dts.i2c1
35+
assert dts_utils.filters.f_owner(i2c1) == 0xBABE
36+
37+
38+
def test_filter_owner_exceptions():
39+
dts = _get_dtsload()
40+
try:
41+
enabled_gpios = dts_utils.filters.f_owner(dts)
42+
assert False
43+
except dts_utils.exceptions.InvalidTemplateValueType:
44+
assert True
45+
46+
47+
def test_filter_has_property():
48+
dts = _get_dtsload()
49+
i2c1 = dts.i2c1
50+
assert dts_utils.filters.f_has_property(i2c1, "outpost,owner")
51+
52+
53+
def test_filter_has_property_exception():
54+
dts = _get_dtsload()
55+
try:
56+
dts_utils.filters.f_has_property(dts, "outpost,owner")
57+
assert False
58+
except dts_utils.exceptions.InvalidTemplateValueType:
59+
assert True
60+
61+
62+
def test_filter_with_property():
63+
dts = _get_dtsload()
64+
dev_list = dts_utils.filters.f_peripherals(dts.root)
65+
assert len(dts_utils.filters.f_with_property(dev_list, "outpost,owner")) == 1
66+
67+
68+
def test_filter_with_property_exception():
69+
dts = _get_dtsload()
70+
try:
71+
dts_utils.filters.f_with_property(dts, "outpost,owner")
72+
assert False
73+
except dts_utils.exceptions.InvalidTemplateValueType:
74+
assert True
75+
try:
76+
dts_utils.filters.f_with_property(dts.usart1, "outpost,owner")
77+
assert False
78+
except dts_utils.exceptions.InvalidTemplateValueType:
79+
assert True

tests/test_node.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+
10+
11+
def _get_dtsload() -> dts_utils.Dts:
12+
return dts_utils.Dts(pathlib.Path(__file__).parent.absolute() / "dts/sample.dts")
13+
14+
15+
def test_node_id():
16+
dts = _get_dtsload()
17+
usart1 = dts.usart1
18+
assert usart1.label == "usart1"
19+
assert usart1.name == "serial@40013800"

0 commit comments

Comments
 (0)