Skip to content

Commit

Permalink
Updating copyright to 2014
Browse files Browse the repository at this point in the history
  • Loading branch information
czarneckid committed Jan 12, 2014
1 parent 8582f8a commit 693d613
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2011, Agora Games, LLC
Copyright (c) 2011-2014, Agora Games, LLC
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion chai/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand Down
2 changes: 1 addition & 1 deletion chai/_termcolor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand Down
16 changes: 8 additions & 8 deletions chai/chai.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand Down Expand Up @@ -42,15 +42,15 @@ def __init__(cls, name, bases, d):
name = '_'.join( [s.lower() for s in pieces] )
d[name] = getattr(base,attr_name)
setattr(cls, name, getattr(base,attr_name))

for func_name, func in d.items():
if func_name.startswith('test') and callable(func):
setattr(cls, func_name, ChaiTestType.test_wrapper(cls, func))

@staticmethod
def test_wrapper(cls, func):
"""
Wraps a test method, when that test method has completed it
Wraps a test method, when that test method has completed it
calls assert_expectations on the stub. This is to avoid getting to exceptions about the same error.
"""
def wrapper(self, *args, **kwargs):
Expand Down Expand Up @@ -82,7 +82,7 @@ def wrapper(self, *args, **kwargs):

if exceptions:
raise ExpectationNotSatisfied(*exceptions)

wrapper.__name__ = func.__name__
wrapper.__doc__ = func.__doc__
wrapper.__module__ = func.__module__
Expand All @@ -109,7 +109,7 @@ class ChaiBase(unittest.TestCase):
all_of = All
not_of = Not
matches = Regex
func = Function
func = Function
ignore_arg = Ignore
ignore = Ignore
in_arg = In
Expand Down Expand Up @@ -145,7 +145,7 @@ def setUp(self):
setattr(mod, 'stub', self.stub)
setattr(mod, 'expect', self.expect)
setattr(mod, 'mock', self.mock)


# Because cAmElCaSe sucks
setup = setUp
Expand All @@ -160,7 +160,7 @@ def tearDown(self):
while len(self._stubs):
stub = self._stubs.popleft()
stub.teardown() # Teardown the reset of the stub

# Do the mocks in reverse order in the rare case someone called mock(obj,attr)
# twice.
while len(self._mocks):
Expand Down Expand Up @@ -202,7 +202,7 @@ def mock(self, obj=None, attr=None, **kwargs):
if obj!=None and attr!=None:
rval._object = obj
rval._attr = attr

if hasattr(obj,attr):
orig = getattr(obj, attr)
self._mocks.append( (obj,attr,orig) )
Expand Down
20 changes: 10 additions & 10 deletions chai/comparators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand Down Expand Up @@ -37,7 +37,7 @@ def __init__(self, value):

def test(self, value):
return self._value == value

def __repr__(self):
return repr(self._value)
__str__ = __repr__
Expand Down Expand Up @@ -68,13 +68,13 @@ def __init__(self, types):

def test(self, value):
return isinstance(value, self._types)

def _format_name(self):
if isinstance(self._types, type):
return self._types.__name__
else:
return str([o.__name__ for o in self._types])

def __repr__(self):
return "IsA(%s)" % (self._format_name())
__str__ = __repr__
Expand All @@ -85,7 +85,7 @@ class Is(Comparator):
'''
def __init__(self, obj):
self._obj = obj

def test(self, value):
return self._obj is value

Expand All @@ -97,11 +97,11 @@ class AlmostEqual(Comparator):
'''
Compare a float value to n number of palces
'''

def __init__(self, float_value, places=7):
self._float_value = float_value
self._places = places

def test(self, value):
return round(value - self._float_value, self._places) == 0

Expand All @@ -113,7 +113,7 @@ class Regex(Comparator):
'''
Checks to see if a string matches a regex
'''

def __init__(self, pattern, flags=0):
self._pattern = pattern
self._flags = flags
Expand Down Expand Up @@ -141,7 +141,7 @@ def test(self, value):
def __repr__(self):
return "Any(%s)" % str(self._comparators)
__str__ = __repr__

class In(Comparator):
'''
Test if a key is in a list or dict
Expand Down Expand Up @@ -237,7 +237,7 @@ def clear(self):
Delete all cached values. Should only be used by the test suite.
'''
self._cache.clear()

def __init__(self, name):
self._name = name

Expand Down
12 changes: 6 additions & 6 deletions chai/exception.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand All @@ -24,7 +24,7 @@ class ChaiException(RuntimeError):
'''
Base class for an actual error in chai.
'''

class UnsupportedStub(ChaiException):
'''
Can't stub the requested object or attribute.
Expand All @@ -47,7 +47,7 @@ def __init__(self, msg=None, prefix=None, suffix=None, call=None, args=None, kwa

if prefix:
msg = '\n\n' + prefix.strip() + msg

if call:
msg += colored('\n\nNo expectation in place for\n', 'white', attrs=['bold'])
msg += colored(call, 'red')
Expand All @@ -62,7 +62,7 @@ def __init__(self, msg=None, prefix=None, suffix=None, call=None, args=None, kwa
if sys.exc_info()[0]:
msg += colored('\n\nWhile handling\n', 'white', attrs=['bold'])
msg += colored(''.join(traceback.format_exception( *sys.exc_info() )), 'red')

if suffix:
msg = msg + '\n\n' + suffix.strip()

Expand All @@ -72,9 +72,9 @@ class ExpectationNotSatisfied(ChaiAssertion):
'''
Raised when all expectations are not met
'''

def __init__(self, *expectations):
self._expectations = expectations

def __str__(self):
return str("\n".join([ str(e) for e in self._expectations]))
10 changes: 5 additions & 5 deletions chai/mock.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand All @@ -23,12 +23,12 @@ def __init__(self, **kwargs):
# appears to be a bug/feature in new classes where special members, or at least
# __call__, have to defined when the instance is created. Also, if it's already
# defined on the instance, getattr() will return the stub but the original
# method will always be called. Anyway, it's all crazy, but that's why the
# method will always be called. Anyway, it's all crazy, but that's why the
# implementation of __call__ is so weird.
def __call__(self, *args, **kwargs):
if isinstance(getattr(self,'__call__'), Stub):
return getattr(self,'__call__')(*args, **kwargs)

raise UnexpectedCall(call=self._name, args=args, kwargs=kwargs)

def __getattr__(self,name):
Expand Down Expand Up @@ -60,7 +60,7 @@ def __len__(self):
if isinstance(getattr(self,'__len__'), Stub):
return getattr(self,'__len__')()
raise UnexpectedCall(call=self._name+'.__len__')

def __getitem__(self, key):
if isinstance(getattr(self,'__getitem__'), Stub):
return getattr(self,'__getitem__')(key)
Expand Down Expand Up @@ -99,7 +99,7 @@ def __enter__(self):
if isinstance(getattr(self,'__enter__'), Stub):
return getattr(self,'__enter__')()
raise UnexpectedCall(call=self._name+'.__enter__')

def __exit__(self, exc_type, exc_value, traceback):
if isinstance(getattr(self,'__exit__'), Stub):
return getattr(self,'__exit__')(exc_type, exc_value, traceback)
Expand Down
18 changes: 9 additions & 9 deletions chai/stub.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'''
Copyright (c) 2011-2013, Agora Games, LLC All rights reserved.
Copyright (c) 2011-2014, Agora Games, LLC All rights reserved.
https://github.com/agoragames/chai/blob/master/LICENSE.txt
'''
Expand Down Expand Up @@ -248,7 +248,7 @@ def __call__(self, *args, **kwargs):
# If args don't match the expectation but its minimum counts have been
# met, close it and move on, else it's an unexpected call. Have to check
# counts here now due to the looser definitions of expectations in 0.3.x
# If we dont match, the counts aren't met and we're not allowing
# If we dont match, the counts aren't met and we're not allowing
# out-of-order, then break out and raise an exception.
if not exp.match(*args, **kwargs):
if exp.counts_met():
Expand All @@ -258,7 +258,7 @@ def __call__(self, *args, **kwargs):
else:
return exp.test(*args, **kwargs)

raise UnexpectedCall(call=self.name, suffix=self._format_exception(), args=args, kwargs=kwargs)
raise UnexpectedCall(call=self.name, suffix=self._format_exception(), args=args, kwargs=kwargs)

def _format_exception(self):
result = [
Expand Down Expand Up @@ -374,7 +374,7 @@ class method would be replaced with a bound method not a class method.
'''
# Figure out if this is a class method and we're unstubbing it on the class
# to which it belongs. This addresses an edge case where a module can
# to which it belongs. This addresses an edge case where a module can
# expose a method of an instance. gevent does this, for example.
if hasattr(self._obj,'__self__') and inspect.isclass(self._obj.__self__) and self._obj.__self__ is self._instance:
setattr(self._instance, self._attr, classmethod(self._obj.__func__))
Expand All @@ -400,7 +400,7 @@ def __init__(self, obj, attr=None):
elif getattr(obj, '__self__', None):
self._instance = obj.__self__
else:

raise UnsupportedStub("Failed to find instance of %s"%(obj))

if getattr(obj,'func_name', None):
Expand Down Expand Up @@ -474,14 +474,14 @@ def __call__(self, *args, **kwargs):
was an __init__.
'''
return super(StubNew,self).__call__( *(args[1:]), **kwargs )

def _teardown(self):
'''
Overload so that we can clear out the cache after a test run.
'''
# __new__ is a super-special case in that even when stubbing a class
# which implements its own __new__ and subclasses object, the
# "Class.__new__" reference is a staticmethod and not a method (or
# __new__ is a super-special case in that even when stubbing a class
# which implements its own __new__ and subclasses object, the
# "Class.__new__" reference is a staticmethod and not a method (or
# function). That confuses the "was_object_method" logic in StubFunction
# which then fails to delattr and from then on the class is corrupted.
# So skip that teardown and use a __new__-specific case.
Expand Down

0 comments on commit 693d613

Please sign in to comment.