class TestStrASCII(unittest.TestCase): def setUp(self): self.convert = ConvertStrASCII(source, action) def test_pack_result1(self): res = True msg = "message" value = 1234567 wait_result = [value, 'read', [res, msg]] result = list(self.convert._pack_result(res, msg, value)) self.assertEqual(wait_result, result) def test_pack_result2(self): res = True msg = "message" wait_result = [source, 'read', [res, msg]] result = list(self.convert._pack_result(res, msg)) self.assertEqual(wait_result, result) ''' Read tests ''' def test_bytes_to_value_0(self): # Here is 'Input6\x00\x00\x00\x00\x00\x00' string source = 'SW5wdXQ2AAAAAAAA' wait_result = self.convert._pack_result(True, OK, 'Input6') result = self.convert._bytes_to_value(source) self.assertEqual(result, wait_result) def test_bytes_to_value_1(self): source = '0tDMMjAyICBWMDMuMDAwMg==' wait_result = self.convert._pack_result(True, OK, '202 V03.0002') result = self.convert._bytes_to_value(source) self.assertEqual(result, wait_result) def test_bytes_to_value_2(self): source = 'qweqwe' wait_result = self.convert._pack_result(False, 'Incorrect argument') result = self.convert._bytes_to_value(source) self.assertEqual(result, wait_result) ''' Write tests ''' def test_value_to_bytes_0(self): source = 'Hello world' wait_result = self.convert._pack_result(True, OK, 'SGVsbG8gd29ybGQ=') result = self.convert._value_to_bytes(source) self.assertEqual(result, wait_result)
def setUp(self): self.convert = ConvertStrASCII(source, action)