Example #1
0
    def test_it_patches_using_with_plus_arg(self):
        # nothing actually goes to console
        with patch("os.getcwd") as getcwd:
            import os

            getcwd.expects().and_returns("foo")
            expect(os.getcwd()) == "foo"
            self.assertEqual(os.getcwd(), "foo")
Example #2
0
 def test_it_patches_stdout_using_with(self):
     # nothing actually goes to console
     old = sys.stdout
     buf = sys.stdout = StringIO()
     try:
         with patch("sys.stdout"):
             print "hello world"
     finally:
         sys.stdout = old
     self.assertEquals(buf.getvalue(), "")
Example #3
0
    def test_it_patches_using_alternative_value(self):
        with patch("os.getcwd", lambda: "lol"):
            import os

            expect(os.getcwd()) == "lol"
            self.assertEqual(os.getcwd(), "lol")