Created
June 27, 2009 04:05
-
-
Save rtyler/136890 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/Tests/CheetahWrapper.py b/src/Tests/CheetahWrapper.py | |
| index 11b903f..e44bc86 100644 | |
| --- a/src/Tests/CheetahWrapper.py | |
| +++ b/src/Tests/CheetahWrapper.py | |
| @@ -11,10 +11,14 @@ Besides unittest usage, recognizes the following command-line options: | |
| --output | |
| Show the output of each subcommand. (Normally suppressed.) | |
| ''' | |
| -import os, shutil, sys, tempfile | |
| -import unittest_local_copy as unittest | |
| - | |
| +import os | |
| +import popen2 | |
| import re # Used by listTests. | |
| +import shutil | |
| +import sys | |
| +import tempfile | |
| +import unittest | |
| + | |
| from optparse import OptionParser | |
| from Cheetah.CheetahWrapper import CheetahWrapper # Used by NoBackup. | |
| @@ -137,6 +141,37 @@ Found %(result)r""" | |
| msg = "backup file exists in spite of --nobackup: %s" % path | |
| self.failIf(exists, msg) | |
| + | |
| + def assertWin32Subprocess(self, cmd): | |
| + _in, _out = os.popen4(cmd) | |
| + _in.close() | |
| + output = _out.read() | |
| + rc = _out.close() | |
| + if rc is None: | |
| + rc = 0 | |
| + return rc, output | |
| + | |
| + def assertPosixSubprocess(self, cmd): | |
| + process = popen2.Popen4(cmd) | |
| + status = process.wait() | |
| + output = process.fromchild.read() | |
| + process.fromchild.close() | |
| + return status, output | |
| + | |
| + def assertSubprocess(self, cmd, nonzero=False): | |
| + status, output = None, None | |
| + if sys.platform == 'win32': | |
| + status, output = self.assertWin32Subprocess(cmd) | |
| + else: | |
| + status, output = self.assertPosixSubprocess(cmd) | |
| + | |
| + if not nonzero: | |
| + self.failUnlessEqual(status, 0, '''Subprocess exited with a non-zero status (%d) | |
| + %s''' % (status, output)) | |
| + else: | |
| + self.failIfEqual(status, 0, '''Subprocess exited with a zero status (%d) | |
| + %s''' % (status, output)) | |
| + return output | |
| def go(self, cmd, expectedStatus=0, expectedOutputSubstring=None): | |
| """Run a "cheetah compile" or "cheetah fill" subcommand. | |
| @@ -149,23 +184,7 @@ Found %(result)r""" | |
| test. | |
| out: None. | |
| """ | |
| - proc_stdin, proc_stdout = os.popen4(cmd) | |
| - proc_stdin.close() | |
| - output = proc_stdout.read() | |
| - status = proc_stdout.close() | |
| - if status == None: | |
| - status = 0 | |
| - if OUTPUT: | |
| - if output.endswith("\n"): | |
| - output = output[:-1] | |
| - print "SUBCOMMAND:", cmd | |
| - print output | |
| - msg = "subcommand exit status %d: %s" % (status, cmd) | |
| - if status!=expectedStatus: | |
| - print output | |
| - self.failUnlessEqual(status, expectedStatus, msg) | |
| + output = self.assertSubprocess(cmd) | |
| if expectedOutputSubstring is not None: | |
| msg = "substring %r not found in subcommand output: %s" % \ | |
| (expectedOutputSubstring, cmd) | |
| @@ -173,29 +192,6 @@ Found %(result)r""" | |
| self.failUnless(substringTest, msg) | |
| - def goExpectError(self, cmd): | |
| - """Run a subcommand and expect it to fail. | |
| - | |
| - in : cmd, string, the command to run. | |
| - out: None. | |
| - """ | |
| - proc_stdin, proc_stdout = os.popen4(cmd) | |
| - proc_stdin.close() | |
| - output = proc_stdout.read() | |
| - status = proc_stdout.close() | |
| - if status == None: | |
| - status = 0 | |
| - msg = "subcommand exit status %s: %s" % (status, cmd) | |
| - self.failIfEqual(status, 0, msg) # Status must *not* be 0. | |
| - if OUTPUT: | |
| - if output.endswith("\n"): | |
| - output = output[:-1] | |
| - print "SUBCOMMAND:", cmd | |
| - print output | |
| - | |
| - | |
| class CFIdirBase(CFBase): | |
| """Subclass for tests with --idir. | |
| """ | |
| @@ -420,13 +416,13 @@ class FlatRecurseCollision(CFBase): | |
| expectError = True | |
| def testCompile(self): | |
| - self.goExpectError("cheetah compile -R --flat") | |
| + self.assertSubprocess("cheetah compile -R --flat", nonzero=True) | |
| def testFill(self): | |
| - self.goExpectError("cheetah fill -R --flat") | |
| + self.assertSubprocess("cheetah fill -R --flat", nonzero=True) | |
| def testText(self): | |
| - self.goExpectError("cheetah fill -R --flat") | |
| + self.assertSubprocess("cheetah fill -R --flat", nonzero=True) | |
| class IdirRecurse(CFIdirBase): | |
| @@ -471,13 +467,13 @@ class IdirFlatRecurseCollision(CFIdirBase): | |
| expectError = True | |
| def testCompile(self): | |
| - self.goExpectError("cheetah compile -R --flat --idir SRC") | |
| + self.assertSubprocess("cheetah compile -R --flat --idir SRC", nonzero=True) | |
| def testFill(self): | |
| - self.goExpectError("cheetah fill -R --flat --idir SRC") | |
| + self.assertSubprocess("cheetah fill -R --flat --idir SRC", nonzero=True) | |
| def testText(self): | |
| - self.goExpectError("cheetah fill -R --flat --idir SRC --oext txt") | |
| + self.assertSubprocess("cheetah fill -R --flat --idir SRC --oext txt", nonzero=True) | |
| class NoBackup(CFBase): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment