def test_it_validates_nullable(self):
    self.assertValidationPasses(None, schema.float.nullable)
    self.assertValidationPasses(None, schema.float(3.14).nullable)

    self.assertValidationFails(False, schema.float.nullable)
    self.assertValidationFails('',    schema.float.nullable)
    self.assertValidationFails([],    schema.float.nullable)
    self.assertValidationFails({},    schema.float.nullable)
Exemple #2
0
  def test_it_validates_nullable(self):
    with warnings.catch_warnings():
      warnings.simplefilter('ignore')

      self.assertValidationPasses(None, schema.float.nullable)
      self.assertValidationPasses(None, schema.float(3.14).nullable)

      self.assertValidationFails(False, schema.float.nullable)
      self.assertValidationFails('',    schema.float.nullable)
      self.assertValidationFails([],    schema.float.nullable)
      self.assertValidationFails({},    schema.float.nullable)
Exemple #3
0
  def test_it_validates_max_value_with_precision(self):
    self.assertValidationPasses(3.141, schema.float.max(math.pi).precision(3))
    self.assertValidationPasses(3.1414, schema.float.max(math.pi).precision(3))
    self.assertValidationPasses(3.1416, schema.float.max(math.pi).precision(3))

    self.assertValidationPasses(-3.141, schema.float.max(-math.pi).precision(3))
    self.assertValidationPasses(-3.1414, schema.float.max(-math.pi).precision(3))
    self.assertValidationPasses(-3.1416, schema.float(-math.pi).precision(3))

    self.assertValidationFails(3.142, schema.float.max(math.pi).precision(3))
    self.assertValidationFails(-3.140, schema.float.max(-math.pi).precision(3))
Exemple #4
0
  def test_it_validates_value(self):
    self.assertValidationPasses(3.14,  schema.float(3.14))
    self.assertValidationPasses(-3.14, schema.float(-3.14))
    self.assertValidationPasses(0.0,   schema.float.zero)

    self.assertValidationFails(None,  schema.float(0.0))
    self.assertValidationFails(3.14,  schema.float(-3.14))
    self.assertValidationFails(-3.14, schema.float(3.14))
    self.assertValidationFails(3,     schema.float(3.14))
    self.assertValidationFails('0.0', schema.float.zero)
  def test_it_validates_value(self):
    self.assertValidationPasses(3.14,  schema.float(3.14))
    self.assertValidationPasses(-3.14, schema.float(-3.14))
    self.assertValidationPasses(0.0,   schema.float.zero)

    self.assertValidationFails(None,  schema.float(0.0))
    self.assertValidationFails(3.14,  schema.float(-3.14))
    self.assertValidationFails(-3.14, schema.float(3.14))
    self.assertValidationFails(3,     schema.float(3.14))
    self.assertValidationFails('0.0', schema.float.zero)
  def test_number_type_representation(self):
    self.assertRepr(schema.number,               'schema.number')
    self.assertRepr(schema.number(42),           'schema.number(42)')
    self.assertRepr(schema.number(3.14),         'schema.number(3.14)')
    self.assertRepr(schema.number.min(0),        'schema.number.min(0)')
    self.assertRepr(schema.number.max(1),        'schema.number.max(1)')
    self.assertRepr(schema.number.between(0, 1), 'schema.number.between(0, 1)')
    self.assertRepr(schema.number.positive,      'schema.number.positive')
    self.assertRepr(schema.number.non_positive,  'schema.number.non_positive')
    self.assertRepr(schema.number.negative,      'schema.number.negative')
    self.assertRepr(schema.number.non_negative,  'schema.number.non_negative')
    self.assertRepr(schema.number.unsigned,      'schema.number.unsigned')
    self.assertRepr(schema.number.zero,          'schema.number.zero')
    self.assertRepr(schema.number.multiple(5),   'schema.number.multiple(5)')
    self.assertRepr(schema.number.nullable,      'schema.number.nullable')

    self.assertRepr(schema.integer,               'schema.integer')
    self.assertRepr(schema.integer(42),           'schema.integer(42)')
    self.assertRepr(schema.integer.min(0),        'schema.integer.min(0)')
    self.assertRepr(schema.integer.max(1),        'schema.integer.max(1)')
    self.assertRepr(schema.integer.between(0, 1), 'schema.integer.between(0, 1)')
    self.assertRepr(schema.integer.positive,      'schema.integer.positive')
    self.assertRepr(schema.integer.non_positive,  'schema.integer.non_positive')
    self.assertRepr(schema.integer.negative,      'schema.integer.negative')
    self.assertRepr(schema.integer.non_negative,  'schema.integer.non_negative')
    self.assertRepr(schema.integer.zero,          'schema.integer.zero')
    self.assertRepr(schema.integer.multiple(5),   'schema.integer.multiple(5)')
    self.assertRepr(schema.integer.nullable,      'schema.integer.nullable')

    self.assertRepr(schema.float,                   'schema.float')
    self.assertRepr(schema.float(3.14),             'schema.float(3.14)')
    self.assertRepr(schema.float.min(0.0),          'schema.float.min(0.0)')
    self.assertRepr(schema.float.max(1.0),          'schema.float.max(1.0)')
    self.assertRepr(schema.float.between(0.0, 1.0), 'schema.float.between(0.0, 1.0)')
    self.assertRepr(schema.float.positive,          'schema.float.positive')
    self.assertRepr(schema.float.non_positive,      'schema.float.non_positive')
    self.assertRepr(schema.float.negative,          'schema.float.negative')
    self.assertRepr(schema.float.non_negative,      'schema.float.non_negative')
    self.assertRepr(schema.float.zero,              'schema.float.zero')
    self.assertRepr(schema.float.nullable,          'schema.float.nullable')