def setUp(self):
     self.seg = RegisterSegment("NAME", 0, 7, self.bits)
Exemplo n.º 2
0
 def add(self, name, lsb_i, msb_i, bits):
     self.segments[name] = RegisterSegment(name, lsb_i, msb_i, bits)
     return self
 def test_lsb_higher_than_msb(self):
     with self.assertRaises(ValueError):
         seg = RegisterSegment("NAME", 7, 0, [0] * 8)
 def test_provided_bits_too_small(self):
     with self.assertRaises(IndexError):
         seg = RegisterSegment("NAME", 0, 7, [0])
 def test_len(self):
     seg = RegisterSegment("NAME", 0, 2, [0] * 3)
     self.assertEqual(len(seg), 3)
 def test_perfect(self):
     seg = RegisterSegment("NAME", 0, 7, [0] * 8)
     self.assertEqual(seg.name, "NAME")
     self.assertEqual(seg.lsb_i, 0)
     self.assertEqual(seg.msb_i, 7)
     self.assertEqual(seg.bits, [0] * 8)
 def test_bit_value_err(self):
     seg = RegisterSegment("NAME", 0, 2, [0] * 3)
     with self.assertRaises(ValueError):
         seg.set_bits([1, 2, 3])
 def test_str(self):
     seg = RegisterSegment("NAME", 0, 2, [0] * 3)
     self.assertEqual(
         str(seg),
         "RegisterSegment<name=NAME, lsb_i=0, msb_i=2, bits=[0, 0, 0]>")
 def test_too_few_bits(self):
     seg = RegisterSegment("NAME", 0, 2, [0] * 3)
     with self.assertRaises(IndexError):
         seg.set_bits([0])
 def test_perfect(self):
     seg = RegisterSegment("NAME", 0, 2, [0] * 3)
     seg.set_bits([1, 1, 0])
     self.assertEqual(seg.bits, [1, 1, 0])
 def test_not_enough_bits(self):
     seg = RegisterSegment("NAME", 9, 11, [0] * 3)
     with self.assertRaises(KeyError):
         seg.update_bits([240])
 def test_in_second_byte(self):
     seg = RegisterSegment("NAME", 9, 11, [0] * 3)
     seg.update_bits([213, 170])
     self.assertEqual(seg.bits, [1, 0, 1])
 def test_perfect(self):
     seg = RegisterSegment("NAME", 0, 2, [0] * 3)
     seg.update_bits([213, 170])
     self.assertEqual(seg.bits, [1, 0, 1])