Ejemplo n.º 1
0
 def test_dump_to_json_file(self):
     RS = ResultsStructure()
     tmpfile = gf.generate_temp_file(extension='json')
     results = {'model': 4, 'data': np.random.random_sample(size=(1000, 2))}
     RS.save_json_object(results=results, filename=tmpfile)
     retres = RS.load_json_object(filename=tmpfile)
     self.assertEqual(retres['model'],
                      results['model'],
                      msg='Model set to 4')
     self.assertTrue(np.array_equal(retres['data'], results['data']),
                     msg='Arrays should be equal')
     os.remove(tmpfile)
Ejemplo n.º 2
0
 def test_load_ser_sim_res(self):
     tmpfolder = gf.generate_temp_folder()
     tmpfolder0 = os.path.join(tmpfolder, 'chain_0')
     os.makedirs(tmpfolder0)
     tmpfile0 = 'chain_0.json'
     tmpfile0 = os.path.join(tmpfolder0, tmpfile0)
     results = dict(a=[0, 1], b='hello')
     RS = ResultsStructure()
     RS.save_json_object(results, tmpfile0)
     pres = CP.load_serial_simulation_results(tmpfolder0)
     shutil.rmtree(tmpfolder)
     self.assertTrue(isinstance(pres['a'], np.ndarray))
     self.assertTrue(isinstance(pres['b'], str))
     self.assertEqual(pres['b'], 'hello')