Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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()
Exemplo n.º 4
0
 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__])
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
 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__))
Exemplo n.º 7
0
 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__))
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
 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()
Exemplo n.º 10
0
 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__])
Exemplo n.º 11
0
 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__))
Exemplo n.º 12
0
 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__))
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
    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)
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
 def test_reload(self):
     x = Autoreloader(Mock(), modules=[__name__])
     x._reload([__name__])
     x.controller.reload.assert_called_with([__name__], reload=True)
Exemplo n.º 18
0
 def test_module_name(self):
     x = Autoreloader(Mock(), modules=[__name__])
     self.assertEqual(x._module_name("foo/bar/baz.py"), "baz")
Exemplo n.º 19
0
 def test_reload(self):
     x = Autoreloader(Mock(), modules=[__name__])
     x._reload([__name__])
     x.controller.reload.assert_called_with([__name__], reload=True)
Exemplo n.º 20
0
 def test_module_name(self):
     x = Autoreloader(Mock(), modules=[__name__])
     self.assertEqual(x._module_name('foo/bar/baz.py'), 'baz')