Merge "Fix non-determinism in tests." am: e34e5b5442
am: 087e9ef59b
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1347982 Change-Id: I28d775699333c041c04dffd08983a5e1e36aa54b
This commit is contained in:
commit
12822092eb
1 changed files with 28 additions and 4 deletions
|
@ -19,7 +19,7 @@ import io
|
|||
import textwrap
|
||||
import unittest
|
||||
|
||||
from xml.etree.ElementTree import tostring
|
||||
from xml.etree.ElementTree import fromstring
|
||||
from symbolfile import FUTURE_API_LEVEL, SymbolFileParser
|
||||
import ndk_api_coverage_parser as nparser
|
||||
|
||||
|
@ -27,6 +27,30 @@ import ndk_api_coverage_parser as nparser
|
|||
# pylint: disable=missing-docstring
|
||||
|
||||
|
||||
# https://stackoverflow.com/a/24349916/632035
|
||||
def etree_equal(elem1, elem2):
|
||||
"""Returns true if the two XML elements are equal.
|
||||
|
||||
xml.etree.ElementTree's comparison operator cares about the ordering of
|
||||
elements and attributes, but they are stored in an unordered dict so the
|
||||
ordering is not deterministic.
|
||||
|
||||
lxml is apparently API compatible with xml and does use an OrderedDict, but
|
||||
we don't have it in the tree.
|
||||
"""
|
||||
if elem1.tag != elem2.tag:
|
||||
return False
|
||||
if elem1.text != elem2.text:
|
||||
return False
|
||||
if elem1.tail != elem2.tail:
|
||||
return False
|
||||
if elem1.attrib != elem2.attrib:
|
||||
return False
|
||||
if len(elem1) != len(elem2):
|
||||
return False
|
||||
return all(etree_equal(c1, c2) for c1, c2 in zip(elem1, elem2))
|
||||
|
||||
|
||||
class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
||||
def test_parse(self):
|
||||
input_file = io.StringIO(textwrap.dedent(u"""\
|
||||
|
@ -52,9 +76,9 @@ class ApiCoverageSymbolFileParserTest(unittest.TestCase):
|
|||
"""))
|
||||
parser = SymbolFileParser(input_file, {}, "", FUTURE_API_LEVEL, True, True)
|
||||
generator = nparser.XmlGenerator(io.StringIO())
|
||||
result = tostring(generator.convertToXml(parser.parse())).decode()
|
||||
expected = '<ndk-library><symbol apex="True" arch="" introduced="23" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_name_to_log_id" /><symbol arch="arm" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_log_id_to_name" /><symbol arch="" introduced-arm64="24" introduced-x86="23" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_assert" /><symbol arch="" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_buf_write" /><symbol arch="" is_deprecated="False" is_platform="True" llndk="True" name="android_fdtrack" /><symbol arch="" introduced="23" is_deprecated="False" is_platform="True" name="android_net" /></ndk-library>'
|
||||
self.assertEqual(expected, result)
|
||||
result = generator.convertToXml(parser.parse())
|
||||
expected = fromstring('<ndk-library><symbol apex="True" arch="" introduced="23" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_name_to_log_id" /><symbol arch="arm" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" llndk="True" name="android_log_id_to_name" /><symbol arch="" introduced-arm64="24" introduced-x86="23" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_assert" /><symbol arch="" introduced-arm64="24" introduced-x86="24" introduced-x86_64="24" is_deprecated="False" is_platform="False" name="__android_log_buf_write" /><symbol arch="" is_deprecated="False" is_platform="True" llndk="True" name="android_fdtrack" /><symbol arch="" introduced="23" is_deprecated="False" is_platform="True" name="android_net" /></ndk-library>')
|
||||
self.assertTrue(etree_equal(expected, result))
|
||||
|
||||
|
||||
def main():
|
||||
|
|
Loading…
Reference in a new issue