From 2f1d32ba80816e3880a464a63d8f3f549a2be9e2 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Tue, 12 Jul 2011 22:02:50 +0200 Subject: [PATCH] Add IsA helper to tests to provde any_int, any_str and any_unicode --- tests/__init__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index 1d4d2e3d..663b89ec 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -22,3 +22,22 @@ def path_to_data_dir(name): path = os.path.abspath(path) return os.path.join(path, name) +class IsA(object): + def __init__(self, klass): + self.klass = klass + + def __eq__(self, rhs): + try: + return isinstance(rhs, self.klass) + except TypeError: + return type(rhs) == type(self.klass) + + def __ne__(self, rhs): + return not self.__eq__(rhs) + + def __repr__(self): + return str(self.klass) + +any_int = IsA(int) +any_str = IsA(str) +any_unicode = IsA(unicode)