def test_generates_matsim_vehicles_xml_file_containing_expected_vehicle_types(
        tmpdir, vehicle_types):
    vehicle_dict = {
        'veh_1': {
            'type': 'bus'
        },
        'veh_2': {
            'type': 'bus'
        },
        'veh_3': {
            'type': 'bus'
        },
        'veh_4': {
            'type': 'tram'
        },
        'veh_5': {
            'type': 'rail'
        },
        'veh_6': {
            'type': 'subway'
        }
    }
    matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict, vehicle_types)

    generated_file_path = os.path.join(tmpdir, 'vehicles.xml')
    xml_obj = lxml.etree.parse(generated_file_path)

    vehicle_types = xml_obj.findall(
        '{http://www.matsim.org/files/dtd}vehicleType')
    expected_vehicle_types = {v['type'] for k, v in vehicle_dict.items()}
    actual_vehicle_types = set()
    for vehicle_type in vehicle_types:
        actual_vehicle_types.add(vehicle_type.get('id'))
    assert expected_vehicle_types == actual_vehicle_types
def test_generates_matsim_vehicles_xml_file_containing_expected_vehicles(
        tmpdir, vehicle_types):
    vehicle_dict = {
        'veh_1': {
            'type': 'bus'
        },
        'veh_2': {
            'type': 'bus'
        },
        'veh_3': {
            'type': 'bus'
        },
        'veh_4': {
            'type': 'tram'
        },
        'veh_5': {
            'type': 'rail'
        },
        'veh_6': {
            'type': 'subway'
        }
    }
    matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict, vehicle_types)

    generated_file_path = os.path.join(tmpdir, 'vehicles.xml')
    xml_obj = lxml.etree.parse(generated_file_path)

    vehicles = xml_obj.findall('{http://www.matsim.org/files/dtd}vehicle')
    assert len(vehicles) == len(vehicle_dict)
    for vehicle in vehicles:
        assert vehicle_dict[vehicle.get('id')]['type'] == vehicle.get('type')
def test_generates_valid_matsim_vehicles_xml_file(tmpdir, vehicles_xsd,
                                                  vehicle_types):
    vehicle_dict = {
        'veh_1': {
            'type': 'bus'
        },
        'veh_2': {
            'type': 'bus'
        },
        'veh_3': {
            'type': 'bus'
        },
        'veh_4': {
            'type': 'tram'
        },
        'veh_5': {
            'type': 'rail'
        },
        'veh_6': {
            'type': 'subway'
        }
    }
    matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict, vehicle_types)

    generated_file_path = os.path.join(tmpdir, 'vehicles.xml')
    xml_obj = lxml.etree.parse(generated_file_path)
    vehicles_xsd.assertValid(xml_obj)
def test_throws_exception_when_generating_vehicles_xml_from_unrecognised_vehicle_types(
        tmpdir):
    vehicle_dict = {'veh_1': 'Bus', 'veh_4': 'Tram', 'veh_5': 'Rocket ship'}
    with pytest.raises(NotImplementedError) as e:
        matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict)
    assert 'No Vehicle Type info available for mode Rocket ship, you will need to add it to matsim_xml_values.py' \
           in str(e.value)
def test_write_matsim_vehicles_produces_semantically_equal_xml_to_input_matsim_xml(
        network_object_from_test_data, tmpdir):
    network = network_object_from_test_data
    matsim_xml_writer.write_matsim_schedule(tmpdir, network.schedule)
    matsim_xml_writer.write_vehicles(tmpdir, network.schedule.vehicles,
                                     network.schedule.vehicle_types)

    xml_diff.assert_semantically_equal(os.path.join(tmpdir, 'vehicles.xml'),
                                       pt2matsim_vehicles_file)
def test_generates_valid_matsim_vehicles_xml_file(tmpdir, vehicles_xsd):
    vehicle_dict = {
        'veh_1': 'Bus',
        'veh_2': 'Bus',
        'veh_3': 'Bus',
        'veh_4': 'Tram',
        'veh_5': 'Rail',
        'veh_6': 'Subway'
    }
    matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict)

    generated_file_path = os.path.join(tmpdir, 'vehicles.xml')
    xml_obj = lxml.etree.parse(generated_file_path)
    vehicles_xsd.assertValid(xml_obj)
def test_throws_exception_when_generating_vehicles_xml_from_unrecognised_vehicle_types(
        tmpdir, vehicle_types):
    vehicle_dict = {
        'veh_1': {
            'type': 'bus'
        },
        'veh_4': {
            'type': 'tram'
        },
        'veh_5': {
            'type': 'rocket ship'
        },
    }
    with pytest.raises(NotImplementedError) as e:
        matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict, vehicle_types)
    assert 'No Vehicle Type info available for mode rocket ship' in str(
        e.value)
def test_generates_matsim_vehicles_xml_file_containing_expected_vehicle_types(
        tmpdir):
    vehicle_dict = {
        'veh_1': 'Bus',
        'veh_2': 'Bus',
        'veh_3': 'Bus',
        'veh_4': 'Tram',
        'veh_5': 'Rail',
        'veh_6': 'Subway'
    }
    matsim_xml_writer.write_vehicles(tmpdir, vehicle_dict)

    generated_file_path = os.path.join(tmpdir, 'vehicles.xml')
    xml_obj = lxml.etree.parse(generated_file_path)

    vehicle_types = xml_obj.findall(
        '{http://www.matsim.org/files/dtd}vehicleType')
    expected_vehicle_types = set(vehicle_dict.values())
    actual_vehicle_types = set()
    for vehicle_type in vehicle_types:
        actual_vehicle_types.add(vehicle_type.get('id'))
    assert expected_vehicle_types == actual_vehicle_types
Esempio n. 9
0
 def write_to_matsim(self, output_dir):
     persistence.ensure_dir(output_dir)
     vehicles = matsim_xml_writer.write_matsim_schedule(output_dir, self)
     matsim_xml_writer.write_vehicles(output_dir, vehicles)