Old xml.etree.cElementTree versions (python2) reorder the attributes
while recent xml.etree.cElementTree versions (python3) keep the
document order.
Example:
python3:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
b'<foo y="foo" x="bar" />'
>>>
python2:
>>> ET.tostring(ET.fromstring('<foo y="foo" x="bar"/>'))
'<foo x="bar" y="foo" />'
>>>
So far, the testsuite compared two serialized XML documents via a simple
string comparison. For instance via,
self.assertEqual(actual_serialized_xml, expected_serialized_xml) where
the expected_serialized_xml is, for instance, a hardcoded str. Obviously,
this would only work for python2 or python3.
In order to support both python versions, we first parse both XML
documents and then compare the corresponding trees (this is OK because
we do not care about comments etc.).
A related issue is the way how the testsuite compares data that is "send"
to the API. So far, this was a plain bytes comparison. Again, this won't
work in case of XML documents (see above). Moreover, we have currently
no notion to "indicate" that the transmitted data is an XML document.
As a workaround, we keep the plain bytes comparison and in case it fails,
we try an xml comparison (see above) as a last resort. Strictly speaking,
this is "wrong" (there might be cases (in the future) where we want to
ensure that the transmitted XML data is bit identical to a fixture file)
but a reasonable comprise for now.
Fixes: #751 ("[python3.8] Testsuite fails")
For now, we assume that if the "exp" keyword argument is specified,
then it is a str. In this case, we simply encode it (using the utf-8
encoding).
Also, simplify the code a bit (get rid of the if-statement that is
always executed).
Importing `cElementTree` has been deprecated since Python 3.3 -
importing `ElementTree` automatically uses the fastest
implementation available - and is finally removed in Python 3.9.
Importing cElementTree directly (not as part of xml) is an even
older relic, it's for Ye Time Before ElementTree Was Added To
Python and it was instead an external module...which was before
Python 2.5.
We still need to work with Python 2.7 for now, so we use a try/
except to handle both 2.7 and 3.9 cases. Also, let's not repeat
this import 12 times in one file for some reason.
Signed-off-by: Adam Williamson <awilliam@redhat.com>
With this change you get bytes with python3 and string in python2
disable travis tests for python 3.x until the full python3 branch
is merged. Otherwise the tests will fail and master isn't python3
ready anyways
There are many places can't be covered by 2to3, especially the
str/unicode -> str/bytes change done in python3. This is a big patch
incorporating all changes made in order to make python3 suite.py run
without any single failure.
It
* adapt the introspect_handler_3 for case there are no __defaults__
* adds the ET_ENCODING variable for ET.fromstring ("unicode" in py3,
"utf-8" in py2)
* (re)adds various builtins to both python versions
- memoryview to python 2.6
- bytes compatible with py3 to 2.6 and 2.7
and it changes few parts of tests/common.py in order to be compatible
with python3
* new urlcompare method compares all components or url + parsed query
string in a dictionary, so the ordering, neither quoting does not matter
* bytes builtin has been added to 2.x and used in assertEqualMultiline
- addfile():
* contains the complete logic for adding a file (=> simplified addFiles(...))
* semantic fixes
- delete_file():
* semantic fixes
- different handling of newly added/replaced files:
* added/replaced files are tracked in the .osc/_to_be_added file
- introduced new file state 'R': 'R' == "replaced"
* usecase: osc rm <file>; osc add <file> => new state is 'R'
* conceptually 'R' is equal to 'A'
- adapted revert() to support the new state (+ some other minor fixes)
- added testcases for addfile() and delete_file()