コード例 #1
0
 def test_functions(self):
     f1 = lambda x: abs(int(x))
     f2 = lambda x: "number = %s" % x
     f = models.IntField(pos=0, parse=f1, replacement=f2)
     self.assertEqual(f.scan(row=["-10", "20"]), 10)
     self.assertEqual(f.emit(10), 'number = 10')
     self.assertEqual(f.emit(10, escaper=lambda x: "xx%sxx" % x),
                      'number = 10')
     f3 = models.IntField(pos=0, parse=f1, replacement="number = {}")
     self.assertEqual(f3.scan(row=["-10", "20"]), 10)
     self.assertEqual(f3.emit(10), 'number = 10')
     self.assertEqual(f3.emit(10, escaper=lambda x: "xx%sxx" % x),
                      'number = 10')
コード例 #2
0
 def test_basics(self):
     f = models.IntField(pos=0, name='f')
     self.assertEqual(f.default, 0)
     self.assertFalse(f.key)
     self.assertFalse(f.required)
     self.assertEqual(f.scan(row=["10", "20"]), 10)
     self.assertEqual(f.emit(10), 10)
     self.assertEqual(f.json_schema(), {'f': {'type': 'integer'}})
コード例 #3
0
class DefaultModel(models.Model):
    a = models.HiddenField(pos=0)
    b = models.IntField(pos=1, key=True)
    c = models.NullIntField(pos=2)
    d = models.StringField(pos=3)
    e = models.NullStringField(pos=4)
    f = models.BooleanField(pos=5)
    g = models.NullField(pos=6)
    h = models.UUIDField(pos=7)
    i = models.JSONField(pos=8)
    j = models.MappingField(pos=8, data_map={"M":"Male", "F": "Female"})
コード例 #4
0
 def test_parse_value(self):
     f = models.IntField(pos=0, parse=lambda x: int(x) * 2)
     self.assertEqual(f.scan(row=["10", "20"]), 20)
コード例 #5
0
 def test_exception_int(self):
     f = models.IntField(pos=0)
     self.assertRaises(ValueError, f.scan, row=["BLA", "20"])
コード例 #6
0
 def test_set_fields(self):
     f = models.IntField(pos=0, key=True, required=True)
     self.assertTrue(f.key)
     self.assertTrue(f.required)
コード例 #7
0
 def test_default_null(self):
     f = models.IntField(pos=0, nullable="NULL", default=10)
     self.assertEqual(f.scan(row=["NULL", "20"]), None)
     self.assertEqual(f.default, 10)
     self.assertEqual(f.emit(None), 10)
コード例 #8
0
 def test_index_data_exception(self):
     f = models.IntField(pos=2, name='f')
     self.assertRaises(DataException, f.scan, row=["10", "20"])
コード例 #9
0
 def test_validation(self):
     f = models.IntField(pos=0, validate=lambda x: int(x) < 100)
     self.assertRaises(ValidationException, f.scan, row=["200", "20"])
コード例 #10
0
 def test_parse_row(self):
     f = models.IntField(parse=lambda x: int(x[1]) * 2)
     self.assertEqual(f.scan(row=["10", "20"]), 40)