Esempio n. 1
0
 def testDates(self):
     d = datetime.date(year=2012, month=9, day=25)
     serialized = json.dumps(d)
     self.assertEqual(
         serialized, '{"py/object": "datetime.date", '
         '"py/repr": "datetime.date(2012, 9, 25)"}')
     deserialized = json.loads(serialized)
     self.assertEqual(type(deserialized), datetime.date)
     self.assertEqual(deserialized.isoformat(), d.isoformat())
Esempio n. 2
0
 def testDumpsObject(self):
   testClass = InferenceShifter()
   testClass.a = 5
   testClass.b = {'b': (17,)}
   encoded = json.dumps(testClass, sort_keys=True)
   self.assertEqual(
       encoded,
       '{"_inferenceBuffer": null, "a": 5, "b": {"b": {"py/tuple": [17]}}, '
       '"py/object": "nupic.data.inference_shifter.InferenceShifter"}')
Esempio n. 3
0
 def testDumpsObject(self):
     testClass = InferenceShifter()
     testClass.a = 5
     testClass.b = {'b': (17, )}
     encoded = json.dumps(testClass, sort_keys=True)
     self.assertEqual(
         encoded,
         '{"_inferenceBuffer": null, "a": 5, "b": {"b": {"py/tuple": [17]}}, '
         '"py/object": "nupic.data.inference_shifter.InferenceShifter"}')
Esempio n. 4
0
 def testDates(self):
   d = datetime.date(year=2012, month=9, day=25)
   serialized = json.dumps(d)
   self.assertEqual(serialized,
                    '{"py/object": "datetime.date", '
                    '"py/repr": "datetime.date(2012, 9, 25)"}')
   deserialized = json.loads(serialized)
   self.assertEqual(type(deserialized), datetime.date)
   self.assertEqual(deserialized.isoformat(), d.isoformat())
Esempio n. 5
0
 def testDatetimes(self):
   d = datetime.datetime(year=2012, month=9, day=25, hour=14, minute=33,
                         second=8, microsecond=455969)
   serialized = json.dumps(d)
   self.assertEqual(serialized,
                    '{"py/object": "datetime.datetime", "py/repr": '
                    '"datetime.datetime(2012, 9, 25, 14, 33, 8, 455969)"}')
   deserialized = json.loads(serialized)
   self.assertEqual(type(deserialized), datetime.datetime)
   self.assertEqual(deserialized.isoformat(), d.isoformat())
Esempio n. 6
0
 def testDatetimes(self):
     d = datetime.datetime(year=2012,
                           month=9,
                           day=25,
                           hour=14,
                           minute=33,
                           second=8,
                           microsecond=455969)
     serialized = json.dumps(d)
     self.assertEqual(
         serialized, '{"py/object": "datetime.datetime", "py/repr": '
         '"datetime.datetime(2012, 9, 25, 14, 33, 8, 455969)"}')
     deserialized = json.loads(serialized)
     self.assertEqual(type(deserialized), datetime.datetime)
     self.assertEqual(deserialized.isoformat(), d.isoformat())
Esempio n. 7
0
 def testObjectWithNonStringKeys(self):
     testClass = InferenceShifter()
     testClass.a = 5
     testClass.b = {(4, 5): (17, )}
     encoded = json.dumps(testClass, sort_keys=True)
     self.assertEqual(
         encoded,
         '{"_inferenceBuffer": null, "a": 5, "b": {"py/dict/keys": '
         '["{\\"py/tuple\\": [4, 5]}"], "{\\"py/tuple\\": [4, 5]}": '
         '{"py/tuple": [17]}}, "py/object": '
         '"nupic.data.inference_shifter.InferenceShifter"}')
     decoded = json.loads(encoded)
     self.assertEqual(decoded.a, 5)
     self.assertEqual(type(decoded.b), dict)
     self.assertEqual(len(decoded.b.keys()), 1)
     self.assertTupleEqual(decoded.b.keys()[0], (4, 5))
     self.assertTupleEqual(decoded.b[(4, 5)], (17, ))
Esempio n. 8
0
 def testObjectWithNonStringKeys(self):
   testClass = InferenceShifter()
   testClass.a = 5
   testClass.b = {(4, 5): (17,)}
   encoded = json.dumps(testClass, sort_keys=True)
   self.assertEqual(
       encoded,
       '{"_inferenceBuffer": null, "a": 5, "b": {"py/dict/keys": '
       '["{\\"py/tuple\\": [4, 5]}"], "{\\"py/tuple\\": [4, 5]}": '
       '{"py/tuple": [17]}}, "py/object": '
       '"nupic.data.inference_shifter.InferenceShifter"}')
   decoded = json.loads(encoded)
   self.assertEqual(decoded.a, 5)
   self.assertEqual(type(decoded.b), dict)
   self.assertEqual(len(decoded.b.keys()), 1)
   self.assertTupleEqual(decoded.b.keys()[0], (4, 5))
   self.assertTupleEqual(decoded.b[(4, 5)], (17,))
Esempio n. 9
0
 def testPrimitives(self):
     self.assertEqual(json.loads(json.dumps(None)), None)
     self.assertEqual(json.loads(json.dumps(True)), True)
     self.assertEqual(json.loads(json.dumps(False)), False)
     self.assertEqual(json.loads(json.dumps(-5)), -5)
     self.assertEqual(json.loads(json.dumps(0)), 0)
     self.assertEqual(json.loads(json.dumps(5)), 5)
     self.assertEqual(json.loads(json.dumps(7.7)), 7.7)
     self.assertEqual(json.loads(json.dumps('hello')), 'hello')
     self.assertEqual(json.loads(json.dumps(5L)), 5L)
     self.assertEqual(json.loads(json.dumps(u'hello')), u'hello')
     self.assertEqual(json.loads(json.dumps([5, 6, 7])), [5, 6, 7])
     self.assertEqual(json.loads(json.dumps({
         '5': 6,
         '7': 8
     })), {
         '5': 6,
         '7': 8
     })
Esempio n. 10
0
 def testBasicDumps(self):
     d = {'a': 1, 'b': {'c': 2}}
     s = json.dumps(d, sort_keys=True)
     self.assertEqual(s, '{"a": 1, "b": {"c": 2}}')
Esempio n. 11
0
 def testTuple(self):
     self.assertTupleEqual(json.loads(json.dumps((5, 6, 7))), (5, 6, 7))
Esempio n. 12
0
 def testComplex(self):
   self.assertEqual(json.loads(json.dumps(2 + 1j)), 2 + 1j)
Esempio n. 13
0
 def testTuple(self):
   self.assertTupleEqual(json.loads(json.dumps((5, 6, 7))), (5, 6, 7))
Esempio n. 14
0
 def testDumpsTuple(self):
   self.assertEqual(json.dumps((5, 6, 7)), '{"py/tuple": [5, 6, 7]}')
Esempio n. 15
0
 def testPrimitives(self):
   self.assertEqual(json.loads(json.dumps(None)), None)
   self.assertEqual(json.loads(json.dumps(True)), True)
   self.assertEqual(json.loads(json.dumps(False)), False)
   self.assertEqual(json.loads(json.dumps(-5)), -5)
   self.assertEqual(json.loads(json.dumps(0)), 0)
   self.assertEqual(json.loads(json.dumps(5)), 5)
   self.assertEqual(json.loads(json.dumps(7.7)), 7.7)
   self.assertEqual(json.loads(json.dumps('hello')), 'hello')
   self.assertEqual(json.loads(json.dumps(5L)), 5L)
   self.assertEqual(json.loads(json.dumps(u'hello')), u'hello')
   self.assertEqual(json.loads(json.dumps([5, 6, 7])), [5, 6, 7])
   self.assertEqual(json.loads(json.dumps({'5': 6, '7': 8})), {'5': 6, '7': 8})
Esempio n. 16
0
 def testBasicDumps(self):
   d = {'a': 1, 'b': {'c': 2}}
   s = json.dumps(d, sort_keys=True)
   self.assertEqual(s, '{"a": 1, "b": {"c": 2}}')
Esempio n. 17
0
 def testDumpsTuple(self):
     self.assertEqual(json.dumps((5, 6, 7)), '{"py/tuple": [5, 6, 7]}')
Esempio n. 18
0
 def testDumpsWithIndent(self):
   d = {'a': 1, 'b': {'c': 2}}
   s = json.dumps(d, indent=2, sort_keys=True)
   self.assertEqual(s, '{\n  "a": 1,\n  "b": {\n    "c": 2\n  }\n}')
Esempio n. 19
0
 def testComplex(self):
     self.assertEqual(json.loads(json.dumps(2 + 1j)), 2 + 1j)
Esempio n. 20
0
 def testNonStringKeys(self):
     original = {1.1: 1, 5: {(7, 8, 9): {1.1: 5}}}
     result = json.loads(json.dumps(original))
     self.assertEqual(original, result)
Esempio n. 21
0
 def testDumpsWithIndent(self):
     d = {'a': 1, 'b': {'c': 2}}
     s = json.dumps(d, indent=2, sort_keys=True)
     self.assertEqual(s, '{\n  "a": 1,\n  "b": {\n    "c": 2\n  }\n}')
Esempio n. 22
0
 def testNonStringKeys(self):
   original = {1.1: 1, 5: {(7, 8, 9): {1.1: 5}}}
   result = json.loads(json.dumps(original))
   self.assertEqual(original, result)