def testSaveJson(self): ps = pipeBase.Struct(foo=2, bar=[10, 20], hard=np.array([5,10])) _, tmpFilepath = tempfile.mkstemp(suffix='.json') saveKpmToJson(ps, tmpFilepath) self.assertTrue(os.path.exists(tmpFilepath)) readBackData = json.load(open(tmpFilepath)) self.assertEqual(readBackData['foo'], 2) os.unlink(tmpFilepath)
def testSaveJson(self): ps = pipeBase.Struct(foo=2, bar=[10, 20], hard=np.array([5, 10])) _, tmpFilepath = tempfile.mkstemp(suffix='.json') saveKpmToJson(ps, tmpFilepath) self.assertTrue(os.path.exists(tmpFilepath)) # Here we get a dict back. readBackData = json.load(open(tmpFilepath)) self.assertEqual(readBackData['foo'], 2) os.unlink(tmpFilepath)
def testLoadJson(self): ps = pipeBase.Struct(foo=2, bar=[10, 20], hard=np.array([5, 10])) _, tmpFilepath = tempfile.mkstemp(suffix='.json') saveKpmToJson(ps, tmpFilepath) # Here we get a pipeBase.Struct back. readBackData = loadKpmFromJson(tmpFilepath) self.assertEqual(readBackData.foo, 2) self.assertEqual(readBackData.bar, [10, 20]) np.testing.assert_array_equal(readBackData.hard, np.array([5, 10])) os.unlink(tmpFilepath)