Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #17 from frecon/mock-stdout

Mock stdout and change function name input
  • Loading branch information...
commit 8d16ba758c10ea6512f7d991a0bba0f4ebe094e0 2 parents 462aa77 + 59c10c8
@Gianfrancoalongi authored
Showing with 15 additions and 18 deletions.
  1. +1 −2  skeletons/python/std.py
  2. +14 −16 skeletons/python/tests.py
View
3  skeletons/python/std.py
@@ -1,3 +1,2 @@
-
-def input(str):
+def murenzhuang(str):
print str
View
30 skeletons/python/tests.py
@@ -1,24 +1,22 @@
import unittest
-import sys
-import os
+from cStringIO import StringIO
+
+import mock
+
import std
-class MyTest(unittest.TestCase):
-
- def test_root_program(self):
- sys.stdout = open('std_out_result', 'w')
- std.input("hello world")
- sys.stdout.close()
- self.assertEqual( in_stdout(), "hello world\n")
-
+
+class TestMurenzhuang(unittest.TestCase):
+ def setUp(self):
+ self.stdout = mock.patch('sys.stdout', new_callable=StringIO).start()
+
def tearDown(self):
- os.remove('std_out_result')
+ mock.patch.stopall()
-def in_stdout():
- return open('std_out_result', 'r').read()
+ def test_echoes_stdin(self):
+ std.murenzhuang('hello world')
+ self.assertEqual('hello world\n', self.stdout.getvalue())
-def main():
- unittest.main()
if __name__ == '__main__':
- main()
+ unittest.main()
Please sign in to comment.
Something went wrong with that request. Please try again.