1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-08-22 22:48:51 +02:00

python3 compatibility: make all unit test pass

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
This commit is contained in:
Michal Vyskocil
2013-04-10 11:34:59 +02:00
committed by Adrian Schröter
parent f0186dbde8
commit b787ca2b39
4 changed files with 90 additions and 47 deletions

View File

@@ -13,10 +13,12 @@ import time
try:
from urllib.parse import urlsplit
from urllib.error import HTTPError
ET_ENCODING = "unicode"
except ImportError:
#python 2.x
from urlparse import urlsplit
from urllib2 import HTTPError
ET_ENCODING = "utf-8"
from optparse import SUPPRESS_HELP
@@ -3541,10 +3543,9 @@ Please submit there instead, or use --nodevelproject to force direct submission.
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
close_fds=True)
p.stdin.write(rdiff)
p.stdin.write(rdiff.encode())
p.stdin.close()
diffstat = "".join(p.stdout.readlines())
print(diffstat)
print("".join(x.decode() for x in p.stdout.readlines()))
elif opts.unified:
print()
print(rdiff)
@@ -6669,7 +6670,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
data.find('title').text = ''.join(title)
data.find('description').text = ''.join(descr)
data.find('url').text = url
data = ET.tostring(data)
data = ET.tostring(data, encoding=ET_ENCODING)
else:
print('error - cannot get meta data', file=sys.stderr)
sys.exit(1)