Last active
December 29, 2015 17:19
-
-
Save allardhoeve/7702807 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
class TestNamedTemporaryFile(TestCase): | |
def setUp(self): | |
# set up the mock | |
# you could use ByteTestCase when you are at byte.nl ;) | |
mockobj = mock.Mock() | |
patcher = mock.patch("tempfile.NamedTemporaryFile", mockobj) | |
self.addCleanup(patcher.stop) | |
patcher.start() | |
def enter(*args): | |
return self.mock_tempfile | |
def exit(*args): | |
pass | |
# set exit and enter on mocked instance | |
self.mock_tempfile = mockobj.return_value | |
self.mock_tempfile.__exit__ = exit | |
self.mock_tempfile.__enter__ = enter | |
self.mock_tempfile.name = "/tmp/mytempfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment