def test_GeoBoundary_init_error_overflow(): """verify GeoBoundary raises when exceeding the maximum boundaries (10)""" coord_values = zip(np.random.random(11) * np.pi, np.random.random(11) * np.pi) geo_coords = [GeoCoord(lat, lon) for lat, lon in coord_values] with pytest.raises(ValueError): GeoBoundary(geo_coords)
def test_GeoBoundary_init_error_on_str(coord_values): """test GeoBoundary raises when getting input type 'str'""" geo_coords = [GeoCoord(lat, lon) for lat, lon in coord_values] geo_coords.insert(4, 'mittens') with pytest.raises(TypeError): GeoBoundary(geo_coords)
def test_to_boundary(): "bc*cells.txt" test_files = glob(os.path.join('tests', 'inputfiles', 'bc*cells.txt')) for file in test_files: test = open(file, 'rt') it = iter(test) while True: try: h3str = next(it) except StopIteration: test.close() break h3 = H3Index.from_string(h3str) assert next(it).startswith('{'), file coordinates = [] while True: line = next(it) if line.startswith('}'): break lat, lon = map(float, line.split()) coordinates.append(GeoCoord.from_degrees(lat, lon)) b1 = h3.to_boundary() b2 = GeoBoundary(coordinates) assert b1 == b2
def test_GeoBoundary_raises_generator(coord_values): """verify GeoBoundary won't accept a generator""" with pytest.raises(TypeError): GeoBoundary(GeoCoord(lat, lon) for lat, lon in coord_values)
def test_GeoBoundary_raises_tuple(coord_values): """verify GeoBoundary won't accept a tuple""" geo_coords = tuple(GeoCoord(lat, lon) for lat, lon in coord_values) with pytest.raises(TypeError): GeoBoundary(geo_coords)
def test_GeoBoundary_init_error_on_float(coord_values): """test GeoBoundary raises when getting input type 'float'""" geo_coords = [5.4] + [GeoCoord(lat, lon) for lat, lon in coord_values] with pytest.raises(TypeError): GeoBoundary(geo_coords)