Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
 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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)