Skip to content

Commit fe7f71b

Browse files
pillo79kartben
authored andcommitted
dtlib: add test for lineno/filename comments
Tweak the existing filename_and_lineno test to also check the generated comments in the string representation of the devicetree match expected contents and alignment. Using tmpdir as the base directory simplifies the comparison by avoiding directory separator issues. Signed-off-by: Luca Burelli <[email protected]>
1 parent c1603b3 commit fe7f71b

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

scripts/dts/python-devicetree/tests/test_dtlib.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@ def test_filename_and_lineno():
25382538
f.write('''/* a new node */
25392539
/ {
25402540
node1: test-node1 {
2541-
prop1A = "value1A";
2541+
prop1A = "short value 1A";
25422542
};
25432543
};
25442544
''')
@@ -2551,17 +2551,17 @@ def test_filename_and_lineno():
25512551
25522552
/ {
25532553
node2: test-node2 {
2554-
prop2A = "value2A";
2555-
prop2B = "value2B";
2554+
prop2A = "value 2A";
2555+
prop2B = "multi", "line", "value", "2B";
25562556
};
25572557
};
25582558
25592559
&node1 {
2560-
prop1B = "value1B";
2560+
prop1B = "longer value 1B";
25612561
};
25622562
''')
25632563

2564-
dt = dtlib.DT(main_file, include_path=[tmpdir])
2564+
dt = dtlib.DT(main_file, include_path=[tmpdir], base_dir=tmpdir)
25652565

25662566
test_node2 = dt.get_node('/test-node2')
25672567
prop2A = test_node2.props['prop2A']
@@ -2584,3 +2584,27 @@ def test_filename_and_lineno():
25842584
assert prop1A.lineno == 4
25852585
assert os.path.samefile(prop1B.filename, main_file)
25862586
assert prop1B.lineno == 13
2587+
2588+
# Test contents and alignment of the generated file comments
2589+
assert str(dt) == '''
2590+
/dts-v1/;
2591+
2592+
/* node '/' defined in included.dtsi:2 */
2593+
/ {
2594+
2595+
/* node '/test-node1' defined in included.dtsi:3 */
2596+
node1: test-node1 {
2597+
prop1A = "short value 1A"; /* in included.dtsi:4 */
2598+
prop1B = "longer value 1B"; /* in test_with_include.dts:13 */
2599+
};
2600+
2601+
/* node '/test-node2' defined in test_with_include.dts:6 */
2602+
node2: test-node2 {
2603+
prop2A = "value 2A"; /* in test_with_include.dts:7 */
2604+
prop2B = "multi",
2605+
"line",
2606+
"value",
2607+
"2B"; /* in test_with_include.dts:8 */
2608+
};
2609+
};
2610+
'''[1:-1]

0 commit comments

Comments
 (0)