Browse Source

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 <l.burelli@arduino.cc>
pull/88935/head
Luca Burelli 2 months ago committed by Benjamin Cabé
parent
commit
fe7f71ba16
  1. 34
      scripts/dts/python-devicetree/tests/test_dtlib.py

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

@ -2538,7 +2538,7 @@ def test_filename_and_lineno():
f.write('''/* a new node */ f.write('''/* a new node */
/ { / {
node1: test-node1 { node1: test-node1 {
prop1A = "value1A"; prop1A = "short value 1A";
}; };
}; };
''') ''')
@ -2551,17 +2551,17 @@ def test_filename_and_lineno():
/ { / {
node2: test-node2 { node2: test-node2 {
prop2A = "value2A"; prop2A = "value 2A";
prop2B = "value2B"; prop2B = "multi", "line", "value", "2B";
}; };
}; };
&node1 { &node1 {
prop1B = "value1B"; prop1B = "longer value 1B";
}; };
''') ''')
dt = dtlib.DT(main_file, include_path=[tmpdir]) dt = dtlib.DT(main_file, include_path=[tmpdir], base_dir=tmpdir)
test_node2 = dt.get_node('/test-node2') test_node2 = dt.get_node('/test-node2')
prop2A = test_node2.props['prop2A'] prop2A = test_node2.props['prop2A']
@ -2584,3 +2584,27 @@ def test_filename_and_lineno():
assert prop1A.lineno == 4 assert prop1A.lineno == 4
assert os.path.samefile(prop1B.filename, main_file) assert os.path.samefile(prop1B.filename, main_file)
assert prop1B.lineno == 13 assert prop1B.lineno == 13
# Test contents and alignment of the generated file comments
assert str(dt) == '''
/dts-v1/;
/* node '/' defined in included.dtsi:2 */
/ {
/* node '/test-node1' defined in included.dtsi:3 */
node1: test-node1 {
prop1A = "short value 1A"; /* in included.dtsi:4 */
prop1B = "longer value 1B"; /* in test_with_include.dts:13 */
};
/* node '/test-node2' defined in test_with_include.dts:6 */
node2: test-node2 {
prop2A = "value 2A"; /* in test_with_include.dts:7 */
prop2B = "multi",
"line",
"value",
"2B"; /* in test_with_include.dts:8 */
};
};
'''[1:-1]

Loading…
Cancel
Save