def test_reindex_population_duplicate_key(): pop = Population() for i in ['1', 'test_1']: hh = Household(i) pop.add(hh) for j in ['1', 'test_1']: hh.add(Person(j)) with pytest.raises(KeyError): pop.reindex("test_")
def test_reindex_population(): pop = Population() for i in ['1', '2']: hh = Household(i) pop.add(hh) for j in ['1', '2']: hh.add(Person(j)) pop.reindex("test_") assert set(pop.households) == {'test_1', 'test_2'} assert {hh.hid for hh in pop.households.values()} == {'test_1', 'test_2'} assert set(pop.households['test_1'].people) == {'test_1', 'test_2'} assert {p.pid for p in pop.households['test_1'].people.values() } == {'test_1', 'test_2'}