def test_should_allow_integer(self): self.assertEqual(coerce_parameters(0), 0) self.assertEqual(coerce_parameters(0x7F), 0x7F) self.assertEqual(coerce_parameters(0x7FFF), 0x7FFF) self.assertEqual(coerce_parameters(0x7FFFFFFF), 0x7FFFFFFF) self.assertEqual(coerce_parameters(0x7FFFFFFFFFFFFFFF), 0x7FFFFFFFFFFFFFFF)
def test_should_allow_dict(self): self.assertEqual(coerce_parameters({}), {}) self.assertEqual( coerce_parameters({ u"one": 1, u"two": 1, u"three": 1 }), { u"one": 1, u"two": 1, u"three": 1 }) self.assertEqual( coerce_parameters({ u"list": [1, 2, 3, [4, 5, 6]], u"dict": { u"a": 1, u"b": 2 } }), { u"list": [1, 2, 3, [4, 5, 6]], u"dict": { u"a": 1, u"b": 2 } })
def test_should_disallow_object(self): with self.assertRaises(TypeError): coerce_parameters(object()) with self.assertRaises(TypeError): coerce_parameters(uuid4())
def test_should_allow_list(self): self.assertEqual(coerce_parameters([]), []) self.assertEqual(coerce_parameters([1, 2, 3]), [1, 2, 3])
def test_should_allow_bytes(self): self.assertEqual(coerce_parameters(bytearray()), bytearray()) self.assertEqual(coerce_parameters(bytearray([1, 2, 3])), bytearray([1, 2, 3]))
def test_should_allow_string(self): self.assertEqual(coerce_parameters(u""), u"") self.assertEqual(coerce_parameters(u"hello, world"), u"hello, world")
def test_should_allow_float(self): self.assertEqual(coerce_parameters(0.0), 0.0) self.assertEqual(coerce_parameters(3.1415926), 3.1415926)
def test_should_disallow_oversized_integer(self): with self.assertRaises(ValueError): coerce_parameters(0x10000000000000000) with self.assertRaises(ValueError): coerce_parameters(-0x10000000000000000)
def test_should_allow_boolean(self): self.assertTrue(coerce_parameters(True)) self.assertFalse(coerce_parameters(False))
def test_should_allow_none(self): self.assertIsNone(coerce_parameters(None))