def test_property_validator(self): p = Parameter("BasicString", Type="String", MaxLength=10) p.validate() p = Parameter("BasicString", Type="String", MaxValue=10) with self.assertRaises(ValueError): p.validate() p = Parameter("BasicNumber", Type="Number", MaxValue=10) p.validate() p = Parameter("BasicNumber", Type="Number", AllowedPattern=".*") with self.assertRaises(ValueError): p.validate()
def test_property_default(self): p = Parameter("param", Type="String", Default="foo") p.validate() p = Parameter("param", Type="Number", Default=1) p.validate() p = Parameter("param", Type="Number", Default=1.0) p.validate() p = Parameter("param", Type="Number", Default=0.1) p.validate() p = Parameter("param", Type="List<Number>", Default="1, 2, 3") p.validate() p = Parameter("param", Type="List<Number>", Default=" 0.1 , 2 , 1.1 ") p.validate() with self.assertRaises(ValueError): p = Parameter("param", Type="String", Default=1) p.validate() with self.assertRaises(ValueError): p = Parameter("param", Type="Number", Default="foo") p.validate() with self.assertRaises(TypeError): p = Parameter("param", Type="Number", Default=["foo"]) p.validate() with self.assertRaises(ValueError): p = Parameter("param", Type="List<Number>", Default="foo") p.validate() with self.assertRaises(ValueError): p = Parameter("param", Type="List<Number>", Default="1, 2, foo") p.validate() with self.assertRaises(TypeError): p = Parameter("param", Type="List<Number>", Default=["1", "2"]) p.validate()