From 5df7c4d1593340b50f0532700872fe7af11c0115 Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Thu, 13 Sep 2012 10:57:48 -0500 Subject: [PATCH] improve test to not use hardcoded test directory --- llvm/test_llvmpy.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index 1af1ea6..480aec4 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -4,8 +4,10 @@ LLVM tests import os import sys import math +import shutil import unittest import subprocess +import tempfile is_py3k = bool(sys.version_info[0] == 3) @@ -28,6 +30,12 @@ tests = [] # --------------------------------------------------------------------------- class TestAsm(unittest.TestCase): + def setUp(self): + self.tmpdir = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self.tmpdir) + def test_asm(self): # create a module m = Module.new('module1') @@ -36,18 +44,18 @@ class TestAsm(unittest.TestCase): # write it's assembly representation to a file asm = str(m) - with open("/tmp/testasm.ll", "w") as fout: + testasm_ll = os.path.join(self.tmpdir, 'testasm.ll') + with open(testasm_ll, "w") as fout: fout.write(asm) # read it back into a module - with open("/tmp/testasm.ll") as fin: + with open(testasm_ll) as fin: m2 = Module.from_assembly(fin) # The default `m.id` is ''. m2.id = m.id # Copy the name from `m` self.assertEqual(str(m2).strip(), asm.strip()) - def test_bitcode(self): # create a module m = Module.new('module1') @@ -56,11 +64,12 @@ class TestAsm(unittest.TestCase): # write it's assembly representation to a file asm = str(m) - with open("/tmp/testasm.bc", "wb") as fout: + testasm_bc = os.path.join(self.tmpdir, 'testasm.bc') + with open(testasm_bc, "wb") as fout: m.to_bitcode(fout) # read it back into a module - with open("/tmp/testasm.bc", "rb") as fin: + with open(testasm_bc, "rb") as fin: m2 = Module.from_bitcode(fin) # The default `m.id` is ''. m2.id = m.id # Copy the name from `m`