Merge "Monkey-patch in tests using mock.patch"
This commit is contained in:
@@ -1382,16 +1382,11 @@ class TestServer(unittest.TestCase):
|
|||||||
def sleep(self, *args, **kwargs):
|
def sleep(self, *args, **kwargs):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
with temptree([]) as t:
|
with temptree([]) as t, open(os.path.join(t, 'output'), 'w+') as f, \
|
||||||
old_stdout = sys.stdout
|
mock.patch.object(sys, 'stdout', f), \
|
||||||
old_wait = manager.WARNING_WAIT
|
mock.patch.object(manager, 'WARNING_WAIT', 0.01), \
|
||||||
old_time = manager.time
|
mock.patch.object(manager, 'time', MockTime()):
|
||||||
try:
|
# Note that we actually capture the read stdout (for prints)
|
||||||
manager.WARNING_WAIT = 0.01
|
|
||||||
manager.time = MockTime()
|
|
||||||
with open(os.path.join(t, 'output'), 'w+') as f:
|
|
||||||
# actually capture the read stdout (for prints)
|
|
||||||
sys.stdout = f
|
|
||||||
# test closing pipe in subprocess unblocks read
|
# test closing pipe in subprocess unblocks read
|
||||||
with MockProcess() as proc:
|
with MockProcess() as proc:
|
||||||
server.procs = [proc]
|
server.procs = [proc]
|
||||||
@@ -1427,10 +1422,6 @@ class TestServer(unittest.TestCase):
|
|||||||
self.assertTrue(proc.is_alive())
|
self.assertTrue(proc.is_alive())
|
||||||
for proc in procs:
|
for proc in procs:
|
||||||
proc.join()
|
proc.join()
|
||||||
finally:
|
|
||||||
sys.stdout = old_stdout
|
|
||||||
manager.WARNING_WAIT = old_wait
|
|
||||||
manager.time = old_time
|
|
||||||
|
|
||||||
def test_interact(self):
|
def test_interact(self):
|
||||||
class MockProcess(object):
|
class MockProcess(object):
|
||||||
|
|||||||
Reference in New Issue
Block a user