def test_write_matsim_xml_v12_gzip(tmp_path, population_heh): location = str(tmp_path / "test.xml.gz") write_matsim(population=population_heh, version=12, plans_path=location, comment="test") expected_file = "{}/test.xml.gz".format(tmp_path) assert os.path.exists(expected_file)
def test_write_matsim_xml_v12(tmp_path, population_heh): location = str(tmp_path / "test.xml") write_matsim(population=population_heh, version=12, plans_path=location, comment="test") expected_file = "{}/test.xml".format(tmp_path) assert os.path.exists(expected_file) xml_obj = lxml.etree.parse(expected_file) dtd = write.v12_plans_dtd() assert dtd.validate(xml_obj), dtd.error_log.filter_from_errors()
def test_write_plans_xml_v12_assert_contents(tmp_path): population = Population() hh = Household('a') p = Person('a', attributes={'1':'1'}) p.add(Activity( act="home", loc=Point((0,0)), start_time=datetime(1900,1,1,0,0,0), end_time=datetime(1900,1,1,8,0,0) )) p.add(Leg( mode='car', start_loc=Point((0,0)), end_loc=Point((0,1000)), start_time=datetime(1900,1,1,8,0,0), end_time=datetime(1900,1,1,9,0,0) )) p.add(Activity( act="work", loc=Point((0,1000)), start_time=datetime(1900,1,1,9,0,0), end_time=datetime(1900,1,1,18,0,0) )) p.add(Leg( mode='car', start_loc=Point((0,1000)), end_loc=Point((0,0)), start_time=datetime(1900,1,1,18,0,0), end_time=datetime(1900,1,1,19,0,0) )) p.add(Activity( act="home", loc=Point((0,0)), start_time=datetime(1900,1,1,19,0,0), end_time=END_OF_DAY )) hh.add(p) population.add(hh) plans_location = str(tmp_path / "test_plans.xml") write_matsim( population, plans_path=plans_location, comment="test", version=12, household_key=None ) new = read_matsim( plans_location, version=12 ) assert new == population assert new['a']['a'].attributes == {'1':'1'} assert new['a']['a'].plan.day[1].distance == 1000
def test_read_write_v12_consistent(tmp_path): test_tripsv12_path = os.path.abspath( os.path.join(os.path.dirname(__file__), "test_data/test_matsim_plansv12.xml")) population = read_matsim(test_tripsv12_path, version=12) location = str(tmp_path / "test.xml.gz") write_matsim( population=population, version=12, plans_path=location, comment="test", household_key=None, ) expected_file = "{}/test.xml.gz".format(tmp_path) population2 = read_matsim(expected_file, version=12) assert population == population2