From c1d5f65368f4169e4d5682669c07c45b64985885 Mon Sep 17 00:00:00 2001 From: Felix Nieuwenhuizen Date: Sun, 27 Jan 2019 11:11:08 +0100 Subject: [PATCH 1/2] travis: run pylint on correct package --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 713bce4..cb0bbad 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ script: coverage run --source=pyxcp setup.py test after_success: - - pylint app + - pylint pyxcp - coveralls - coverage xml && python-codacy-coverage -r coverage.xml - codeclimate-test-reporter From 02a437dde8a3ec7312b4675d39a467e4f7805fbb Mon Sep 17 00:00:00 2001 From: Felix Nieuwenhuizen Date: Fri, 8 Feb 2019 22:48:52 +0100 Subject: [PATCH 2/2] add testcase with socket send/recv --- pyxcp/tests/test_master.py | 45 ++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/pyxcp/tests/test_master.py b/pyxcp/tests/test_master.py index e76efd4..03f4b93 100644 --- a/pyxcp/tests/test_master.py +++ b/pyxcp/tests/test_master.py @@ -13,17 +13,18 @@ class TestMaster(unittest.TestCase): @mock.patch("pyxcp.transport.Eth") def testConnect(self, Eth): tr = Eth() - tr.request.return_value = bytes([0x1d, 0xc0, 0xff, 0xdc, 0x05, 0x01, 0x01]) + tr.request.return_value = bytes( + [0x1d, 0xc0, 0xff, 0xdc, 0x05, 0x01, 0x01]) with Master(tr) as xm: res = xm.connect() self.assertEqual(res.maxCto, 255) self.assertEqual(res.maxDto, 1500) self.assertEqual(res.protocolLayerVersion, 1) self.assertEqual(res.transportLayerVersion, 1) - self.assertEqual(res.resource.pgm , True) - self.assertEqual(res.resource.stim , True) - self.assertEqual(res.resource.daq , True) - self.assertEqual(res.resource.calpag , True) + self.assertEqual(res.resource.pgm, True) + self.assertEqual(res.resource.stim, True) + self.assertEqual(res.resource.daq, True) + self.assertEqual(res.resource.calpag, True) self.assertEqual(res.commModeBasic.optional, True) self.assertEqual(res.commModeBasic.slaveBlockMode, True) self.assertEqual(res.commModeBasic.addressGranularity, 'BYTE') @@ -67,7 +68,8 @@ def testSync(self, Eth): @mock.patch("pyxcp.transport.Eth") def testGetCommModeInfo(self, Eth): tr = Eth() - tr.request.return_value = bytes([0x00, 0x01, 0xff, 0x02, 0x00, 0x00, 0x19]) + tr.request.return_value = bytes( + [0x00, 0x01, 0xff, 0x02, 0x00, 0x00, 0x19]) with Master(tr) as xm: res = xm.getCommModeInfo() self.assertEqual(res.commModeOptional.interleavedMode, False) @@ -80,20 +82,45 @@ def testGetCommModeInfo(self, Eth): @mock.patch("pyxcp.transport.Eth") def testGetID(self, Eth): tr = Eth() - tr.request.return_value = bytes([0x00, 0x01, 0xff, 0x06, 0x00, 0x00, 0x00]) + tr.request.return_value = bytes( + [0x00, 0x01, 0xff, 0x06, 0x00, 0x00, 0x00]) with Master(tr) as xm: gid = xm.getID(0x01) - tr.request.return_value = bytes([0x58, 0x43, 0x50, 0x73, 0x69, 0x6d]) + tr.request.return_value = bytes( + [0x58, 0x43, 0x50, 0x73, 0x69, 0x6d]) res = xm.upload(gid.length) self.assertEqual(gid.mode, 0) self.assertEqual(gid.reserved, 65281) self.assertEqual(gid.length, 6) self.assertEqual(res, b'XCPsim') + @mock.patch('socket.socket') + @mock.patch('selectors.DefaultSelector') + def testDownloadMax(self, mock_selector, mock_socket): + mock_socket.return_value.recv.side_effect = [ + [0x01, 0x00, 0xff, 0x06], [0xff]] + mock_selector.return_value.select.side_effect = [[(0, 1)], [(0, 1)]] + + tr = transport.Eth('localhost', loglevel="DEBUG") + + mock_socket.assert_called() + mock_selector.assert_called() + mock_selector.return_value.register.assert_called() + + with Master(tr) as xm: + data = [0xCA, 0xFE, 0xBA, 0xBE] + print("testDownloadMax: {} {}".format(len(data), data)) + xm.downloadMax(data) + + tr.close() + + mock_socket.return_value.send.assert_called_with(bytes( + [0x05, 0x00, 0x00, 0x00, 0xee, 0xca, 0xfe, 0xba, 0xbe])) + def main(): unittest.main() + if __name__ == '__main__': main() -