def test_floor_example_from_dan_harasty(): # See blog post comment for details of this example gridref = bng.from_osgb36((529900, 199900), nDigits=4) assert gridref == 'TQ2999'
def test_from_osbg36_single_example(): gridref = bng.from_osgb36((327550, 672950)) assert gridref == 'NT275729'
def test_from_osbg36_zipped_example(): x = [443143, 363723, 537395] y = [1139158, 356004, 35394] xy = zip(x, y) gridrefs = bng.from_osgb36(xy, nDigits=4) assert gridrefs == ['HU4339', 'SJ6356', 'TV3735']
def test_from_osgb36_throws_bng_error_on_bad_figs_value(figs): with pytest.raises(bng.BNGError, match=r'Valid inputs for figs are .*'): bng.from_osgb36((123456, 123456), figs=figs)
def test_from_osgb36_throws_bng_error_on_coords_out_of_range(coords): with pytest.raises(bng.BNGError, match=r'Coordinate location outside .*'): bng.from_osgb36(coords)
def test_from_osgb36_throws_bng_error_on_bad_coords_type(coords): with pytest.raises(bng.BNGError, match=r'Valid inputs are .*'): bng.from_osgb36(coords)
def test_from_osgb36_selects_correct_square(x, y, expected): gridref = bng.from_osgb36((x, y), figs=4) assert gridref == expected
def test_from_osgb36_rounds_figs_down(x, y, figs, expected): gridref = bng.from_osgb36((x, y), figs=figs) assert gridref == expected