def setUp(self):
     self.convert = ConvertFlag(source, action)
class TestFlag(unittest.TestCase):
    def setUp(self):
        self.convert = ConvertFlag(source, action)

    def test_test_input_1(self):
        self.convert._source = 'True'
        self.assertTrue(self.convert._test_input(self.convert._source))

    def test_test_input_2(self):
        self.convert._source = 'False'
        self.assertTrue(self.convert._test_input(self.convert._source))

    def test_test_input_3(self):
        self.convert._source = 'Test'
        self.assertFalse(self.convert._test_input(self.convert._source))

    def test_pack_result1(self):
        res = True
        msg = "message"
        value = 'True'
        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 = False
        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_1(self):
        source = '0'
        wait_result = self.convert._pack_result(True, 'Data OK', 'False')
        result = self.convert._bytes_to_value(source)
        self.assertEqual(result, wait_result)

    def test_bytes_to_value_2(self):
        source = 'Rqwertyu='
        wait_result = self.convert._pack_result(False, 'Not valid data: '
                                                'Rqwertyu=')
        result = self.convert._bytes_to_value(source)
        self.assertEqual(result, wait_result)

    def test_bytes_to_value_3(self):
        source = '1'
        wait_result = self.convert._pack_result(True, 'Data OK', 'True')
        result = self.convert._bytes_to_value(source)
        self.assertEqual(result, wait_result)

    ''' Write tests '''
    def test_value_to_bytes_1(self):
        source = 'True'
        wait_result = self.convert._pack_result(True, 'Data OK', '/wA=')
        result = self.convert._value_to_bytes(source)
        self.assertEqual(result, wait_result)

    def test_value_to_bytes_2(self):
        source = 'False'
        wait_result = self.convert._pack_result(True, 'Data OK', 'AAA=')
        result = self.convert._value_to_bytes(source)
        self.assertEqual(result, wait_result)

    def test_value_to_bytes_3(self):
        source = '18455545'
        wait_result = self.convert._pack_result(False,
                                                'Value to decode: 18455545'
                                                ' must be True or False')
        result = self.convert._value_to_bytes(source)
        self.assertEqual(result, wait_result)