Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions tests/fixtures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,3 @@ def _make_euring2000plus_record_with_invalid_species(*, accuracy_of_coordinates:
species_mentioned="12ABC",
species_concluded="12ABC",
)


def _make_euring2020_record_for_coords(**kwargs) -> str:
return _make_euring2020_record(**kwargs)


def _make_euring2020_record_with_coords() -> str:
return _make_euring2020_record(
geographical_coordinates="." * 15,
accuracy_of_coordinates="A",
latitude="52.3760",
longitude="4.9000",
)
25 changes: 18 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
import euring.main as main_module
from euring import exceptions as euring_exceptions
from euring.coordinates import _lat_to_euring_coordinate, _lng_to_euring_coordinate
from euring.fields import EURING_FIELDS
from euring.fields import EURING_KEY_INDEX
from euring.main import app
from tests.fixtures import _make_euring2000plus_record_with_invalid_species, _make_euring2020_record_with_coords
from tests.fixtures import (
_make_euring2000plus_record_with_invalid_species,
_make_euring2020_record,
)


def test_lookup_place_verbose_includes_details():
Expand Down Expand Up @@ -59,7 +62,7 @@ def test_decode_cli_success():

def test_decode_cli_format_mismatch_fails():
runner = CliRunner()
record = _make_euring2020_record_with_coords()
record = _make_euring2020_record()
result = runner.invoke(app, ["decode", "--format", "euring2000", record])
assert result.exit_code == 1
assert 'Format "EURING2000" conflicts with pipe-delimited data.' in result.output
Expand Down Expand Up @@ -157,7 +160,7 @@ def test_validate_cli_invalid_format_hint():
def test_validate_cli_forced_euring2000_rejects_pipe_record():
import json

record = _make_euring2020_record_with_coords()
record = _make_euring2020_record()
runner = CliRunner()
result = runner.invoke(app, ["validate", "--json", "--format", "euring2000", record])
assert result.exit_code == 1
Expand Down Expand Up @@ -493,6 +496,12 @@ def test_convert_cli_downgrade_with_coords():
runner = CliRunner()
lat = _lat_to_euring_coordinate(52.3760)
lng = _lng_to_euring_coordinate(4.9000)
euring2020_record_with_coordinates = _make_euring2020_record(
geographical_coordinates="." * 15,
accuracy_of_coordinates="A",
latitude="52.3760",
longitude="4.9000",
)
result = runner.invoke(
app,
[
Expand All @@ -502,10 +511,12 @@ def test_convert_cli_downgrade_with_coords():
"--to",
"euring2000plus",
"--force",
_make_euring2020_record_with_coords(),
euring2020_record_with_coordinates,
],
)
assert result.exit_code == 0
fields = result.output.strip().split("|")
geo_index = next(i for i, f in enumerate(EURING_FIELDS) if f["key"] == "geographical_coordinates")
assert fields[geo_index] == f"{lat}{lng}"
accuracy_of_coordinates = fields[EURING_KEY_INDEX["accuracy_of_coordinates"]]
assert accuracy_of_coordinates == "0" # Changed from 'A' to '0'
geographical_coordinates = fields[EURING_KEY_INDEX["geographical_coordinates"]]
assert geographical_coordinates == f"{lat}{lng}" # Generated from latitude and longitude
9 changes: 7 additions & 2 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from euring.converters import convert_euring_record
from euring.coordinates import _lat_to_euring_coordinate, _lng_to_euring_coordinate
from euring.fields import EURING_FIELDS
from tests.fixtures import _make_euring2020_record_with_coords
from tests.fixtures import _make_euring2020_record


def _load_fixture(module_name: str, attr: str) -> str:
Expand Down Expand Up @@ -98,7 +98,12 @@ def test_convert_alpha_accuracy_invalid():


def test_convert_coordinate_downgrade_fills():
record = _make_euring2020_record_with_coords()
record = _make_euring2020_record(
geographical_coordinates="." * 15,
accuracy_of_coordinates="A",
latitude="52.3760",
longitude="4.9000",
)
lat = _lat_to_euring_coordinate(52.3760)
lng = _lng_to_euring_coordinate(4.9000)
converted = convert_euring_record(record, target_format="euring2000plus", force=True)
Expand Down
14 changes: 7 additions & 7 deletions tests/test_decoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from tests.fixtures import (
_make_euring2000plus_record,
_make_euring2000plus_record_with_invalid_species,
_make_euring2020_record_for_coords,
_make_euring2020_record,
)


Expand Down Expand Up @@ -203,7 +203,7 @@ def test_decode_invalid_species_format(self):

def test_decode_euring2020_rejects_geo_with_lat_long(self):
record = EuringRecord.decode(
_make_euring2020_record_for_coords(
_make_euring2020_record(
geographical_coordinates="+0000000+0000000",
latitude="1.0000",
longitude="2.0000",
Expand All @@ -213,7 +213,7 @@ def test_decode_euring2020_rejects_geo_with_lat_long(self):

def test_decode_euring2020_requires_longitude_with_latitude(self):
record = EuringRecord.decode(
_make_euring2020_record_for_coords(
_make_euring2020_record(
geographical_coordinates="...............",
latitude="1.0000",
longitude="",
Expand All @@ -223,7 +223,7 @@ def test_decode_euring2020_requires_longitude_with_latitude(self):

def test_decode_euring2020_requires_latitude_with_longitude(self):
record = EuringRecord.decode(
_make_euring2020_record_for_coords(
_make_euring2020_record(
geographical_coordinates="...............",
latitude="",
longitude="2.0000",
Expand All @@ -233,7 +233,7 @@ def test_decode_euring2020_requires_latitude_with_longitude(self):

def test_decode_euring2020_latitude_out_of_range(self):
record = EuringRecord.decode(
_make_euring2020_record_for_coords(
_make_euring2020_record(
geographical_coordinates="...............",
latitude="90.0001",
longitude="2.0000",
Expand All @@ -243,7 +243,7 @@ def test_decode_euring2020_latitude_out_of_range(self):

def test_decode_euring2020_longitude_out_of_range(self):
record = EuringRecord.decode(
_make_euring2020_record_for_coords(
_make_euring2020_record(
geographical_coordinates="...............",
latitude="10.0000",
longitude="180.0001",
Expand All @@ -253,7 +253,7 @@ def test_decode_euring2020_longitude_out_of_range(self):

def test_decode_euring2020_latitude_too_many_decimals(self):
record = EuringRecord.decode(
_make_euring2020_record_for_coords(
_make_euring2020_record(
geographical_coordinates="...............",
latitude="10.00001",
longitude="2.0000",
Expand Down