def test_float_handler_wrapper_default(self): handler = float_handler(self.state, "attribute", lambda x: x > 0, True) self.assertTrue(self.state.attribute) handler(b"\xc2(\x00\x00") self.assertFalse(self.state.attribute) handler(b"B(\x00\x00") self.assertTrue(self.state.attribute)
def test_float_handler_basic(self): with self.assertRaises(AttributeError): self.state.attribute handler = float_handler(self.state, "attribute") self.assertEqual(self.state.attribute, 0.0) handler(b"@I\x0f\xdb") self.assertAlmostEqual(self.state.attribute, math.pi, places=5)
def test_float_handler_basic(self): with self.assertRaises(AttributeError): self.state.attribute handler = float_handler(self.state, 'attribute') self.assertEqual(self.state.attribute, 0.0) handler(b'@I\x0f\xdb') self.assertAlmostEqual(self.state.attribute, math.pi, places=5)
def test_float_handler_default(self): handler = float_handler(self.state, 'attribute', default=7.0) self.assertEqual(self.state.attribute, 7.0)
def test_float_handler_wrapper(self): handler = float_handler(self.state, 'attribute', lambda x: x * x) handler(b'@I\x0f\xdb') self.assertAlmostEqual(self.state.attribute, math.pi * math.pi, places=5)
def test_float_handler_default(self): handler = float_handler(self.state, "attribute", default=7.0) self.assertEqual(self.state.attribute, 7.0)
def test_float_handler_wrapper(self): handler = float_handler(self.state, "attribute", lambda x: x * x) handler(b"@I\x0f\xdb") self.assertAlmostEqual(self.state.attribute, math.pi * math.pi, places=5)