summaryrefslogtreecommitdiff
path: root/unit_tests/mock.py
diff options
context:
space:
mode:
authorJason Pellerin <jpellerin@gmail.com>2006-12-19 03:35:52 +0000
committerJason Pellerin <jpellerin@gmail.com>2006-12-19 03:35:52 +0000
commit05bff2bd41a7d1930dbfc4eb87a19e1461f5b467 (patch)
tree23e570e05f07cfda8862862ba54bd53331031468 /unit_tests/mock.py
downloadnose-05bff2bd41a7d1930dbfc4eb87a19e1461f5b467.tar.gz
[0.10-dev] Imported last revision from python-hosting to start 0.10-dev branch
Diffstat (limited to 'unit_tests/mock.py')
-rw-r--r--unit_tests/mock.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/unit_tests/mock.py b/unit_tests/mock.py
new file mode 100644
index 0000000..745ed14
--- /dev/null
+++ b/unit_tests/mock.py
@@ -0,0 +1,53 @@
+"""Useful mock objects.
+"""
+
+class Bucket(object):
+ def __init__(self, **kw):
+ self.__dict__['d'] = {}
+ self.__dict__['d'].update(kw)
+
+ def __getattr__(self, attr):
+ if not self.__dict__.has_key('d'):
+ return None
+ return self.__dict__['d'].get(attr)
+
+ def __setattr__(self, attr, val):
+ self.d[attr] = val
+
+
+class MockOptParser(object):
+ def __init__(self):
+ self.opts = []
+ def add_option(self, *args, **kw):
+ self.opts.append((args, kw))
+
+
+class Mod(object):
+ def __init__(self, name, **kw):
+ self.__name__ = name
+ if 'file' in kw:
+ self.__file__ = kw.pop('file')
+ else:
+ if 'path' in kw:
+ path = kw.pop('path')
+ else:
+ path = ''
+ self.__file__ = "%s/%s.pyc" % (path, name.replace('.', '/'))
+ self.__path__ = [ self.__file__ ] # FIXME?
+ self.__dict__.update(kw)
+
+
+class Result(object):
+ def __init__(self):
+ from nose.result import Result
+ import types
+ self.errors = []
+ for attr in dir(Result):
+ if type(getattr(Result, attr)) is types.MethodType:
+ if not hasattr(self, attr):
+ setattr(self, attr, lambda s, *a, **kw: None)
+ elif not attr.startswith('__'):
+ setattr(self, attr, None)
+
+ def addError(self, test, err):
+ self.errors.append(err)