Exemplo n.º 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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
 def test_int_handler_enum(self):
     class TestWrapper(enum.Enum):
         ValOne = 1
         ValTwo = 2
     handler = int_handler(self.state, 'attribute', wrapper=TestWrapper)
     handler(b'\x00\x00\x00\x02')
     self.assertEqual(self.state.attribute, TestWrapper.ValTwo)
Exemplo n.º 4
0
    def test_int_handler_enum(self):
        class TestWrapper(enum.Enum):
            ValOne = 1
            ValTwo = 2

        handler = int_handler(self.state, 'attribute', wrapper=TestWrapper)
        handler(b'\x00\x00\x00\x02')
        self.assertEqual(self.state.attribute, TestWrapper.ValTwo)
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
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)
Exemplo n.º 11
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)
Exemplo n.º 12
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)
Exemplo n.º 13
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)
Exemplo n.º 14
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)
Exemplo n.º 15
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)
Exemplo n.º 16
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)
Exemplo n.º 17
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)