def test_get_areas_accepts_lists(): areas_from_list = broadcast_area_libraries.get_areas([ 'ctry19-W92000004', 'ctry19-E92000001', ]) areas_from_args = broadcast_area_libraries.get_areas( 'ctry19-W92000004', 'ctry19-E92000001', ) assert len(areas_from_args) == len(areas_from_list) == 2 assert areas_from_args == areas_from_list
def test_has_polygons(): england = broadcast_area_libraries.get_areas('ctry19-E92000001')[0] scotland = broadcast_area_libraries.get_areas('ctry19-S92000003')[0] assert len(england.polygons) == 35 assert len(scotland.polygons) == 195 assert england.polygons.as_coordinate_pairs_lat_long[0][0] == [ 55.811085, -2.034358 # https://goo.gl/maps/wsf2LUWzYinwydMk8 ]
def test_estimated_bleed( area, expected_bleed_in_m, expected_bleed_in_degrees, ): assert close_enough( broadcast_area_libraries.get_areas(area)[0].estimated_bleed_in_m, expected_bleed_in_m, ) assert close_enough( broadcast_area_libraries.get_areas(area)[0].estimated_bleed_in_degrees, expected_bleed_in_degrees, )
def test_phone_density( area, expected_phones_per_square_mile, ): assert close_enough( broadcast_area_libraries.get_areas(area)[0].phone_density, expected_phones_per_square_mile, )
def test_get_names_of_areas(): areas = broadcast_area_libraries.get_areas( 'ctry19-W92000004', 'lad20-W06000014', 'ctry19-E92000001', ) assert [area.name for area in sorted(areas)] == [ 'England', 'Vale of Glamorgan', 'Wales', ]
def test_lat_long_order(): england = broadcast_area_libraries.get_areas('ctry19-E92000001')[0] lat_long = england.polygons.as_coordinate_pairs_lat_long long_lat = england.polygons.as_coordinate_pairs_long_lat assert len(lat_long[0]) == len(long_lat[0]) == 2082 # Coordinates in polygon assert len(lat_long[0][0]) == len(long_lat[0][0]) == 2 # Axes in coordinates assert lat_long[0][0] == list(reversed(long_lat[0][0]))
def test_city_of_london_counts_are_not_derived_from_population(): city_of_london = broadcast_area_libraries.get_areas('lad20-E09000001')[0] assert city_of_london.name == 'City of London' assert len(city_of_london.sub_areas) == len(CITY_OF_LONDON.WARDS) == 25 for ward in city_of_london.sub_areas: # The population of the whole City of London is 9,401, so an # average of 300 per ward. What we’re asserting here is that the # count of phones is much larger, because it isn’t derived from # the resident population. assert ward.count_of_phones > 5_000
def test_loads_areas_from_libraries(id): assert ( broadcast_area_libraries.get('ctry19').get(id) ) == ( broadcast_area_libraries.get_areas(id)[0] )
def test_count_of_phones_for_all_levels(area_id, area_name, expected_count): area = broadcast_area_libraries.get_areas(area_id)[0] assert area.name == area_name assert area.count_of_phones == expected_count
def test_electoral_wards_are_groupable_ealing(): areas = broadcast_area_libraries.get_areas(['lad20-E09000009']) assert len(areas) == 1 ealing = areas[0] assert len(ealing.sub_areas) == 23
def test_electoral_wards_are_groupable_cardiff(): areas = broadcast_area_libraries.get_areas(['lad20-W06000015']) assert len(areas) == 1 cardiff = areas[0] assert len(cardiff.sub_areas) == 29
def test_includes_electoral_wards(): areas = broadcast_area_libraries.get_areas(['wd20-E05009289']) assert len(areas) == 1
def get_areas(self, areas): return broadcast_area_libraries.get_areas(*areas)