Added __str__ to place
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
""" version info """
|
||||
|
||||
__version__ = "0.23.1"
|
||||
__version__ = "0.23.2"
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
Provides reverse geolocation info for photos
|
||||
"""
|
||||
from abc import ABC, abstractmethod
|
||||
from collections import namedtuple
|
||||
from collections import namedtuple # pylint: disable=syntax-error
|
||||
|
||||
import yaml
|
||||
from bpylist import archiver
|
||||
|
||||
# postal address information, returned by PlaceInfo.address
|
||||
@@ -362,6 +363,15 @@ class PlaceInfo4(PlaceInfo):
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __str__(self):
|
||||
info = {
|
||||
"name": self.name,
|
||||
"names": self.names,
|
||||
"country_code": self.country_code,
|
||||
}
|
||||
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
|
||||
return strval
|
||||
|
||||
|
||||
class PlaceInfo5(PlaceInfo):
|
||||
""" Reverse geolocation place info for a photo (Photos >= 5) """
|
||||
@@ -431,3 +441,15 @@ class PlaceInfo5(PlaceInfo):
|
||||
|
||||
def __ne__(self, other):
|
||||
return not self.__eq__(other)
|
||||
|
||||
def __str__(self):
|
||||
info = {
|
||||
"name": self.name,
|
||||
"names": self.names,
|
||||
"country_code": self.country_code,
|
||||
"ishome": self.ishome,
|
||||
"address_str": self.address_str,
|
||||
"address": str(self.address),
|
||||
}
|
||||
strval = "PlaceInfo(" + ", ".join([f"{k}='{v}'" for k, v in info.items()]) + ")"
|
||||
return strval
|
||||
|
||||
@@ -92,3 +92,16 @@ def test_place_no_place_info():
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["no_place"]])[0]
|
||||
|
||||
assert photo.place is None
|
||||
|
||||
|
||||
def test_place_str():
|
||||
# test __str__
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_dc"]])[0]
|
||||
|
||||
assert (
|
||||
str(photo.place)
|
||||
== "PlaceInfo(name='2038 18th St NW', names='['2038 18th St NW', 'Adams Morgan', 'Washington', 'Washington', 'Washington', 'District of Columbia', 'United States']', country_code='US', ishome='False', address_str='2038 18th St NW, Washington, DC 20009, United States', address='PostalAddress(street='2038 18th St NW', sub_locality='Adams Morgan', city='Washington', sub_administrative_area=None, state='DC', postal_code='20009', country='United States', iso_country_code='US')')"
|
||||
)
|
||||
|
||||
@@ -45,3 +45,15 @@ def test_place_no_place_info():
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["no_place"]])[0]
|
||||
|
||||
assert photo.place is None
|
||||
|
||||
|
||||
def test_place_str():
|
||||
# test __str__
|
||||
import osxphotos
|
||||
|
||||
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
|
||||
photo = photosdb.photos(uuid=[UUID_DICT["place_uk"]])[0]
|
||||
assert (
|
||||
str(photo.place)
|
||||
== "PlaceInfo(name='St James's Park', names='[\"St James's Park\", 'Westminster', 'London', 'England', 'United Kingdom']', country_code='GB')"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user