1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
|
From: Carsten Schoenert <c.schoenert@t-online.de>
Date: Sat, 6 Nov 2021 12:03:25 +0100
Subject: Porting existing code over to Python3 by using 2to3
Upstream has done some usage of 2to3 in real time to convert the source
code into Python3 compatible code.
This requires the existence of 2to3 at build time, but Debian is only
supporting Python3 for some time. This patch does nothing more than the
patching of the source which was done by 2to3 in real time before.
This patch should become obsolete once upstream will completely move to
support Python3 only.
Forwarded: not-needed
---
fudge/__init__.py | 22 +++++++++++-----------
fudge/inspector.py | 4 ++--
fudge/patcher.py | 6 +++---
fudge/tests/test_fudge.py | 10 +++++-----
fudge/tests/test_inspector.py | 24 ++++++++++++------------
fudge/tests/test_patcher.py | 2 +-
fudge/tests/test_registry.py | 20 ++++++++++----------
fudge/util.py | 2 +-
8 files changed, 45 insertions(+), 45 deletions(-)
diff --git a/fudge/__init__.py b/fudge/__init__.py
index cf0aea7..e83dab7 100644
--- a/fudge/__init__.py
+++ b/fudge/__init__.py
@@ -9,7 +9,7 @@ __version__ = '1.1.1'
import os
import re
import sys
-import thread
+import _thread
import warnings
from fudge.exc import FakeDeclarationError
from fudge.patcher import *
@@ -49,7 +49,7 @@ class Registry(object):
self.clear_actual_calls()
for stack in self.call_stacks:
stack.reset()
- for fake, call_order in self.get_expected_call_order().items():
+ for fake, call_order in list(self.get_expected_call_order().items()):
call_order.reset_calls()
def clear_expectations(self):
@@ -67,12 +67,12 @@ class Registry(object):
this_call_order.add_expected_call(expected_call)
def get_expected_calls(self):
- self.expected_calls.setdefault(thread.get_ident(), [])
- return self.expected_calls[thread.get_ident()]
+ self.expected_calls.setdefault(_thread.get_ident(), [])
+ return self.expected_calls[_thread.get_ident()]
def get_expected_call_order(self):
- self.expected_call_order.setdefault(thread.get_ident(), {})
- return self.expected_call_order[thread.get_ident()]
+ self.expected_call_order.setdefault(_thread.get_ident(), {})
+ return self.expected_call_order[_thread.get_ident()]
def remember_expected_call_order(self, expected_call_order):
ordered_fakes = self.get_expected_call_order()
@@ -94,7 +94,7 @@ class Registry(object):
for exp in self.get_expected_calls():
exp.assert_called()
exp.assert_times_called()
- for fake, call_order in self.get_expected_call_order().items():
+ for fake, call_order in list(self.get_expected_call_order().items()):
call_order.assert_order_met(finalize=True)
finally:
self.clear_calls()
@@ -305,7 +305,7 @@ class Call(object):
# i.e. keyword args that are only checked if the call provided them
if self.expected_matching_kwargs:
for expected_arg, expected_value in \
- self.expected_matching_kwargs.items():
+ list(self.expected_matching_kwargs.items()):
if expected_arg in kwargs:
if expected_value != kwargs[expected_arg]:
raise AssertionError(
@@ -340,13 +340,13 @@ class Call(object):
if self.expected_kwarg_count is None:
self.expected_kwarg_count = 0
- if len(kwargs.keys()) != self.expected_kwarg_count:
+ if len(list(kwargs.keys())) != self.expected_kwarg_count:
raise AssertionError(
"%s was called with %s keyword arg(s) but expected %s" % (
- self, len(kwargs.keys()), self.expected_kwarg_count))
+ self, len(list(kwargs.keys())), self.expected_kwarg_count))
if self.unexpected_kwargs:
- for un_key, un_val in self.unexpected_kwargs.items():
+ for un_key, un_val in list(self.unexpected_kwargs.items()):
if un_key in kwargs and kwargs[un_key] == un_val:
raise AssertionError(
"%s was called unexpectedly with kwarg %s=%s" %
diff --git a/fudge/inspector.py b/fudge/inspector.py
index 4de684c..a9db739 100644
--- a/fudge/inspector.py
+++ b/fudge/inspector.py
@@ -505,7 +505,7 @@ class Stringlike(ValueTest):
return self._make_argspec(fmt_val(self.part))
def stringlike(self, value):
- if isinstance(value, (str, unicode)):
+ if isinstance(value, str):
return value
else:
return str(value)
@@ -530,7 +530,7 @@ class HasAttr(ValueTest):
return self._make_argspec(", ".join(sorted(fmt_dict_vals(self.attributes))))
def __eq__(self, other):
- for name, value in self.attributes.items():
+ for name, value in list(self.attributes.items()):
if not hasattr(other, name):
return False
if getattr(other, name) != value:
diff --git a/fudge/patcher.py b/fudge/patcher.py
index 8ca7e68..74892dc 100644
--- a/fudge/patcher.py
+++ b/fudge/patcher.py
@@ -80,7 +80,7 @@ class patch(object):
except:
etype, val, tb = sys.exc_info()
self.__exit__(etype, val, tb)
- raise etype, val, tb
+ raise etype(val).with_traceback(tb)
else:
self.__exit__(None, None, None)
return value
@@ -239,7 +239,7 @@ def patch_object(obj, attr_name, patched_value):
'clean'
"""
- if isinstance(obj, (str, unicode)):
+ if isinstance(obj, str):
obj_path = adjusted_path = obj
done = False
exc = None
@@ -259,7 +259,7 @@ def patch_object(obj, attr_name, patched_value):
# We're at the top level module and it doesn't exist.
# Raise the first exception since it will make more sense:
etype, val, tb = exc
- raise etype, val, tb
+ raise etype(val).with_traceback(tb)
if not adjusted_path.count('.'):
at_top_level = True
for part in obj_path.split('.')[1:]:
diff --git a/fudge/tests/test_fudge.py b/fudge/tests/test_fudge.py
index 786ac0a..a9b94cf 100644
--- a/fudge/tests/test_fudge.py
+++ b/fudge/tests/test_fudge.py
@@ -1,4 +1,4 @@
-from __future__ import with_statement
+
import sys
import unittest
@@ -63,7 +63,7 @@ class TestFake(unittest.TestCase):
eq_(my_obj.vice, 'versa')
try:
my_obj.stuff
- except Exception, exc:
+ except Exception as exc:
eq_(str(exc), 'broken stuff')
else:
raise RuntimeError('expected Exception')
@@ -89,7 +89,7 @@ class TestFake(unittest.TestCase):
)
try:
fake.set_bits()
- except AssertionError, exc:
+ except AssertionError as exc:
eq_(str(exc),
"fake:widget.set_bits('123456789101112131415161718192021222324252627...') "
"was called unexpectedly with args ()")
@@ -192,7 +192,7 @@ class TestLongArgValues(unittest.TestCase):
try:
# this should not be shortened but the above arg spec should:
fake.set_bits("99999999999999999999999999999999999999999999999999999999")
- except AssertionError, exc:
+ except AssertionError as exc:
eq_(str(exc),
"fake:widget.set_bits('123456789101112131415161718192021222324252627...') "
"was called unexpectedly with args "
@@ -207,7 +207,7 @@ class TestLongArgValues(unittest.TestCase):
try:
# this should not be shortened but the above arg spec should:
fake.set_bits(newbits="99999999999999999999999999999999999999999999999999999999")
- except AssertionError, exc:
+ except AssertionError as exc:
eq_(str(exc),
"fake:widget.set_bits(newbits='123456789101112131415161718192021222324252627...') "
"was called unexpectedly with args "
diff --git a/fudge/tests/test_inspector.py b/fudge/tests/test_inspector.py
index 52ba3db..31a4e30 100644
--- a/fudge/tests/test_inspector.py
+++ b/fudge/tests/test_inspector.py
@@ -133,8 +133,8 @@ class TestObjectlike(unittest.TestCase):
eq_(repr(o), "arg.has_attr(one=1, two='two')")
def test_objectlike_unicode(self):
- o = inspector.HasAttr(one=1, ivan=u"Ivan_Krsti\u0107")
- eq_(repr(o), "arg.has_attr(ivan=%s, one=1)" % repr(u'Ivan_Krsti\u0107'))
+ o = inspector.HasAttr(one=1, ivan="Ivan_Krsti\u0107")
+ eq_(repr(o), "arg.has_attr(ivan=%s, one=1)" % repr('Ivan_Krsti\u0107'))
def test_objectlike_repr_long_val(self):
o = inspector.HasAttr(
@@ -157,24 +157,24 @@ class TestStringlike(unittest.TestCase):
db.execute("select from")
def test_startswith_ok_uni(self):
- db = Fake("db").expects("execute").with_args(arg.startswith(u"Ivan_Krsti\u0107"))
- db.execute(u"Ivan_Krsti\u0107(); foo();")
+ db = Fake("db").expects("execute").with_args(arg.startswith("Ivan_Krsti\u0107"))
+ db.execute("Ivan_Krsti\u0107(); foo();")
def test_startswith_unicode(self):
- p = inspector.Startswith(u"Ivan_Krsti\u0107")
- eq_(repr(p), "arg.startswith(%s)" % repr(u'Ivan_Krsti\u0107'))
+ p = inspector.Startswith("Ivan_Krsti\u0107")
+ eq_(repr(p), "arg.startswith(%s)" % repr('Ivan_Krsti\u0107'))
def test_endswith_ok(self):
db = Fake("db").expects("execute").with_args(arg.endswith("values (1,2,3,4)"))
db.execute("insert into foo values (1,2,3,4)")
def test_endswith_ok_uni(self):
- db = Fake("db").expects("execute").with_args(arg.endswith(u"Ivan Krsti\u0107"))
- db.execute(u"select Ivan Krsti\u0107")
+ db = Fake("db").expects("execute").with_args(arg.endswith("Ivan Krsti\u0107"))
+ db.execute("select Ivan Krsti\u0107")
def test_endswith_unicode(self):
- p = inspector.Endswith(u"Ivan_Krsti\u0107")
- eq_(repr(p), "arg.endswith(%s)" % repr(u'Ivan_Krsti\u0107'))
+ p = inspector.Endswith("Ivan_Krsti\u0107")
+ eq_(repr(p), "arg.endswith(%s)" % repr('Ivan_Krsti\u0107'))
def test_startswith_repr(self):
p = inspector.Startswith("_start")
@@ -247,8 +247,8 @@ class TestContains(unittest.TestCase):
eq_(repr(c), "arg.contains(':part:')")
def test_unicode(self):
- c = inspector.Contains(u"Ivan_Krsti\u0107")
- eq_(repr(c), "arg.contains(%s)" % repr(u'Ivan_Krsti\u0107'))
+ c = inspector.Contains("Ivan_Krsti\u0107")
+ eq_(repr(c), "arg.contains(%s)" % repr('Ivan_Krsti\u0107'))
class TestMakeValueTest(unittest.TestCase):
diff --git a/fudge/tests/test_patcher.py b/fudge/tests/test_patcher.py
index 54e7ad5..31dcb3b 100644
--- a/fudge/tests/test_patcher.py
+++ b/fudge/tests/test_patcher.py
@@ -1,4 +1,4 @@
-from __future__ import with_statement
+
import inspect
import unittest
diff --git a/fudge/tests/test_registry.py b/fudge/tests/test_registry.py
index a518146..112435c 100644
--- a/fudge/tests/test_registry.py
+++ b/fudge/tests/test_registry.py
@@ -1,5 +1,5 @@
-import thread
+import _thread
import sys
import unittest
import fudge
@@ -85,13 +85,13 @@ class TestRegistry(unittest.TestCase):
eq_(len(self.reg.get_expected_calls()), 1)
exp_order = ExpectedCallOrder(self.fake)
self.reg.remember_expected_call_order(exp_order)
- eq_(self.reg.get_expected_call_order().keys(), [self.fake])
+ eq_(list(self.reg.get_expected_call_order().keys()), [self.fake])
fudge.clear_expectations()
eq_(len(self.reg.get_expected_calls()), 0,
"clear_expectations() should reset expectations")
- eq_(len(self.reg.get_expected_call_order().keys()), 0,
+ eq_(len(list(self.reg.get_expected_call_order().keys())), 0,
"clear_expectations() should reset expected call order")
def test_multithreading(self):
@@ -114,7 +114,7 @@ class TestRegistry(unittest.TestCase):
exp_order = ExpectedCallOrder(self.fake)
reg.remember_expected_call_order(exp_order)
- eq_(len(reg.get_expected_call_order().keys()), 1)
+ eq_(len(list(reg.get_expected_call_order().keys())), 1)
# registered first time on __init__ :
exp = ExpectedCall(self.fake, 'callMe', call_order=exp_order)
@@ -131,17 +131,17 @@ class TestRegistry(unittest.TestCase):
fudge.verify()
fudge.clear_expectations()
- except Exception, er:
+ except Exception as er:
thread_run.errors.append(er)
raise
finally:
thread_run.waiting -= 1
- thread.start_new_thread(registry, (1,))
- thread.start_new_thread(registry, (2,))
- thread.start_new_thread(registry, (3,))
- thread.start_new_thread(registry, (4,))
- thread.start_new_thread(registry, (5,))
+ _thread.start_new_thread(registry, (1,))
+ _thread.start_new_thread(registry, (2,))
+ _thread.start_new_thread(registry, (3,))
+ _thread.start_new_thread(registry, (4,))
+ _thread.start_new_thread(registry, (5,))
count = 0
while thread_run.waiting > 0:
diff --git a/fudge/util.py b/fudge/util.py
index 1f81e12..d9daf40 100644
--- a/fudge/util.py
+++ b/fudge/util.py
@@ -30,7 +30,7 @@ def fmt_dict_vals(dict_vals, shorten=True):
"""Returns list of key=val pairs formatted
for inclusion in an informative text string.
"""
- items = dict_vals.items()
+ items = list(dict_vals.items())
if not items:
return [fmt_val(None, shorten=shorten)]
return ["%s=%s" % (k, fmt_val(v, shorten=shorten)) for k,v in items]
|