Beispiel #1
0
   def testDict(self):
      try:
         das.conform({1: {"given": "Bart", "family": "Simpson"}}, "conform.NameDict")
      except Exception:
         self.assertTrue(False)
      else:
         self.assertTrue(True)

      try:
         das.conform({1: "Simpson"}, "conform.NameDict")
      except Exception:
         self.assertTrue(True)
      else:
         self.assertTrue(False)
Beispiel #2
0
   def testStruct(self):
      bart = {"name": {"given": "Bart", "family": "Simpson", "middle": "Jojo"}, "age": 10, "gender": "male"}
      res = das.conform(bart, "conform.Person")
      self.assertNotIn("gender", res)
      self.assertIn("name", res)
      self.assertIn("given", res["name"])
      self.assertIn("family", res["name"])
      self.assertNotIn("middle", res["name"])
      self.assertIn("age", res)

      bart.pop("age")
      try:
         res = das.conform(bart, "conform.Person")
      except:
         self.assertTrue(True)
      else:
         self.assertTrue(False)
Beispiel #3
0
 def testSequence(self):
    seq = [{"name": {"given": "Lisa", "family": "Simpson", "middle": "Marie"}, "age": 7, "gender": "female"}, {"name": {"given": "Bart", "family": "Simpson", "middle": "Jojo"}, "age": 10, "gender": "male"}]
    res = das.conform(seq, "conform.PersonSeq")
    for per in res:
       self.assertNotIn("gender", per)
       self.assertIn("name", per)
       self.assertIn("given", per["name"])
       self.assertIn("family", per["name"])
       self.assertNotIn("middle", per["name"])
       self.assertIn("age", per)
Beispiel #4
0
   def testFill(self):
      res = {"age": 1}

      try:
         res = das.conform(res, "conform.Person")
      except:
         self.assertTrue(True)
      else:
         self.assertTrue(False)

      self.assertNotIn("name", res)

      res = {"age": 1}

      try:
         res = das.conform(res, "conform.Person", fill=True)
      except:
         self.assertTrue(False)
      else:
         self.assertTrue(True)

      self.assertIn("name", res)
Beispiel #5
0
 def check(cls, v):
     try:
         das.conform(v, cls.Schema, fill=False)
         return True
     except:
         return False
Beispiel #6
0
 def __init__(self, value):
     super(Das, self).__init__()
     self.__v = das.conform(value, self.Schema, fill=False)