Python3 fixes

This commit is contained in:
Stephan Kulow 2019-05-02 20:34:21 +02:00
parent 3b568a60dd
commit 58d6d7ca16
11 changed files with 44 additions and 29 deletions

View File

@ -1,7 +1,13 @@
from dateutil.parser import parse as date_parse
from metrics import timestamp
import requests
from urlparse import urljoin
try:
from urllib.parse import urljoin
except ImportError:
# python 2.x
from urlparse import urljoin
import yaml
BASEURL = 'http://review.tumbleweed.boombatower.com/data/'

View File

@ -467,7 +467,7 @@ def project_meta_revision(apiurl, project):
def entity_exists(apiurl, project, package=None):
try:
http_GET(makeurl(apiurl, filter(None, ['source', project, package]) + ['_meta']))
http_GET(makeurl(apiurl, list(filter(None, ['source', project, package])) + ['_meta']))
except HTTPError as e:
if e.code == 404:
return False

View File

@ -140,7 +140,7 @@ def dump_solv(name, baseurl):
pool = solv.Pool()
pool.setarch()
repo = pool.add_repo(''.join(random.choice(string.letters) for _ in range(5)))
repo = pool.add_repo(''.join(random.choice(string.ascii_letters) for _ in range(5)))
if not parse_repomd(repo, baseurl) and not parse_susetags(repo, baseurl):
raise Exception('neither repomd nor susetags exists in ' + baseurl)
@ -226,7 +226,7 @@ def update_project(apiurl, project):
os.lseek(f.fileno(), 0, os.SEEK_SET)
repo.add_susetags(solv.xfopen_fd(None, f.fileno()), defvendorid, None, solv.Repo.REPO_NO_INTERNALIZE|solv.Repo.SUSETAGS_RECORD_SHARES)
repo1 = pool.add_repo(''.join(random.choice(string.letters) for _ in range(5)))
repo1 = pool.add_repo(''.join(random.choice(string.ascii_letters) for _ in range(5)))
repo1.add_solv(solv_file)
print_repo_delta(pool, repo1, open(packages_file, 'w'))

View File

@ -95,7 +95,7 @@ class TestCase(unittest.TestCase):
print(self.output) # For debugging assertion failures.
def assertOutput(self, string):
self.assertTrue(string in self.output, '[MISSING] ' + string)
self.assertTrue(bytes(string, 'utf-8') in self.output, '[MISSING] ' + string)
def assertReview(self, rid, **kwargs):
request = get_request(self.apiurl, rid)

View File

@ -5,8 +5,8 @@ import unittest
import httpretty
import re
import osc.core
from osclib.conf import Config
from osclib.stagingapi import StagingAPI
from xml.etree import cElementTree as ET
@ -185,11 +185,11 @@ class TestApiCalls(OBSLocal.TestCase):
wf.api.create_package_container('openSUSE:Factory:Staging:B', 'wine')
url = wf.api.makeurl(['source', 'openSUSE:Factory:Staging:B', 'wine', '_meta'])
self.assertEqual(osc.core.http_GET(url).read(), '<package name="wine" project="openSUSE:Factory:Staging:B">\n <title/>\n <description/>\n</package>\n')
self.assertEqual(osc.core.http_GET(url).read().decode('utf-8'), '<package name="wine" project="openSUSE:Factory:Staging:B">\n <title/>\n <description/>\n</package>\n')
wf.api.create_package_container('openSUSE:Factory:Staging:B', 'wine', disable_build=True)
m = '<package name="wine" project="openSUSE:Factory:Staging:B">\n <title/>\n <description/>\n <build>\n <disable/>\n </build>\n</package>\n'
self.assertEqual(osc.core.http_GET(url).read(), m)
self.assertEqual(osc.core.http_GET(url).read().decode('utf-8'), m)
def test_review_handling(self):
"""Test whether accepting/creating reviews behaves correctly."""

View File

@ -121,7 +121,7 @@ class TestCheckCommand(unittest.TestCase):
def test_check_command_all(self):
"""Validate json conversion for all projects."""
wf = self.setup_vcr()
with open('tests/fixtures/project/staging_projects/openSUSE:Factory.json') as f:
with open('tests/fixtures/project/staging_projects/openSUSE:Factory.json', encoding='utf-8') as f:
wf.api.project_status = MagicMock(return_value=json.load(f))
report = self.checkcommand._check_project()
self.maxDiff = 20000
@ -130,7 +130,7 @@ class TestCheckCommand(unittest.TestCase):
def test_check_command_single(self):
"""Validate json conversion for a single project."""
wf = self.setup_vcr()
with open('tests/fixtures/project/staging_projects/openSUSE:Factory/H.json') as f:
with open('tests/fixtures/project/staging_projects/openSUSE:Factory/H.json', encoding='utf-8') as f:
wf.api.project_status = MagicMock(return_value=json.load(f))
report = self.checkcommand._check_project('H')
self.assertMultiLineEqual('\n'.join(report).strip(), H_REPORT.strip())

View File

@ -26,6 +26,10 @@ FIXTURES = os.path.join(os.getcwd(), 'tests/fixtures')
class TestTagChecker(unittest.TestCase):
def tearDown(self):
httpretty.reset()
httpretty.disable()
def setUp(self):
"""
Initialize the configuration
@ -209,9 +213,9 @@ Pico text editor while also offering a few enhancements.</description>
def change_request(result, method, uri, headers):
u = urlparse(uri)
if u.query == 'newstate=accepted&cmd=changereviewstate&by_user=maintbot':
if u.query == 'cmd=changereviewstate&newstate=accepted&by_user=maintbot':
result['state_accepted'] = True
elif u.query == 'newstate=declined&cmd=changereviewstate&by_user=maintbot':
elif u.query == 'cmd=changereviewstate&newstate=declined&by_user=maintbot':
result['state_accepted'] = False
return (200, headers, '<status code="ok"/>')

View File

@ -24,6 +24,10 @@ def rr(s):
class TestFactorySourceAccept(unittest.TestCase):
def tearDown(self):
httpretty.disable()
httpretty.reset()
def setUp(self):
"""
Initialize the configuration
@ -71,7 +75,7 @@ class TestFactorySourceAccept(unittest.TestCase):
""")
httpretty.register_uri(httpretty.GET,
rr("/source/Base:System/timezone?rev=481ecbe0dfc63ece3a1f1b5598f7d96c&view=info"),
rr("/source/Base:System/timezone?view=info&rev=481ecbe0dfc63ece3a1f1b5598f7d96c"),
match_querystring = True,
body = """
<sourceinfo package="timezone"
@ -106,6 +110,7 @@ class TestFactorySourceAccept(unittest.TestCase):
<filename>timezone.spec</filename>
</sourceinfo>
""")
httpretty.register_uri(httpretty.GET,
rr("/search/request?match=%28state%2F%40name%3D%27new%27+or+state%2F%40name%3D%27review%27%29+and+%28action%2Ftarget%2F%40project%3D%27openSUSE%3AFactory%27+or+action%2Fsource%2F%40project%3D%27openSUSE%3AFactory%27%29+and+%28action%2Ftarget%2F%40package%3D%27timezone%27+or+action%2Fsource%2F%40package%3D%27timezone%27%29+and+action%2F%40type%3D%27submit%27"),
match_querystring = True,
@ -172,7 +177,7 @@ class TestFactorySourceAccept(unittest.TestCase):
def test_source_not_in_factory(self):
httpretty.register_uri(httpretty.GET,
rr("/search/request?withfullhistory=1&match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27factory-source%27+and+%40state%3D%27new%27%5D"),
rr("/search/request?match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27factory-source%27+and+%40state%3D%27new%27%5D&withfullhistory=1"),
match_querystring = True,
body = """
<collection matches="1">
@ -271,7 +276,7 @@ class TestFactorySourceAccept(unittest.TestCase):
def change_request(result, method, uri, headers):
u = urlparse(uri)
if u.query == 'newstate=declined&cmd=changereviewstate&by_user=factory-source':
if u.query == 'cmd=changereviewstate&newstate=declined&by_user=factory-source':
result['factory_source_declined'] = True
return (200, headers, '<status code="ok"/>')

View File

@ -30,13 +30,13 @@ class TestFreeze(OBSLocal.TestCase):
fc = FreezeCommand(wf.api)
fp = self._get_fixture_path('staging-meta-for-bootstrap-copy.xml')
fixture = subprocess.check_output('/usr/bin/xmllint --format %s' % fp, shell=True)
fixture = subprocess.check_output('/usr/bin/xmllint --format %s' % fp, shell=True).decode('utf-8')
f = tempfile.NamedTemporaryFile(delete=False)
f.write(fc.prj_meta_for_bootstrap_copy('openSUSE:Factory:Staging:A'))
f.close()
output = subprocess.check_output('/usr/bin/xmllint --format %s' % f.name, shell=True)
output = subprocess.check_output('/usr/bin/xmllint --format %s' % f.name, shell=True).decode('utf-8')
for line in difflib.unified_diff(fixture.split("\n"), output.split("\n")):
print(line)

View File

@ -51,7 +51,7 @@ class TestMaintenance(unittest.TestCase):
"""
httpretty.register_uri(httpretty.GET,
rr("/search/request?withfullhistory=1&match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27maintbot%27+and+%40state%3D%27new%27%5D"),
rr('/search/request?match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27maintbot%27+and+%40state%3D%27new%27%5D&withfullhistory=1'),
match_querystring = True,
body = """
<collection matches="1">
@ -128,7 +128,7 @@ class TestMaintenance(unittest.TestCase):
def change_request(result, method, uri, headers):
u = urlparse(uri)
if u.query == 'by_package=mysql-workbench&cmd=addreview&by_project=server%3Adatabase':
if u.query == 'cmd=addreview&by_project=server%3Adatabase&by_package=mysql-workbench':
result['devel_review_added'] = True
return (200, headers, '<status code="ok"/>')
@ -164,7 +164,7 @@ class TestMaintenance(unittest.TestCase):
def test_non_maintainer_double_review(self):
httpretty.register_uri(httpretty.GET,
rr("/search/request?withfullhistory=1&match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27maintbot%27+and+%40state%3D%27new%27%5D"),
rr('/search/request?match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27maintbot%27+and+%40state%3D%27new%27%5D&withfullhistory=1'),
match_querystring = True,
body = """
<collection matches="1">
@ -285,7 +285,7 @@ class TestMaintenance(unittest.TestCase):
def test_backports_submit(self):
httpretty.register_uri(httpretty.GET,
rr("/search/request?withfullhistory=1&match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27maintbot%27+and+%40state%3D%27new%27%5D"),
rr('/search/request?match=state%2F%40name%3D%27review%27+and+review%5B%40by_user%3D%27maintbot%27+and+%40state%3D%27new%27%5D&withfullhistory=1'),
match_querystring = True,
body = """
<collection matches="1">

View File

@ -170,9 +170,9 @@ class StagingWorkflow(object):
def create_staging(self, suffix, freeze=False, rings=None):
project_links = []
if rings == 0:
project_links.append(self.project + ":Rings:0-Bootstrap")
project_links.append(self.project + ":Rings:0-Bootstrap")
if rings == 1 or rings == 0:
project_links.append(self.project + ":Rings:1-MinimalX")
project_links.append(self.project + ":Rings:1-MinimalX")
staging = Project(self.project + ':Staging:' + suffix, project_links=project_links)
if freeze:
FreezeCommand(self.api).perform(staging.name)
@ -181,12 +181,12 @@ class StagingWorkflow(object):
def __del__(self):
try:
self.remove()
self.remove()
except:
# normally exceptions in destructors are ignored but a info
# message is displayed. Make this a little more useful by
# printing it into the capture log
traceback.print_exc(None, sys.stdout)
# normally exceptions in destructors are ignored but a info
# message is displayed. Make this a little more useful by
# printing it into the capture log
traceback.print_exc(None, sys.stdout)
def remove(self):
print('deleting staging workflow')
@ -299,7 +299,7 @@ class Package(object):
def create_commit(self, text=None):
url = osc.core.makeurl(APIURL, ['source', self.project.name, self.name, 'README'])
if not text:
text = ''.join([random.choice(string.letters) for i in range(40)])
text = ''.join([random.choice(string.ascii_letters) for i in range(40)])
osc.core.http_PUT(url, data=text)
class Request(object):