def test_parsers(self): # populate a property tree from an input file ptree = PropertyTree() # INFO parser info_file = 'input.info' today = 'april 8th, 2016' with open(info_file, 'w') as fout: fout.write('date "' + today + '"') ptree.parse_info(info_file) self.assertEqual(ptree.get_string('date'), today) remove(info_file) # XML parser xml_file = 'input.xml' pi = 3.14 with open(xml_file, 'w') as fout: fout.write('<pi>' + str(pi) + '</pi>') ptree.parse_xml(xml_file) self.assertEqual(ptree.get_double('pi'), pi) remove(xml_file) # JSON parser json_file = 'input.json' with open(json_file, 'w') as fout: fout.write('{') fout.write(' "foo":') fout.write(' {') fout.write(' "bar": false') fout.write(' }') fout.write('}') ptree.parse_json(json_file) self.assertFalse(ptree.get_bool('foo.bar')) remove(json_file)
def test_property_tree(self): # ptree as container to store int, double, string, and bool ptree = PropertyTree() ptree.put_int('dim', 3) self.assertEqual(ptree.get_int('dim'), 3) ptree.put_double('path.to.pi', 3.14) self.assertEqual(ptree.get_double('path.to.pi'), 3.14) ptree.put_string('good.news', 'it works') self.assertEqual(ptree.get_string('good.news'), 'it works') ptree.put_bool('is.that.a.good.idea', False) self.assertEqual(ptree.get_bool('is.that.a.good.idea'), False)