Move context, tidy up object model and add memory to test_rig.

This commit is contained in:
Mike Auty
2013-05-05 22:06:38 +01:00
parent dc65c356fc
commit e351958413
12 changed files with 196 additions and 92 deletions
+8 -1
View File
@@ -10,9 +10,16 @@ class ValidityRoutines(object):
def type_check(self, value, valid_type):
"""Checks that value is an instance of valid_type, and returns value if it is, or throws a TypeError otherwise"""
if not isinstance(value, valid_type):
raise TypeError(self.__class__.__name__ + " expected " + valid_type.__class__.__name__ + ", not " + type(value))
print(repr(valid_type), repr(type(value).__name__))
raise TypeError(self.__class__.__name__ + " expected " + valid_type.__name__ + ", not " + type(value).__name__)
return value
def class_check(self, klass, valid_class):
"""Checks that value is an instance of valid_type, and returns value if it is, or throws a TypeError otherwise"""
if not issubclass(klass, valid_class):
raise TypeError(self.__class__.__name__ + " expected " + valid_class.__name__ + ", not " + klass.__name__)
return klass
def confirm(self, assertion, error):
"""Acts like an assertion, but will not be disabled when __debug__ is disabled"""
if not assertion: