def test_do(self): """Test 'do' functionality.""" xknx = XKNX(loop=self.loop) cover = Cover(xknx, 'TestCover') with patch('xknx.devices.Cover.set_up') as mock: fut = asyncio.Future() fut.set_result(None) mock.return_value = fut self.loop.run_until_complete(asyncio.Task(cover.do("up"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.set_short_up') as mock: fut = asyncio.Future() fut.set_result(None) mock.return_value = fut self.loop.run_until_complete(asyncio.Task(cover.do("short_up"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.set_down') as mock: fut = asyncio.Future() fut.set_result(None) mock.return_value = fut self.loop.run_until_complete(asyncio.Task(cover.do("down"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.set_short_down') as mock: fut = asyncio.Future() fut.set_result(None) mock.return_value = fut self.loop.run_until_complete(asyncio.Task(cover.do("short_down"))) mock.assert_called_once_with()
def test_do(self): """Test 'do' functionality.""" async def async_none(): return None xknx = XKNX() cover = Cover(xknx, "TestCover") with patch("xknx.devices.Cover.set_up") as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(cover.do("up")) mock.assert_called_once_with() with patch("xknx.devices.Cover.set_short_up") as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(cover.do("short_up")) mock.assert_called_once_with() with patch("xknx.devices.Cover.set_down") as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(cover.do("down")) mock.assert_called_once_with() with patch("xknx.devices.Cover.set_short_down") as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(cover.do("short_down")) mock.assert_called_once_with() with patch("xknx.devices.Cover.stop") as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(cover.do("stop")) mock.assert_called_once_with()
def test_do(self): """Test 'do' functionality.""" async def async_none(): return None xknx = XKNX(loop=self.loop) cover = Cover( xknx, 'TestCover') with patch('xknx.devices.Cover.set_up') as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(asyncio.Task(cover.do("up"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.set_short_up') as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(asyncio.Task(cover.do("short_up"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.set_down') as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(asyncio.Task(cover.do("down"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.set_short_down') as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(asyncio.Task(cover.do("short_down"))) mock.assert_called_once_with() with patch('xknx.devices.Cover.stop') as mock: mock.return_value = asyncio.ensure_future(async_none()) self.loop.run_until_complete(asyncio.Task(cover.do("stop"))) mock.assert_called_once_with()
def test_wrong_do(self): """Test wrong do command.""" xknx = XKNX(loop=self.loop) cover = Cover(xknx, 'TestCover') with patch('logging.Logger.warning') as mock_warn: self.loop.run_until_complete(asyncio.Task(cover.do("execute"))) self.assertEqual(xknx.telegrams.qsize(), 0) mock_warn.assert_called_with( 'Could not understand action %s for device %s', 'execute', 'TestCover')
def test_wrong_do(self): """Test wrong do command.""" xknx = XKNX() cover = Cover(xknx, "TestCover") with patch("logging.Logger.warning") as mock_warn: self.loop.run_until_complete(cover.do("execute")) self.assertEqual(xknx.telegrams.qsize(), 0) mock_warn.assert_called_with( "Could not understand action %s for device %s", "execute", "TestCover")
def test_wrong_do(self): """Test wrong do command.""" xknx = XKNX(loop=self.loop) cover = Cover( xknx, 'TestCover') with patch('logging.Logger.warning') as mock_warn: self.loop.run_until_complete(asyncio.Task(cover.do("execute"))) self.assertEqual(xknx.telegrams.qsize(), 0) mock_warn.assert_called_with('Could not understand action %s for device %s', 'execute', 'TestCover')