Ejemplo n.º 1
0
class TestCodeBugGet(unittest.TestCase):

    def setUp(self):
        self.codebug = CodeBugRaw(serial.Serial('/dev/ttyACM0'))
        # self.codebug = CodeBugRaw(serial.Serial('/dev/pts/31'))
        self.num_channels = 5

    def test_set_get(self):
        for i in range(self.num_channels):
            self.codebug.set(i, (i*i) % 0x1F)

        for i in range(self.num_channels):
            self.assertEqual(self.codebug.get(i), (i*i) % 0x1F)
Ejemplo n.º 2
0
 def setUp(self):
     self.codebug = CodeBugRaw(serial.Serial('/dev/ttyACM0'))
     # self.codebug = CodeBugRaw(serial.Serial('/dev/pts/4'))
     self.num_channels = 5
Ejemplo n.º 3
0
class TestCodeBugRawObject(unittest.TestCase):

    def setUp(self):
        self.codebug = CodeBugRaw(serial.Serial('/dev/ttyACM0'))
        # self.codebug = CodeBugRaw(serial.Serial('/dev/pts/4'))
        self.num_channels = 5

    # @unittest.skip
    def test_channels_get_set(self):
        """
            >>> codebug.set(1, 2)
            >>> codebug.get(1)
            2
        """
        for i in range(self.num_channels):
            self.codebug.set(i, (i*i) % 0x1F)

        for i in range(self.num_channels):
            self.assertEqual(self.codebug.get(i), (i*i) % 0x1F)

        # with or_mask
        for i in range(self.num_channels):
            self.codebug.set(i, 0x10, or_mask=True)

        for i in range(self.num_channels):
            self.assertEqual(self.codebug.get(i), (0x10 | (i*i)) % 0x1F)

    # @unittest.skip
    def test_channel_get_set_bulk(self):
        """
            >>> codebug.set_bulk(0, [1, 2, 3])
            >>> codebug.channels[1].value
            2
        """
        v = list(range(self.num_channels))
        self.codebug.set_bulk(0, v)
        self.assertEqual(tuple(self.codebug.get_bulk(0, len(v))),
                         tuple(v))

        v[2] = 0b11011
        v[3] = 0b01001
        self.codebug.set_bulk(2, v[2:4])
        self.assertEqual(tuple(self.codebug.get_bulk(0, self.num_channels)),
                         tuple(v))

        v = list(range(self.num_channels))
        self.codebug.set_bulk(0, v)
        self.assertEqual(tuple(self.codebug.get_bulk(0, len(v))),
                         tuple(v))

        v[2] |= 0b10001
        v[3] |= 0b01001
        self.codebug.set_bulk(2, v[2:4], or_mask=True)
        self.assertEqual(tuple(self.codebug.get_bulk(0, self.num_channels)),
                         tuple(v))

    def test_channel_get_set_bulk(self):
        x = self.codebug.get(5)
        a = (x >> 4) & 0x1
        b = (x >> 5) & 0x1
        print("A is {}, B is {}".format(a, b))