Skip to content

Commit

Permalink
#72 Update location module
Browse files Browse the repository at this point in the history
  • Loading branch information
astropenguin committed Jan 20, 2024
1 parent 470171a commit b99235d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
14 changes: 7 additions & 7 deletions azely/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


# dependencies
from astropy.coordinates import EarthLocation, Latitude, Longitude
from astropy.coordinates import Angle, EarthLocation, Latitude, Longitude
from astropy.units import Quantity
from astropy.utils.data import conf
from ipinfo import getHandler
Expand All @@ -27,13 +27,13 @@ class Location:
"""Name of the location."""

longitude: str
"""Longitude of the location."""
"""Longitude of the location with units."""

latitude: str
"""Latitude of the location."""
"""Latitude of the location with units."""

altitude: str = "0.0 m"
"""Altitude of the location."""
altitude: str = "0m"
"""Altitude of the location with units."""

tf: ClassVar = TimezoneFinder()
"""TimezoneFinder instance."""
Expand Down Expand Up @@ -108,8 +108,8 @@ def get_location_by_ip(

return Location(
name=response.city,
longitude=response.longitude,
latitude=response.latitude,
longitude=str(Angle(response.longitude, "deg")),
latitude=str(Angle(response.latitude, "deg")),
)


Expand Down
24 changes: 6 additions & 18 deletions tests/test_location.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,32 @@
# standard library
from dataclasses import asdict
from tempfile import NamedTemporaryFile


# dependencies
from azely.location import Location, get_location
from pytest import mark
from tomlkit import dump


# test data
locations = [
Location(
name="Atacama Large Millimeter/submillimeter Array",
longitude="292d14m48.93972s",
longitude="-67d45m11.06028s",
latitude="-23d01m21.97704s",
altitude="0.0 m",
altitude="0m",
),
Location(
name="Gran Telescopio Milimétrico Alfonso Serrano",
longitude="262d41m06.76068s",
longitude="-97d18m53.23932s",
latitude="18d59m08.66328s",
altitude="0.0 m",
altitude="0m",
),
Location(
name="Nobeyama Radio Astronomy Observatory",
longitude="138d28m25.28621699s",
latitude="35d56m34.76364s",
altitude="0.0 m",
altitude="0m",
),
]


# test functions
@mark.parametrize("obj", locations)
def test_get_location(obj: Location) -> None:
with NamedTemporaryFile("w", suffix=".toml") as f:
dump({obj.name: asdict(obj)}, f)

# save an object to the TOML file
assert get_location(obj.name, source=f.name) == obj
# read the object from the TOML file
assert get_location(obj.name, source=f.name) == obj
assert get_location(obj.name, source=None) == obj

0 comments on commit b99235d

Please sign in to comment.