Пример #1
0
 def test_int_handler_basic(self):
     with self.assertRaises(AttributeError):
         self.state.attribute
     handler = int_handler(self.state, 'attribute')
     self.assertEqual(self.state.attribute, 0)
     handler(b'\x00\x00\x00\x01')
     self.assertEqual(self.state.attribute, 1)
Пример #2
0
 def test_int_handler_enum(self):
     handler = int_handler(self.state, 'attribute', wrapper=TestEnum)
     handler(b'\x00\x00\x00\x02')
     self.assertEqual(self.state.attribute, TestEnum.ValTwo)
Пример #3
0
 def test_int_handler_default(self):
     handler = int_handler(self.state, 'attribute', default=7)
     self.assertEqual(self.state.attribute, 7)
     handler(b'\x00\x00\x00\x08')
     self.assertEqual(self.state.attribute, 8)
Пример #4
0
 def test_int_handler_wrapper(self):
     wrapper = lambda x: x * x
     handler = int_handler(self.state, 'attribute', wrapper=wrapper)
     handler(b'\x00\x00\x00\x04')
     self.assertEqual(self.state.attribute, 0x10)
Пример #5
0
 def test_int_handler_shift(self):
     handler = int_handler(self.state, 'attribute', shift=8)
     handler(b'\xF0\xFF\xFF\x0F')
     self.assertEqual(self.state.attribute, 0xFFF0FFFF)
Пример #6
0
 def test_int_handler_mask(self):
     handler = int_handler(self.state, 'attribute', mask=0xFF00)
     handler(b'\x00\x00\xFF\xFF')
     self.assertEqual(self.state.attribute, 0xFF00)