def test_use_trips_freq_as_persons_and_hhs_freq_no_persons_attributes(trips): with pytest.raises(UserWarning): population = load_travel_diary(trips=trips, persons_attributes=None, hhs_attributes=None, trip_freq_as_hh_freq=True, trip_freq_as_person_freq=True)
def test_read_hhs_with_missing_persons_input_and_no_trips_hid( trips, persons_attributes, hhs_attributes): trips_ = trips.drop('hid', axis=1) with pytest.raises(UserWarning): population = load_travel_diary(trips=trips_, persons_attributes=None, hhs_attributes=hhs_attributes)
def test_use_trips_freq_as_persons_freq_no_persons_attributes(trips): population = load_travel_diary( trips=trips, persons_attributes=None, trip_freq_as_person_freq=True ) assert population[0][0].freq == 2
def test_agent_pid_12_not_start_and_return_home_night_worker_complex_chain_type1_intra_trip( test_trips, test_attributes ): population = load_travel_diary(test_trips, test_attributes) acts = [a.act for a in population.households['9'].people['12'].activities] print(acts) assert acts == ['work', 'shop', 'home', 'work']
def test_read_trips_and_persons_and_hhs_no_index(trips, persons_attributes, hhs_attributes): hhs_attributes_ = hhs_attributes.reset_index() population = load_travel_diary(trips=trips, persons_attributes=persons_attributes, hhs_attributes=hhs_attributes_) assert len(population) == 3
def test_read_trips_without_seq_fail_if_out_of_order(trips): trips = trips.drop('seq', axis=1).iloc[::-1] population = load_travel_diary( trips=trips ) with pytest.raises(PAMValidationLocationsError): population.validate()
def test_read_fail_with_bad_hhs_input(trips, persons_attributes, hhs_attributes): with pytest.raises(UserWarning): population = load_travel_diary( trips=trips, persons_attributes=persons_attributes, hhs_attributes=True )
def test_read_hhs_with_missing_persons_input(trips, persons_attributes, hhs_attributes): population = load_travel_diary( trips=trips, persons_attributes=None, hhs_attributes=hhs_attributes ) assert len(population) == 3
def test_read_trips_and_persons_and_hhs(trips, persons_attributes, hhs_attributes): population = load_travel_diary( trips=trips, persons_attributes=persons_attributes, hhs_attributes=hhs_attributes ) assert len(population) == 3
def test_read_trips_and_persons_and_hhs_from_paths(): population = load_travel_diary( trips=test_trips_path, persons_attributes=test_attributes_path, hhs_attributes=test_hhs_attributes_path ) assert len(population) == 23
def test_read_hh_weights_from_hhs(trips, persons_attributes, hhs_attributes): population = load_travel_diary( trips=trips, persons_attributes=persons_attributes, hhs_attributes=hhs_attributes ) assert population[0].freq == 1
def test_use_trips_freq_as_persons_freq_overwrite(trips, persons_attributes): population = load_travel_diary( trips=trips, persons_attributes=persons_attributes, trip_freq_as_person_freq=True ) assert population[0][0].freq == 2
def test_agent_pid_7_not_start_and_return_home_night_worker( test_trips, test_attributes): population = load_travel_diary(test_trips, test_attributes) person = population[4][7] person.print() print(person.home) acts = [a.act for a in population.households[4].people[7].activities] assert acts == ['work', 'home', 'work']
def test_read_hhs_with_missing_persons_input_and_no_trips_hid(trips, persons_attributes, hhs_attributes): trips = trips.drop('hid', axis=1) population = load_travel_diary( trips=trips, persons_attributes=None, hhs_attributes=hhs_attributes ) assert len(population) == 3 for hid, hh in population: assert len(hh.people) == 1 assert isinstance(hh[hid], Person)
def test_read_trips_without_seq(trips): trips_ = trips.drop('seq', axis=1) population = load_travel_diary( trips=trips_ ) population.validate()
def test_trip_based_encoding(trips): population = load_travel_diary(trips=trips, tour_based=False) assert len(population) == 3
def test_read_weights_from_trips(trips): population = load_travel_diary(trips=trips) assert population[1].freq == 6 assert population[1][2].freq == 6
def test_read_trips_from_path(): population = load_travel_diary(trips=test_trips_path) assert len(population) == 23
def test_trips_read_fail_with_no_pid_field(trips): trips_no_pid = trips.drop('pid', axis=1) with pytest.raises(UserWarning): population = load_travel_diary(trips=trips_no_pid)
def test_read_fail_with_no_trips_input(): with pytest.raises(UserWarning): population = load_travel_diary(trips=None)
def test_read_trips_only(trips): print(trips.describe()) print(trips.dtypes) population = load_travel_diary(trips=trips) assert len(population) == 3
def test_agent_pid_14_not_start_from_home_impossible_chain_type1_intra_trip( test_trips, test_attributes): population = load_travel_diary(test_trips, test_attributes) acts = [a.act for a in population.households[11].people[14].activities] assert acts == ['work', 'shop', 'home']
def test_read_trips_with_seq(trips): population = load_travel_diary( trips=trips ) population.validate()
def test_agent_pid_5_not_start_from_home(test_trips, test_attributes): population = load_travel_diary(test_trips, test_attributes) acts = [a.act for a in population.households[2].people[5].activities] assert acts == ['work', 'home']
def test_extra_person_stays_at_home(trips, extra_persons_attributes): population = load_travel_diary(trips=trips, persons_attributes=extra_persons_attributes) assert len(population[1][3].plan) == 1 assert population[1][3].plan.day[0].act == "home"
def test_agent_pid_6_not_return_home(test_trips, test_attributes): population = load_travel_diary(test_trips, test_attributes) acts = [a.act for a in population.households[3].people[6].activities] assert acts == ['home', 'work']
def test_persons_read_fail_with_no_pid_field(trips, persons_attributes): persons_no_pid = persons_attributes.reset_index().drop('pid', axis=1) with pytest.raises(UserWarning): population = load_travel_diary(trips=trips, persons_attributes=persons_no_pid)
def test_agent_pid_20_not_start_and_return_home_night_worker_complex_chain_type2_intra_trip_not_work( test_trips, test_attributes): population = load_travel_diary(test_trips, test_attributes) acts = [a.act for a in population.households[17].people[20].activities] assert acts == ['escort', 'shop', 'home', 'escort']
def test_act_based_encoding(activity_encoded_trips): population = load_travel_diary(trips=activity_encoded_trips) assert len(population) == 3
def test_persons_read_with_pid_not_as_index(trips, persons_attributes): persons_ = persons_attributes.reset_index() population = load_travel_diary(trips=trips, persons_attributes=persons_) assert len(population) == 3