# HG changeset patch
# User Mihai Ibanescu <https://issues.rpath.com/>
# Date 1250801424 14400
# Node ID b6cc51a3529eaec8198ae6abf49076be10e3626e
# Parent  f618ab696c0d9811cc230659ad77bcb70e168320
Attempt to fix the testsuite

diff -r f618ab696c0d -r b6cc51a3529e tests/test.py
--- a/tests/test.py	Thu Aug 20 16:23:04 2009 -0400
+++ b/tests/test.py	Thu Aug 20 16:50:24 2009 -0400
@@ -1,26 +1,36 @@
 #!/usr/bin/env python
 
-import sys, popen2
+import os
+import sys
+import subprocess
 import getopt
 import unittest
 
 
 class GenTest(unittest.TestCase):
+    def execute(self, cmd, cwd = None):
+        p = subprocess.Popen(cmd, cwd = cwd,
+            stdout = subprocess.PIPE, stderr = subprocess.PIPE,
+            shell = True)
+        stdout, stderr = p.communicate()
+        return stdout, stderr
 
-    def test_1_generate(self):
-        cmd = 'python ../generateDS.py -f -o out2sup.py -s out2sub.py --super=out2sup -u gends_user_methods people.xsd'
-        outfile, infile = popen2.popen2(cmd)
-        result = outfile.read()
-        outfile.close()
-        infile.close()
-        self.failUnless(len(result) == 0)
+    def setUp(self):
+        cmd = 'python generateDS.py -f -o tests/out2sup.py -s tests/out2sub.py --super=out2sup -u gends_user_methods tests/people.xsd'
+        stdout, stderr = self.execute(cmd, cwd = '..')
+        self.failUnlessEqual(len(stdout), 0)
+        self.failUnlessEqual(len(stderr), 0)
+
+    def tearDown(self):
+        for f in [ "out2sub.py", "out2sup.py" ]:
+            try:
+                os.unlink(f)
+            except OSError:
+                pass
 
     def test_2_compare_superclasses(self):
         cmd = 'diff out1sup.py out2sup.py'
-        outfile, infile = popen2.popen2(cmd)
-        result = outfile.read()
-        outfile.close()
-        infile.close()
+        result, _ = self.execute(cmd)
         #print 'len(result):', len(result)
         # Ignore the differing lines containing the date/time.
         #self.failUnless(len(result) < 130 and result.find('Generated') > -1)
@@ -28,10 +38,7 @@
 
     def test_3_compare_subclasses(self):
         cmd = 'diff out1sub.py out2sub.py'
-        outfile, infile = popen2.popen2(cmd)
-        result = outfile.read()
-        outfile.close()
-        infile.close()
+        result, _ = self.execute(cmd)
         # Ignore the differing lines containing the date/time.
         #self.failUnless(len(result) < 130 and result.find('Generated') > -1)
         self.failUnless(check_result(result))
