From 4d3fcd9dc1f2c53272abd9c9fc8464df81f0da3e Mon Sep 17 00:00:00 2001
From: Oleg Girko
Date: Thu, 13 Aug 2015 12:40:16 +0100
Subject: [PATCH] Fix Python 3 support.
This change fixes errors when running test suite with Python 3.
Signed-off-by: Oleg Girko
---
osc/core.py | 2 +-
tests/common.py | 2 +-
tests/test_commit.py | 9 +++++++--
3 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/osc/core.py b/osc/core.py
index 0b48d63c..9108c742 100644
--- a/osc/core.py
+++ b/osc/core.py
@@ -3701,7 +3701,7 @@ def show_project_sourceinfo(apiurl, project, nofilename, *packages):
def get_project_sourceinfo(apiurl, project, nofilename, *packages):
try:
si = show_project_sourceinfo(apiurl, project, nofilename, *packages)
- except HTTPError, e:
+ except HTTPError as e:
# old API servers (e.g. 2.3.5) do not know the 'nofilename' parameter, so retry without
if e.code == 400 and nofilename:
return get_project_sourceinfo(apiurl, project, False, *packages)
diff --git a/tests/common.py b/tests/common.py
index f0fee8b5..f194b4a2 100644
--- a/tests/common.py
+++ b/tests/common.py
@@ -92,7 +92,7 @@ class MyHTTPHandler(HTTPHandler):
elif exp is None:
raise RuntimeError('exp or expfile required')
if exp is not None:
- if req.get_data() != bytes(exp, "utf-8"):
+ if req.data != bytes(exp, "utf-8"):
raise RequestDataMismatch(req.get_full_url(), repr(req.get_data()), repr(exp))
return self.__get_response(req.get_full_url(), **kwargs)
diff --git a/tests/test_commit.py b/tests/test_commit.py
index aed14b44..02baa855 100644
--- a/tests/test_commit.py
+++ b/tests/test_commit.py
@@ -2,9 +2,14 @@ import osc.core
import osc.oscerr
import os
import sys
-import urllib2
from common import GET, PUT, POST, DELETE, OscTestCase
from xml.etree import cElementTree as ET
+try:
+ from urllib.error import HTTPError
+except ImportError:
+ #python 2.x
+ from urllib2 import HTTPError
+
FIXTURES_DIR = os.path.join(os.getcwd(), 'commit_fixtures')
def suite():
@@ -302,7 +307,7 @@ class TestCommit(OscTestCase):
self._change_to_pkg('simple')
p = osc.core.Package('.')
self._check_status(p, 'nochange', 'M')
- self.assertRaises(urllib2.HTTPError, p.commit)
+ self.assertRaises(HTTPError, p.commit)
exp = 'Sending nochange\nTransmitting file data .'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_status(p, 'nochange', 'M')