def testRoundTripData(self): comp = fctutils.Compressor() comp.write("""hello=goodbye multiline=[ hello f**k mimsy ] parishioner=arse """) comp.close() data = comp.getvalue() full_input = "fish=wiggle\n" + data in_f = io.StringIO(full_input) fct = fctutils.ParamBag() fct.load(in_f) self.assertEqual("goodbye", fct.dict["hello"]) self.assertEqual("arse", fct.dict["parishioner"]) self.assertEqual("wiggle", fct.dict["fish"]) self.assertEqual("""hello f**k mimsy """, fct.dict["multiline"])
def save(self, file, update_saved_flag=True, **kwds): print("gnofract4d parameter file", file=file) print("version=%s" % THIS_FORMAT_VERSION, file=file) compress = kwds.get("compress", False) if compress is not False: # compress this file main_file = file file = fctutils.Compressor() for pair in zip(self.paramnames, self.params): print("%s=%.17f" % pair, file=file) print("maxiter=%d" % self.maxiter, file=file) print("yflip=%s" % self.yflip, file=file) print("periodicity=%s" % int(self.periodicity), file=file) print("period_tolerance=%.17f" % self.period_tolerance, file=file) self.forms[0].save_formula_params(file, self.warp_param) self.forms[1].save_formula_params(file) self.forms[2].save_formula_params(file) i = 0 for transform in self.transforms: transform.save_formula_params(file, None, i) i += 1 print("[colors]", file=file) print("colorizer=1", file=file) print("solids=[", file=file) for solid in self.solids: print("%02x%02x%02x%02x" % solid, file=file) print("]", file=file) print("[endsection]", file=file) if compress: file.close() print(file.getvalue(), file=main_file) if update_saved_flag: self.saved = True