def setUp(self): self.backend = Backend(FrontendMock())
class TestCase(unittest.TestCase): def setUp(self): self.backend = Backend(FrontendMock()) def test_exception_when_not_initialized(self): """ The backend should raise an AttributeError saying there's no 'client' attribute. This might be changed to something better later on, but for now at least have a test. """ self.assertRaises(AttributeError, self.backend.idle) self.backend.initialize() self.assertTrue(hasattr(self.backend, 'client')) self.backend.disconnect() def test_idle_thread_runs_after_initialize(self): self.backend.initialize() self.assertTrue(self.backend.idle_thread.frontend is not None) self.assertTrue(self.backend.idle_thread.is_alive()) self.assertTrue(self.backend.idle_thread.should_run) self.assertTrue(self.backend.idle_thread.daemon) self.backend.disconnect() def test_go_into_idle_mode(self): self.backend.initialize() self.assertFalse(self.backend.client.idle) self.assertFalse(self.backend.idle_request.is_set()) self.backend.idle() self.assertTrue(self.backend.client.idle) self.assertTrue(self.backend.idle_request.is_set()) # If this test hangs, async_refresh is never called! self.assertTrue(self.backend.frontend.async_refresh_called.wait(5.0)) self.backend.frontend.async_refresh_called.clear() def test_with_statement(self): self.backend.initialize() self.backend.idle() with self.backend: pass self.assertEqual(self.backend.last_changes(), ['playlist'])