dtlib: fix include_path edge case
The documentation says DT.__init__ takes any iterable for the include_path, but this leads to bad results when you pass it something other than a 'real' sequence (list/tuple/etc), like a generator: >>> dt = DT('/tmp/foo.dts', (x for x in ['a', 'b', 'c'])) >>> repr(dt) "DT(filename='/tmp/foo.dts', include_path=<generator object ...>)" Make a copy in list form just to avoid things like this. Add a test for this and relax the regular expression in the existing test case related to this. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
628fb90412
commit
b13b5b8b3a
2 changed files with 11 additions and 5 deletions
|
@ -708,7 +708,7 @@ class DT:
|
||||||
relative to the .dts file that contains the /include/ or /incbin/.
|
relative to the .dts file that contains the /include/ or /incbin/.
|
||||||
"""
|
"""
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self._include_path = include_path
|
self._include_path = list(include_path)
|
||||||
|
|
||||||
with open(filename, encoding="utf-8") as f:
|
with open(filename, encoding="utf-8") as f:
|
||||||
self._file_contents = f.read()
|
self._file_contents = f.read()
|
||||||
|
|
|
@ -2077,7 +2077,7 @@ foo: / {
|
||||||
def test_reprs():
|
def test_reprs():
|
||||||
'''Test the __repr__() functions.'''
|
'''Test the __repr__() functions.'''
|
||||||
|
|
||||||
dt = parse("""
|
dts = """
|
||||||
/dts-v1/;
|
/dts-v1/;
|
||||||
|
|
||||||
/ {
|
/ {
|
||||||
|
@ -2086,16 +2086,22 @@ def test_reprs():
|
||||||
y = < 1 >;
|
y = < 1 >;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
""",
|
"""
|
||||||
include_path=("foo", "bar"))
|
|
||||||
|
|
||||||
assert re.fullmatch(r"DT\(filename='.*', include_path=\('foo', 'bar'\)\)",
|
dt = parse(dts, include_path=("foo", "bar"))
|
||||||
|
|
||||||
|
assert re.fullmatch(r"DT\(filename='.*', include_path=.'foo', 'bar'.\)",
|
||||||
repr(dt))
|
repr(dt))
|
||||||
assert re.fullmatch("<Property 'x' at '/' in '.*'>",
|
assert re.fullmatch("<Property 'x' at '/' in '.*'>",
|
||||||
repr(dt.root.props["x"]))
|
repr(dt.root.props["x"]))
|
||||||
assert re.fullmatch("<Node /sub in '.*'>",
|
assert re.fullmatch("<Node /sub in '.*'>",
|
||||||
repr(dt.root.nodes["sub"]))
|
repr(dt.root.nodes["sub"]))
|
||||||
|
|
||||||
|
dt = parse(dts, include_path=iter(("foo", "bar")))
|
||||||
|
|
||||||
|
assert re.fullmatch(r"DT\(filename='.*', include_path=.'foo', 'bar'.\)",
|
||||||
|
repr(dt))
|
||||||
|
|
||||||
def test_names():
|
def test_names():
|
||||||
'''Tests for node/property names.'''
|
'''Tests for node/property names.'''
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue