def test_register_callbacks(self): mock_listener = Mock(spec_set=InputEventListener) self.cls.listener = mock_listener with patch('%s.logger' % pbm) as mock_logger: self.cls.register_callbacks() assert mock_logger.mock_calls == [ call.debug("registering callbacks"), call.debug('registering callback for %s ON', 0), call.debug('registering callback for %s OFF', 0), call.debug('registering callback for %s ON', 1), call.debug('registering callback for %s OFF', 1), call.debug('registering callback for %s ON', 2), call.debug('registering callback for %s OFF', 2), call.debug('registering callback for %s ON', 3), call.debug('registering callback for %s OFF', 3), call.debug('done registering callbacks'), call.info('Initial pin states: %s', [10, 11, 12, 13]) ] assert mock_listener.mock_calls == [ call.register(0, IODIR_ON, self.cls.handle_input_on), call.register(0, IODIR_OFF, self.cls.handle_input_off), call.register(1, IODIR_ON, self.cls.handle_input_on), call.register(1, IODIR_OFF, self.cls.handle_input_off), call.register(2, IODIR_ON, self.cls.handle_input_on), call.register(2, IODIR_OFF, self.cls.handle_input_off), call.register(3, IODIR_ON, self.cls.handle_input_on), call.register(3, IODIR_OFF, self.cls.handle_input_off), ] assert self.cls.current_values == [10, 11, 12, 13]
def test_atexit(self): m = Mock() with Replacer() as r: r.replace('atexit.register', m.register) c = TestComponents() expected = [call.register(c.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: c.atexit() self.assertTrue(len(w), 1) compare(str(w[0].message), ( # pragma: no branch "TestComponents instances not uninstalled by shutdown!" )) c.uninstall() compare(expected, m.mock_calls) # check re-running has no ill effects c.atexit() compare(expected, m.mock_calls)
def test_atexit(self): # http://bugs.python.org/issue25532 from mock import call m = Mock() with Replacer() as r: # make sure the marker is false, other tests will # probably have set it r.replace('testfixtures.TempDirectory.atexit_setup', False) r.replace('atexit.register', m.register) d = TempDirectory() expected = [call.register(d.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: d.atexit() self.assertTrue(len(w), 1) compare( str(w[0].message), ( # pragma: no branch "TempDirectory instances not cleaned up by shutdown:\n" + d.path)) d.cleanup() compare(set(), TempDirectory.instances) # check re-running has no ill effects d.atexit()
def test_atexit(self): m = Mock() with Replacer() as r: # make sure the marker is false, other tests will # probably have set it r.replace('testfixtures.TempDirectory.atexit_setup', False) r.replace('atexit.register', m.register) d = TempDirectory() expected = [call.register(d.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: d.atexit() self.assertTrue(len(w), 1) compare(str(w[0].message), ( # pragma: no branch "TempDirectory instances not cleaned up by shutdown:\n" + d.path )) d.cleanup() compare(set(), TempDirectory.instances) # check re-running has no ill effects d.atexit()
def test_atexit(self): m = Mock() with Replacer() as r: # make sure the marker is false, other tests will # probably have set it r.replace('testfixtures.LogCapture.atexit_setup', False) r.replace('atexit.register', m.register) l = LogCapture() expected = [call.register(l.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: l.atexit() self.assertTrue(len(w), 1) compare(str(w[0].message), ( # pragma: no branch "LogCapture instances not uninstalled by shutdown, " "loggers captured:\n" "(None,)" )) l.uninstall() compare(set(), LogCapture.instances) # check re-running has no ill effects l.atexit()
def test_atexit(self): # http://bugs.python.org/issue25532 from mock import call m = Mock() with Replacer() as r: # make sure the marker is false, other tests will # probably have set it r.replace('testfixtures.LogCapture.atexit_setup', False) r.replace('atexit.register', m.register) l = LogCapture() expected = [call.register(l.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: l.atexit() self.assertTrue(len(w), 1) compare(str(w[0].message), ( # pragma: no branch "LogCapture instances not uninstalled by shutdown, " "loggers captured:\n" "(None,)" )) l.uninstall() compare(set(), LogCapture.instances) # check re-running has no ill effects l.atexit()
def test_start_up_registers_atexit_lock_cleanup(self): filelock_mock = MagicMock() self.patch(start_up, 'FileLock', Mock(side_effect=filelock_mock)) # Patch atexit.register to assert it's called with the right # argument. atexit_mock = self.patch(start_up, 'atexit') start_up.start_up() self.assertEqual( [call.register(filelock_mock(start_up.LOCK_FILE_NAME).break_lock)], atexit_mock.mock_calls)
def test_start_up_registers_atexit_lock_cleanup(self): filelock_mock = MagicMock() self.patch(start_up, 'FileLock', Mock(side_effect=filelock_mock)) # Patch atexit.register to assert it's called with the right # argument. atexit_mock = self.patch(start_up, 'atexit') start_up.start_up() self.assertEqual( [call.register( filelock_mock(start_up.LOCK_FILE_NAME).break_lock)], atexit_mock.mock_calls)
def test_atexit(self): from mock import call m = Mock() with Replacer() as r: r.replace('testfixtures.TempDirectory.atexit_setup', False) r.replace('atexit.register', m.register) d = TempDirectory() expected = [call.register(d.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: d.atexit() self.assertTrue(len(w), 1) compare(str(w[0].message), 'TempDirectory instances not cleaned up by shutdown:\n' + d.path) d.cleanup() compare(set(), TempDirectory.instances) d.atexit()
def test_atexit(self): from mock import call m = Mock() with Replacer() as r: r.replace('testfixtures.LogCapture.atexit_setup', False) r.replace('atexit.register', m.register) l = LogCapture() expected = [call.register(l.atexit)] compare(expected, m.mock_calls) with catch_warnings(record=True) as w: l.atexit() self.assertTrue(len(w), 1) compare( str(w[0].message), 'LogCapture instances not uninstalled by shutdown, loggers captured:\n(None,)' ) l.uninstall() compare(set(), LogCapture.instances) l.atexit()