예제 #1
0
 def test_jsonvalue(self):
     v = DlList([
         DlString("AAA"),
         DlList([
             DlInteger(1),
             DlDate(datetime.date(2020, 1, 3)),
             DlString(None),
             DlDictionary({
                 "C1": DlInteger(1),
                 "C2": DlDate(datetime.date(2020, 1, 3))
             })
         ])
     ])
     self.assertEqual(v.jsonvalue, [{
         ':s': 'AAA'
     },
                                    [{
                                        ':i': 1
                                    }, {
                                        ':d': '2020-01-03'
                                    }, {
                                        ':s': None
                                    }, {
                                        'C1:i': 1,
                                        'C2:d': '2020-01-03'
                                    }]])
예제 #2
0
 def test_fulltypename(self):
     v = DlList([
         DlInteger(1),
         DlInteger(2),
         DlDate(datetime.date(2020, 1, 3)),
         DlString(None)
     ])
     self.assertEqual(v.fulltypename, "LIST")
예제 #3
0
 def test_typecode(self):
     v = DlList([
         DlInteger(1),
         DlInteger(2),
         DlDate(datetime.date(2020, 1, 3)),
         DlString(None)
     ])
     self.assertEqual(v.typecode, "l")
예제 #4
0
 def test_fulltypename(self):
     v = DlDictionary({
         "C1":
         DlInteger(1),
         "C2":
         DlDate(datetime.date(2020, 1, 3)),
         "C3":
         DlString(None),
         "C4":
         DlList([
             DlInteger(2),
             DlDate(datetime.date(2020, 1, 3)),
             DlString(None)
         ]),
         "C5":
         DlDictionary({"C51": DlString("HHH")})
     })
     self.assertEqual(v.fulltypename, "DICTIONARY")
예제 #5
0
 def test_typecode(self):
     v = DlDictionary({
         "C1":
         DlInteger(1),
         "C2":
         DlDate(datetime.date(2020, 1, 3)),
         "C3":
         DlString(None),
         "C4":
         DlList([
             DlInteger(2),
             DlDate(datetime.date(2020, 1, 3)),
             DlString(None)
         ]),
         "C5":
         DlDictionary({"C51": DlString("HHH")})
     })
     self.assertEqual(v.typecode, "m")
예제 #6
0
 def test_jsondata(self):
     v = DlDictionary({
         "C2":
         DlDate(datetime.date(2020, 1, 3)),
         "C1":
         DlInteger(1),
         "C3":
         DlString(None),
         "C4":
         DlList([
             DlInteger(2),
             DlDate(datetime.date(2020, 1, 3)),
             DlString(None)
         ]),
         "C5":
         DlDictionary({"C51": DlString("HHH")})
     })
     self.assertEqual(jsondata(v), (
         '{"C1:i":1,"C2:d":"2020-01-03","C3:s":null,"C4":[{":i":2},{":d":"2020-01-03"},{":s":null}],"C5":{"C51:s":"HHH"}}',
         '2de76179ab2bbe63c1412b1bab782266fa82322f'))
예제 #7
0
 def test_jsonvalue(self):
     v = DlDictionary({
         "C1":
         DlInteger(1),
         "C2":
         DlDate(datetime.date(2020, 1, 3)),
         "C3":
         DlString(None),
         "C4":
         DlList([
             DlInteger(2),
             DlDate(datetime.date(2020, 1, 3)),
             DlString(None)
         ]),
         "C5":
         DlDictionary({"C51": DlString("HHH")})
     })
     self.assertEqual(
         json.dumps(v.jsonvalue),
         '{"C1:i": 1, "C2:d": "2020-01-03", "C3:s": null, "C4": [{":i": 2}, {":d": "2020-01-03"}, {":s": null}], "C5": {"C51:s": "HHH"}}'
     )
예제 #8
0
 def test_jsonvaluenone(self):
     v = DlString(None)
     self.assertIsNone(v.jsonvalue)
예제 #9
0
 def test_init2(self):
     with self.assertRaises(ValueError):
         v = DlString("ABC", 2)
예제 #10
0
 def test_jsonvalue(self):
     v = DlString("ABC")
     self.assertEqual(v.jsonvalue, "ABC")
예제 #11
0
 def test_typelength(self):
     v = DlString("ABC", 10)
     self.assertEqual(v.typelength, 10)
예제 #12
0
 def test_fulltypename(self):
     v = DlString("ABC", 10)
     self.assertEqual(v.fulltypename, "STRING(10)")
예제 #13
0
 def test_typename(self):
     v = DlString("ABC")
     self.assertEqual(v.typename, "STRING")
예제 #14
0
 def test_fulltypecode(self):
     v = DlString("ABC")
     self.assertEqual(v.fulltypecode, "s")
예제 #15
0
import sys

sys.path.append(".")
from dlschema.encoder import DlNull, DlInteger, DlDouble, DlDecimal, DlString, DlDate, DlTime, DlDatetime, DlTimestamp, DlBoolean, DlRaw, DlList, DlDictionary, jsondata
import unittest
from decimal import Decimal
import datetime
import json

if __name__ == '__main__':
    v = [
        DlDictionary({
            "ID":
            DlInteger(1),
            "NAME":
            DlString("Sherlock Holmes"),
            "ADDRESS":
            DlString("221b, Baker Street, London, NW1 6XE, UK", 200),
            "SALARY":
            DlDecimal(Decimal("12.45"), 16, 2),
            "TAXES":
            DlDecimal(
                Decimal("687192025652473624789243787872498713367.89012")),
            "BIRTHDAY":
            DlDate(datetime.date(2020, 1, 3)),
            "VISIT_TS":
            DlTimestamp(datetime.datetime.now()),
            "IS_MARRIED":
            DlBoolean(False),
            "CHILDREN":
            DlList([]),