[pypy-svn] r29512 - pypy/dist/pypy/translator/cli/test
antocuni at codespeak.net
antocuni at codespeak.net
Fri Jun 30 00:19:18 CEST 2006
Author: antocuni
Date: Fri Jun 30 00:19:13 2006
New Revision: 29512
Modified:
pypy/dist/pypy/translator/cli/test/test_oo.py
Log:
refactoring
Modified: pypy/dist/pypy/translator/cli/test/test_oo.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_oo.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_oo.py Fri Jun 30 00:19:13 2006
@@ -1,13 +1,5 @@
-from pypy.translator.cli.test.runtest import check
from pypy.translator.cli.test.runtest import CliTest
-def test_oo():
- for name, func in globals().iteritems():
- if not name.startswith('oo_'):
- continue
-
- yield check, func, [int, int], (42, 13)
-
class MyClass:
INCREMENT = 1
@@ -38,6 +30,20 @@
return self.x - self.y
+# helper functions
+def call_method(obj):
+ return obj.compute()
+
+def init_and_compute(cls, x, y):
+ return cls(x, y).compute()
+
+def nonnull_helper(lst):
+ if lst is None:
+ return 1
+ else:
+ return 2
+
+
class TestOO(CliTest):
def test_indirect_call(self):
def f():
@@ -66,55 +72,54 @@
return x(n)
assert self.interpret(fn, [True, 42]) == 43
-# helper functions
-def call_method(obj):
- return obj.compute()
-
-def init_and_compute(cls, x, y):
- return cls(x, y).compute()
-
-# test functions
-def oo_compute(x, y):
- obj = MyClass(x, y)
- return obj.compute()
-
-def oo_compute_multiply(x, y):
- obj = MyClass(x, y)
- return obj.compute_and_multiply(2)
-
-def oo_inheritance(x, y):
- obj = MyDerivedClass(x, y)
- return obj.compute_and_multiply(2)
-
-def oo_liskov(x, y):
- base = MyClass(x, y)
- derived = MyDerivedClass(x, y)
- return call_method(base) + call_method(derived)
-
-def oo_static_method(x, y):
- base = MyClass(x, y)
- derived = MyDerivedClass(x, y)
- return base.static_meth(x,y) + derived.static_meth(x, y)\
- + MyClass.static_meth(x, y) + MyDerivedClass.static_meth(x, y)
-
-def oo_class_attribute(x, y):
- base = MyClass(x, y)
- derived = MyDerivedClass(x, y)
- return base.class_attribute() + derived.class_attribute()
-
-def oo_runtimenew(x, y):
- return init_and_compute(MyClass, x, y) + init_and_compute(MyDerivedClass, x, y)
-
-def nonnull_helper(lst):
- if lst is None:
- return 1
- else:
- return 2
-def oo_nonnull(x, y):
- return nonnull_helper([]) + nonnull_helper(None)
+ def test_compute(self):
+ def fn(x, y):
+ obj = MyClass(x, y)
+ return obj.compute()
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_compute_multiply(self):
+ def fn(x, y):
+ obj = MyClass(x, y)
+ return obj.compute_and_multiply(2)
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_inheritance(self):
+ def fn(x, y):
+ obj = MyDerivedClass(x, y)
+ return obj.compute_and_multiply(2)
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_liskov(self):
+ def fn(x, y):
+ base = MyClass(x, y)
+ derived = MyDerivedClass(x, y)
+ return call_method(base) + call_method(derived)
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_static_method(self):
+ def fn(x, y):
+ base = MyClass(x, y)
+ derived = MyDerivedClass(x, y)
+ return base.static_meth(x,y) + derived.static_meth(x, y)\
+ + MyClass.static_meth(x, y) + MyDerivedClass.static_meth(x, y)
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_class_attribute(self):
+ def fn(x, y):
+ base = MyClass(x, y)
+ derived = MyDerivedClass(x, y)
+ return base.class_attribute() + derived.class_attribute()
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_runtimenew(self):
+ def fn(x, y):
+ return init_and_compute(MyClass, x, y) + init_and_compute(MyDerivedClass, x, y)
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
+
+ def test_nonnull(self):
+ def fn(x, y):
+ return nonnull_helper([]) + nonnull_helper(None)
+ assert self.interpret(fn, [42, 13]) == fn(42, 13)
-if __name__ == '__main__':
- from pypy.translator.cli import conftest
- conftest.option.wd = True
- check(oo_liskov, [int, int], (42, 13))
More information about the Pypy-commit
mailing list