Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions fudge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

"""

from __future__ import absolute_import
__version__ = '1.1.1'
import os
import re
import sys
import thread
import six.moves._thread
import warnings
from fudge.exc import FakeDeclarationError
from fudge.patcher import *
Expand Down Expand Up @@ -67,12 +68,12 @@ def expect_call(self, expected_call):
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(six.moves._thread.get_ident(), [])
return self.expected_calls[six.moves._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(six.moves._thread.get_ident(), {})
return self.expected_call_order[six.moves._thread.get_ident()]

def remember_expected_call_order(self, expected_call_order):
ordered_fakes = self.get_expected_call_order()
Expand Down Expand Up @@ -340,10 +341,10 @@ def __call__(self, *args, **kwargs):

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():
Expand Down
4 changes: 3 additions & 1 deletion fudge/inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
>>> fudge.clear_expectations()

"""
from __future__ import absolute_import
import warnings

from fudge.util import fmt_val, fmt_dict_vals
import six

__all__ = ['arg', 'arg_not']

Expand Down Expand Up @@ -505,7 +507,7 @@ def _repr_argspec(self):
return self._make_argspec(fmt_val(self.part))

def stringlike(self, value):
if isinstance(value, (str, unicode)):
if isinstance(value, (str, six.text_type)):
return value
else:
return str(value)
Expand Down
8 changes: 5 additions & 3 deletions fudge/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
See :ref:`using-fudge` for common scenarios.
"""

from __future__ import absolute_import
import six
__all__ = ['patch_object', 'with_patched_object', 'PatchHandler',
'patched_context', 'patch']

Expand Down Expand Up @@ -97,7 +99,7 @@ def caller(*args, **kw):
except:
etype, val, tb = sys.exc_info()
self.__exit__(etype, val, tb)
raise etype, val, tb
six.reraise(etype, val, tb)
else:
self.__exit__(None, None, None)
return value
Expand Down Expand Up @@ -256,7 +258,7 @@ def patch_object(obj, attr_name, patched_value):
'clean'

"""
if isinstance(obj, (str, unicode)):
if isinstance(obj, (str, six.text_type)):
obj_path = adjusted_path = obj
done = False
exc = None
Expand All @@ -276,7 +278,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
six.reraise(etype, val, tb)
if not adjusted_path.count('.'):
at_top_level = True
for part in obj_path.split('.')[1:]:
Expand Down
1 change: 1 addition & 0 deletions fudge/tests/_py3_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# FIXME: this is dumb

from __future__ import absolute_import
from fudge.tests.test_fudge import *
from fudge.tests.test_import_all import *
from fudge.tests.test_inspector import *
Expand Down
9 changes: 5 additions & 4 deletions fudge/tests/test_fudge.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import with_statement
from __future__ import absolute_import
import sys
import unittest

Expand Down Expand Up @@ -63,7 +64,7 @@ def test_has_property(self):
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')
Expand All @@ -89,7 +90,7 @@ def test_repr_shortens_long_values(self):
)
try:
fake.set_bits()
except AssertionError, exc:
except AssertionError as exc:
eq_(str(exc),
"fake:widget.set_bits('123456789101112131415161718192021222324252627...') "
"was called unexpectedly with args ()")
Expand Down Expand Up @@ -192,7 +193,7 @@ def test_arg_diffs_are_not_shortened(self):
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 "
Expand All @@ -207,7 +208,7 @@ def test_kwarg_diffs_are_not_shortened(self):
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 "
Expand Down
1 change: 1 addition & 0 deletions fudge/tests/test_import_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from __future__ import absolute_import
from fudge import *

def test_import_all():
Expand Down
1 change: 1 addition & 0 deletions fudge/tests/test_inspector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import re
import unittest

Expand Down
1 change: 1 addition & 0 deletions fudge/tests/test_inspector_import_all.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from __future__ import absolute_import
from fudge.inspector import *

def test_import_all():
Expand Down
1 change: 1 addition & 0 deletions fudge/tests/test_patcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import with_statement
from __future__ import absolute_import
import inspect
import unittest

Expand Down
21 changes: 11 additions & 10 deletions fudge/tests/test_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import thread
from __future__ import absolute_import
import six.moves._thread
import sys
import unittest
import fudge
Expand Down Expand Up @@ -85,13 +86,13 @@ def test_global_clear_expectations(self):
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):
Expand All @@ -114,7 +115,7 @@ def registry(num):

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)
Expand All @@ -131,17 +132,17 @@ def registry(num):

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,))
six.moves._thread.start_new_thread(registry, (1,))
six.moves._thread.start_new_thread(registry, (2,))
six.moves._thread.start_new_thread(registry, (3,))
six.moves._thread.start_new_thread(registry, (4,))
six.moves._thread.start_new_thread(registry, (5,))

count = 0
while thread_run.waiting > 0:
Expand Down
3 changes: 2 additions & 1 deletion fudge/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

from __future__ import absolute_import
try:
from functools import wraps
except ImportError:
Expand Down Expand Up @@ -30,7 +31,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]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_mailer(FakeSMTP):
author_email='kumar.mcmillan@gmail.com',
license="The MIT License",
packages=find_packages(exclude=['ez_setup']),
install_requires=[],
install_requires=['six'],
url='https://github.com/fudge-py/fudge',
include_package_data=True,
classifiers = [
Expand Down