def setUp(self): """ Set up the tests, giving ourselves a detector object to play with and setting up its testable knobs to refer to our mocked versions. """ self.detector = process._FDDetector() self.detector.listdir = self.listdir self.detector.getpid = self.getpid self.detector.openfile = self.openfile
def setUp(self): """ Set up the tests, giving ourselves a detector object to play with and setting up its testable knobs to refer to our mocked versions. """ self.detector = process._FDDetector() self.detector.listdir = self.listdir self.detector.getpid = self.getpid self.detector.openfile = self.openfile self._files = [0, 1, 2] self.addCleanup( self.replaceResourceModule, sys.modules.get('resource'))
def test_identityOfListOpenFDsChanges(self): """ Check that the identity of _listOpenFDs changes after running _listOpenFDs the first time, but not after the second time it's run. In other words, check that the monkey patching actually works. """ # Create a new instance detector = process._FDDetector() first = detector._listOpenFDs.func_name detector._listOpenFDs() second = detector._listOpenFDs.func_name detector._listOpenFDs() third = detector._listOpenFDs.func_name self.assertNotEqual(first, second) self.assertEqual(second, third)