def test_Either(self): with self.assertRaises(TypeError): prop = Either() prop = Either(Range(Int, 0, 100), Regex("^x*$"), List(Int)) self.assertTrue(prop.is_valid(None)) # TODO: self.assertFalse(prop.is_valid(False)) # TODO: self.assertFalse(prop.is_valid(True)) self.assertTrue(prop.is_valid(0)) self.assertTrue(prop.is_valid(1)) self.assertFalse(prop.is_valid(0.0)) self.assertFalse(prop.is_valid(1.0)) self.assertFalse(prop.is_valid(1.0 + 1.0j)) self.assertTrue(prop.is_valid("")) self.assertFalse(prop.is_valid(())) self.assertTrue(prop.is_valid([])) self.assertFalse(prop.is_valid({})) self.assertFalse(prop.is_valid(Foo())) self.assertTrue(prop.is_valid(100)) self.assertFalse(prop.is_valid(-100)) self.assertTrue(prop.is_valid("xxx")) self.assertFalse(prop.is_valid("yyy")) self.assertTrue(prop.is_valid([1, 2, 3])) self.assertFalse(prop.is_valid([1, 2, ""]))
def test_Regex(self): with self.assertRaises(TypeError): prop = Regex() prop = Regex("^x*$") self.assertTrue(prop.is_valid(None)) self.assertFalse(prop.is_valid(False)) self.assertFalse(prop.is_valid(True)) self.assertFalse(prop.is_valid(0)) self.assertFalse(prop.is_valid(1)) self.assertFalse(prop.is_valid(0.0)) self.assertFalse(prop.is_valid(1.0)) self.assertFalse(prop.is_valid(1.0 + 1.0j)) self.assertTrue(prop.is_valid("")) self.assertFalse(prop.is_valid(())) self.assertFalse(prop.is_valid([])) self.assertFalse(prop.is_valid({})) self.assertFalse(prop.is_valid(Foo()))
def test_Regex(self): with self.assertRaises(TypeError): prop = Regex() prop = Regex("^x*$") self.assertTrue(prop.is_valid(None)) self.assertFalse(prop.is_valid(False)) self.assertFalse(prop.is_valid(True)) self.assertFalse(prop.is_valid(0)) self.assertFalse(prop.is_valid(1)) self.assertFalse(prop.is_valid(0.0)) self.assertFalse(prop.is_valid(1.0)) self.assertFalse(prop.is_valid(1.0+1.0j)) self.assertTrue(prop.is_valid("")) self.assertFalse(prop.is_valid(())) self.assertFalse(prop.is_valid([])) self.assertFalse(prop.is_valid({})) self.assertFalse(prop.is_valid(Foo()))