def test_stop(self): x = Autoreloader(Mock(), modules=[__name__]) x._monitor = None x.stop() x._monitor = Mock() x.stop() x._monitor.stop.assert_called_with()
def test_on_event_loop_close(self): x = Autoreloader(Mock(), modules=[__name__]) hub = Mock() x._monitor = Mock() x.on_event_loop_close(hub) x._monitor.on_event_loop_close.assert_called_with(hub) x._monitor = None x.on_event_loop_close(hub)
def test_start(self, fhash): x = Autoreloader(Mock(), modules=[__name__]) x.Monitor = Mock() mon = x.Monitor.return_value = Mock() mon.start.side_effect = OSError() mon.start.side_effect.errno = errno.EINTR x.body() mon.start.side_effect.errno = errno.ENOENT with self.assertRaises(OSError): x.body() mon.start.side_effect = None x.body()
def test_on_change(self): x = Autoreloader(Mock(), modules=[__name__]) mm = x._maybe_modified = Mock(0) mm.return_value = True x._reload = Mock() x.file_to_module[__name__] = __name__ x.on_change([__name__]) self.assertTrue(x._reload.called) mm.return_value = False x.on_change([__name__])
def test_maybe_modified(self, exists, fhash): exists.return_value = True fhash.return_value = 'abcd' x = Autoreloader(Mock(), modules=[__name__]) x._hashes = {} x._hashes[__name__] = 'dcba' self.assertTrue(x._maybe_modified(__name__)) x._hashes[__name__] = 'abcd' self.assertFalse(x._maybe_modified(__name__)) exists.return_value = False self.assertFalse(x._maybe_modified(__name__))
def test_maybe_modified(self, fhash): fhash.return_value = "abcd" x = Autoreloader(Mock(), modules=[__name__]) x._hashes = {} x._hashes[__name__] = "dcba" self.assertTrue(x._maybe_modified(__name__)) x._hashes[__name__] = "abcd" self.assertFalse(x._maybe_modified(__name__))
def test_on_poll_init(self): x = Autoreloader(Mock(), modules=[__name__]) hub = Mock() x._monitor = None x.on_init = Mock() def se(*args, **kwargs): x._monitor = Mock() x.on_init.side_effect = se x.on_poll_init(hub) x.on_init.assert_called_with() x._monitor.on_poll_init.assert_called_with(hub) x._monitor.on_poll_init.reset_mock() x.on_poll_init(hub) x._monitor.on_poll_init.assert_called_with(hub)
def test_register_with_event_loop(self): x = Autoreloader(Mock(), modules=[__name__]) hub = Mock() x._monitor = None x.on_init = Mock() def se(*args, **kwargs): x._monitor = Mock() x.on_init.side_effect = se x.register_with_event_loop(hub) x.on_init.assert_called_with() x._monitor.register_with_event_loop.assert_called_with(hub) x._monitor.register_with_event_loop.reset_mock() x.register_with_event_loop(hub) x._monitor.register_with_event_loop.assert_called_with(hub)
def test_reload(self): x = Autoreloader(Mock(), modules=[__name__]) x._reload([__name__]) x.controller.reload.assert_called_with([__name__], reload=True)
def test_module_name(self): x = Autoreloader(Mock(), modules=[__name__]) self.assertEqual(x._module_name("foo/bar/baz.py"), "baz")
def test_module_name(self): x = Autoreloader(Mock(), modules=[__name__]) self.assertEqual(x._module_name('foo/bar/baz.py'), 'baz')