Ejemplo n.º 1
0
def test_write_plans_xml(tmp_path, population_heh):
    location = str(tmp_path / "test.xml")
    write_matsim_plans(population_heh, 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.v11_plans_dtd()
    assert dtd.validate(xml_obj), dtd.error_log.filter_from_errors()
Ejemplo n.º 2
0
def test_write_read_continuity_gzip(tmp_path, population_heh):
    plans_location = str(tmp_path / "test_plans.xml.gz")
    write_matsim_plans(population_heh, path=plans_location, comment="test")
    attributes_location = str(tmp_path / "test_attributes.xml.gz")
    write_matsim_attributes(population_heh, location=attributes_location, comment="test")
    population = read_matsim(
        plans_path=plans_location, attributes_path=attributes_location, household_key='hid'
    )
    assert population_heh['0']['1'].plan == population['0']['1'].plan
    assert population_heh == population
Ejemplo n.º 3
0
def test_write_plans_xml_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_plans(population, path=plans_location, comment="test")
    attributes_location = str(tmp_path / "test_attributes.xml")
    write_matsim_attributes(population, location=attributes_location, comment="test", household_key=None)
    new = read_matsim(
        plans_location,
        attributes_path=attributes_location,
        version=11
        )
    assert new == population
    assert new['a']['a'].attributes == {'1':'1'}
    assert new['a']['a'].plan.day[1].distance == 1000
Ejemplo n.º 4
0
def test_read_write_read_continuity_complex_xml(tmp_path):
    test_trips_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "test_data/test_matsim_plans.xml"))
    test_attributes_path = os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                        "test_data/test_matsim_attributes.xml"))
    population_in = read_matsim(test_trips_path, test_attributes_path)
    complex_plan_in = population_in['census_1']['census_1'].plan
    plans_location = str(tmp_path / "test_plans.xml")
    write_matsim_plans(population_in, path=plans_location, comment="test")
    attributes_location = str(tmp_path / "test_attributes.xml")
    write_matsim_attributes(population_in, location=attributes_location, comment="test")
    population_out = read_matsim(
        plans_path=plans_location, attributes_path=attributes_location, household_key='hid'
    )
    complex_plan_out = population_out['census_1']['census_1'].plan
    assert complex_plan_in == complex_plan_out
    assert population_in == population_out
Ejemplo n.º 5
0
def test_read_write_read_continuity_complex_xml(tmp_path):
    population_in = read_matsim(test_trips_path, test_attributes_path)
    complex_plan_in = population_in['census_1']['census_1'].plan

    plans_location = str(tmp_path / "test_plans.xml")
    write_matsim_plans(population_in, location=plans_location, comment="test")
    attributes_location = str(tmp_path / "test_attributes.xml")
    write_matsim_attributes(population_in,
                            location=attributes_location,
                            comment="test")

    population_out = read_matsim(plans_path=plans_location,
                                 attributes_path=attributes_location,
                                 household_key='hid')
    complex_plan_out = population_out['census_1']['census_1'].plan

    assert complex_plan_in == complex_plan_out
Ejemplo n.º 6
0
def test_write_plans_gzip(tmp_path, population_heh):
    location = str(tmp_path / "test.xml.gz")
    write_matsim_plans(population_heh, location=location, comment="test")

    expected_file = "{}/test.xml.gz".format(tmp_path)
    assert os.path.exists(expected_file)
Ejemplo n.º 7
0
def test_write_plans_xml(tmp_path, population_heh):
    location = str(tmp_path / "test.xml")
    write_matsim_plans(population_heh, location=location, comment="test")