diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index 84a2a0a..a5fe957 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -8,6 +8,7 @@ import shutil import unittest import subprocess import tempfile +import contextlib is_py3k = bool(sys.version_info[0] == 3) BITS = tuple.__itemsize__ * 8 @@ -29,9 +30,40 @@ import llvm.ee as le tests = [] + # --------------------------------------------------------------------------- -class TestAsm(unittest.TestCase): +if sys.version_info[:2] <= (2, 6): + # create custom TestCase + class TestCase(unittest.TestCase): + def assertIn(self, item, container): + self.assertTrue(item in container) + + def assertNotIn(self, item, container): + self.assertFalse(item in container) + + def assertLess(self, a, b): + self.assertTrue(a < b) + + def assertIs(self, a, b): + self.assertTrue(a is b) + + @contextlib.contextmanager + def assertRaises(self, exc): + try: + yield + except exc: + pass + else: + raise self.failureException("Did not raise %s" % exc) + +else: + TestCase = unittest.TestCase + + +# --------------------------------------------------------------------------- + +class TestAsm(TestCase): def setUp(self): self.tmpdir = tempfile.mkdtemp() @@ -82,7 +114,7 @@ tests.append(TestAsm) # --------------------------------------------------------------------------- -class TestAttr(unittest.TestCase): +class TestAttr(TestCase): def make_module(self): test_module = """ define i32 @sum(i32, i32) { @@ -104,7 +136,7 @@ tests.append(TestAttr) # --------------------------------------------------------------------------- -class TestAtomic(unittest.TestCase): +class TestAtomic(TestCase): orderings = ['unordered', 'monotonic', 'acquire', 'release', 'acq_rel', 'seq_cst'] @@ -187,7 +219,7 @@ tests.append(TestAtomic) # --------------------------------------------------------------------------- -class TestConstExpr(unittest.TestCase): +class TestConstExpr(TestCase): def test_constexpr_opcode(self): mod = Module.new('test_constexpr_opcode') @@ -203,7 +235,7 @@ tests.append(TestConstExpr) # --------------------------------------------------------------------------- -class TestOperands(unittest.TestCase): +class TestOperands(TestCase): # implement a test function test_module = """ define i32 @prod(i32, i32) { @@ -259,7 +291,7 @@ tests.append(TestOperands) # --------------------------------------------------------------------------- -class TestPasses(unittest.TestCase): +class TestPasses(TestCase): # Create a module. asm = """ @@ -385,7 +417,7 @@ tests.append(TestPasses) # --------------------------------------------------------------------------- -class TestEngineBuilder(unittest.TestCase): +class TestEngineBuilder(TestCase): def make_test_module(self): module = Module.new("testmodule") @@ -452,7 +484,7 @@ tests.append(TestEngineBuilder) # --------------------------------------------------------------------------- -class TestExecutionEngine(unittest.TestCase): +class TestExecutionEngine(TestCase): def test_get_pointer_to_global(self): module = lc.Module.new(str(self)) gvar = module.add_global_variable(Type.int(), 'hello') @@ -492,7 +524,7 @@ class TestExecutionEngine(unittest.TestCase): tests.append(TestExecutionEngine) # --------------------------------------------------------------------------- -class TestObjCache(unittest.TestCase): +class TestObjCache(TestCase): def test_objcache(self): # Testing module aliasing @@ -593,7 +625,7 @@ tests.append(TestObjCache) # --------------------------------------------------------------------------- -class TestTargetMachines(unittest.TestCase): +class TestTargetMachines(TestCase): '''Exercise target machines Require PTX backend @@ -646,7 +678,7 @@ tests.append(TestTargetMachines) # --------------------------------------------------------------------------- -class TestNative(unittest.TestCase): +class TestNative(TestCase): def setUp(self): self.tmpdir = tempfile.mkdtemp() @@ -708,7 +740,7 @@ if sys.platform != 'win32': # --------------------------------------------------------------------------- -class TestNativeAsm(unittest.TestCase): +class TestNativeAsm(TestCase): def test_asm(self): m = Module.new('module1') @@ -731,7 +763,7 @@ tests.append(TestNativeAsm) # --------------------------------------------------------------------------- -class TestUses(unittest.TestCase): +class TestUses(TestCase): def test_uses(self): m = Module.new('a') @@ -768,7 +800,7 @@ tests.append(TestUses) # --------------------------------------------------------------------------- -class TestMetaData(unittest.TestCase): +class TestMetaData(TestCase): # test module metadata def test_metadata(self): m = Module.new('a') @@ -788,7 +820,7 @@ tests.append(TestMetaData) # --------------------------------------------------------------------------- -class TestInlining(unittest.TestCase): +class TestInlining(TestCase): def test_inline_call(self): mod = Module.new(__name__) callee = mod.add_function(Type.function(Type.int(), [Type.int()]), @@ -817,7 +849,7 @@ tests.append(TestInlining) # --------------------------------------------------------------------------- -class TestIssue10(unittest.TestCase): +class TestIssue10(TestCase): def test_issue10(self): m = Module.new('a') ti = Type.int() @@ -838,7 +870,7 @@ tests.append(TestIssue10) # --------------------------------------------------------------------------- -class TestOpaque(unittest.TestCase): +class TestOpaque(TestCase): def test_opaque(self): # Create an opaque type @@ -869,7 +901,7 @@ class TestOpaque(unittest.TestCase): tests.append(TestOpaque) # --------------------------------------------------------------------------- -class TestCPUSupport(unittest.TestCase): +class TestCPUSupport(TestCase): def _build_test_module(self): mod = Module.new('test') @@ -945,7 +977,7 @@ class TestCPUSupport(unittest.TestCase): tests.append(TestCPUSupport) # --------------------------------------------------------------------------- -class TestIntrinsicBasic(unittest.TestCase): +class TestIntrinsicBasic(TestCase): def _build_module(self, float): mod = Module.new('test') @@ -1032,7 +1064,7 @@ tests.append(TestIntrinsicBasic) # --------------------------------------------------------------------------- -class TestIntrinsic(unittest.TestCase): +class TestIntrinsic(TestCase): def test_bswap(self): # setup a function and a builder mod = Module.new('test') @@ -1130,7 +1162,7 @@ tests.append(TestIntrinsic) # --------------------------------------------------------------------------- -class TestVolatile(unittest.TestCase): +class TestVolatile(TestCase): def test_volatile(self): mod = Module.new('mod') @@ -1184,7 +1216,7 @@ tests.append(TestVolatile) # --------------------------------------------------------------------------- -class TestNamedMetaData(unittest.TestCase): +class TestNamedMetaData(TestCase): def test_named_md(self): m = Module.new('test_named_md') nmd = m.get_or_insert_named_metadata('something') diff --git a/test/inlineasm.py b/test/inlineasm.py index 635e6bf..df91d71 100644 --- a/test/inlineasm.py +++ b/test/inlineasm.py @@ -3,12 +3,13 @@ # Import the llvm-py modules. from llvm import * from llvm.core import * +from llvm.test_llvmpy import TestCase import logging import unittest -class TestInlineAsm(unittest.TestCase): +class TestInlineAsm(TestCase): def test_inline_asm(self): mod = Module.new(__name__) fnty = Type.function(Type.int(), [Type.int()]) diff --git a/test/loopvectorize.py b/test/loopvectorize.py index ff7cb10..9cf1654 100644 --- a/test/loopvectorize.py +++ b/test/loopvectorize.py @@ -2,13 +2,14 @@ from llvm.core import * from llvm.passes import * from llvm.ee import * import llvm +from llvm.test_llvmpy import TestCase from os.path import dirname, join as join_path import unittest import re -class TestLoopVectorizer(unittest.TestCase): +class TestLoopVectorizer(TestCase): def test_loop_vectorizer(self): if llvm.version <= (3, 1): return # SKIP diff --git a/test/metadata.py b/test/metadata.py index 90b6ae8..3228159 100644 --- a/test/metadata.py +++ b/test/metadata.py @@ -1,10 +1,10 @@ from __future__ import print_function import unittest - +from llvm.test_llvmpy import TestCase from llvm.core import * -class TestMetaData(unittest.TestCase): +class TestMetaData(TestCase): def test_metadata_get(self): module = Module.new('test_metadata') md = MetaData.get(module, [Constant.int(Type.int(), 1234)]) diff --git a/test/tbaa.py b/test/tbaa.py index d775a53..242ed19 100644 --- a/test/tbaa.py +++ b/test/tbaa.py @@ -1,8 +1,9 @@ from llvm.core import * from llvm.tbaa import * +from llvm.test_llvmpy import TestCase import unittest -class TestTBAABuilder(unittest.TestCase): +class TestTBAABuilder(TestCase): def test_tbaa_builder(self): mod = Module.new('test_tbaa_builder') fty = Type.function(Type.void(), [Type.pointer(Type.float())]) diff --git a/test/test.py b/test/test.py index bbc43f4..3b46281 100644 --- a/test/test.py +++ b/test/test.py @@ -7,9 +7,9 @@ import unittest, sys, logging from llvm import * from llvm.core import * +from llvm.test_llvmpy import TestCase - -class TestModule(unittest.TestCase): +class TestModule(TestCase): def setUp(self): pass @@ -100,8 +100,10 @@ def main(): gc.set_debug(gc.DEBUG_LEAK) # run tests - unittest.main(exit=False) # set exit to False so that it will return. - + if sys.version_info[:2] > (2, 6): + unittest.main(exit=False) # set exit to False so that it will return. + else: + unittest.main() # done for it in gc.garbage: logging.debug('garbage = %s', it) diff --git a/test/test_debuginfo.py b/test/test_debuginfo.py index 8ecaa3a..0340c1b 100644 --- a/test/test_debuginfo.py +++ b/test/test_debuginfo.py @@ -4,8 +4,9 @@ import unittest import llvm.ee from llvm.core import * from llvm import _dwarf, debuginfo +from llvm.test_llvmpy import TestCase -class TestDebugInfo(unittest.TestCase): +class TestDebugInfo(TestCase): def test_dwarf_constants(self): dwarf_constants = vars(_dwarf)