Mercurial > sqlpython
changeset 167:d73915d6d852
where is my stdout going?
author | catherine@Elli.myhome.westell.com |
---|---|
date | Wed, 22 Oct 2008 17:47:52 -0400 |
parents | 7e7fd8e12015 |
children | 35ed0e0c63d9 |
files | sqlpython/test_sqlpyPlus.py |
diffstat | 1 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/test_sqlpyPlus.py Wed Oct 22 17:17:50 2008 -0400 +++ b/sqlpython/test_sqlpyPlus.py Wed Oct 22 17:47:52 2008 -0400 @@ -2,21 +2,29 @@ from sqlpyPlus import * class TestSqlPyPlus(unittest.TestCase): def setUp(self): - self.oldStdOut = sys.stdout self.testsession = sqlpyPlus() self.testsession.onecmd('connect testdata/testdata@orcl') def assertOutput(self, commandtext, expected): - self.testsession.onecmd(commandtext + ' > temp_test_output.txt') - resultfile = open('temp_test_output.txt') - result = resultfile.read() - resultfile.close() + oldStdOut = sys.stdout + oldStdErr = sys.stderr + tempoutput = tempfile.TemporaryFile() + temperr = tempfile.TemporaryFile() + sys.stdout = tempoutput + sys.stderr = temperr + self.testsession.onecmd(commandtext) + tempoutput.seek(0) + result = tempoutput.read() + temperr.read() self.assertEqual(expected, result) + sys.stdout = oldStdOut + sys.stderr = oldStdErr def testselect(self): self.assertOutput('select * from species;', ''' blah ''') self.assertOutput def tearDown(self): - sys.stdout = self.oldStdOut + pass -unittest.main() \ No newline at end of file +trueStdOut = sys.stdout +unittest.main() +sys.stdout = trueStdOut \ No newline at end of file