# Path: upoints/tzdata.py
# class Zone(point.Point):
#     """Class for representing timezone descriptions from zoneinfo data.
# 
#     .. versionadded:: 0.6.0
#     """
# 
#     def __init__(self, location, country, zone, comments=None):
#         """Initialise a new ``Zone`` object.
# 
#         Args:
#             location (str): Primary location in |ISO|-6709 format
#             country (str): Location’s |ISO|-3166 country code
#             zone (str): Location’s zone name as used in zoneinfo database
#             comments (list): Location’s alternate names
#         """
#         latitude, longitude = utils.from_iso6709(location + '/')[:2]
#         super(Zone, self).__init__(latitude, longitude)
# 
#         self.country = country
#         self.zone = zone
#         self.comments = comments
# 
#     def __repr__(self):
#         """Self-documenting string representation.
# 
#         Returns:
#             str: String to recreate ``Zone`` object
#         """
#         location = utils.to_iso6709(
#             self.latitude, self.longitude, format='dms'
#         )[:-1]
#         return utils.repr_assist(self, {'location': location})
# 
#     def __str__(self):
#         """Pretty printed location string.
# 
#         Args:
#             mode (str): Coordinate formatting system to use
# 
#         Returns:
#             str: Human readable string representation of ``Zone`` object
#         """
#         text = [
#             '%s (%s: %s'
#             % (self.zone, self.country, super(Zone, self).__format__('dms')),
#         ]
#         if self.comments:
#             text.append(' also ' + ', '.join(self.comments))
#         text.append(')')
#         return ''.join(text)
# 
# class Zones(point.Points):
#     """Class for representing a group of :class:`Zone` objects.
# 
#     .. versionadded:: 0.6.0
#     """
# 
#     def __init__(self, zone_file=None):
#         """Initialise a new Zones object."""
#         super(Zones, self).__init__()
#         self._zone_file = zone_file
#         if zone_file:
#             self.import_locations(zone_file)
# 
#     def import_locations(self, zone_file):
#         """Parse zoneinfo zone description data files.
# 
#         ``import_locations()`` returns a list of :class:`Zone` objects.
# 
#         It expects data files in one of the following formats::
# 
#             AN	+1211-06900	America/Curacao
#             AO	-0848+01314	Africa/Luanda
#             AQ	-7750+16636	Antarctica/McMurdo	McMurdo Station, Ross Island
# 
#         Files containing the data in this format can be found in the
#         :file:`zone.tab` file that is normally found in
#         :file:`/usr/share/zoneinfo` on UNIX-like systems, or from the `standard
#         distribution site`_.
# 
#         When processed by ``import_locations()`` a ``list`` object of the
#         following style will be returned::
# 
#             [Zone(None, None, 'AN', 'America/Curacao', None),
#              Zone(None, None, 'AO', 'Africa/Luanda', None),
#              Zone(None, None, 'AO', 'Antartica/McMurdo',
#                   ['McMurdo Station', 'Ross Island'])]
# 
#         Args:
#             zone_file (iter): ``zone.tab`` data to read
# 
#         Returns:
#             list: Locations as :class:`Zone` objects
# 
#         Raises:
#             FileFormatError: Unknown file format
# 
#         .. _standard distribution site: ftp://elsie.nci.nih.gov/pub/
#         """
#         self._zone_file = zone_file
#         field_names = ('country', 'location', 'zone', 'comments')
# 
#         data = utils.prepare_csv_read(zone_file, field_names, delimiter=r'	')
# 
#         for row in (x for x in data if not x['country'].startswith('#')):
#             if row['comments']:
#                 row['comments'] = row['comments'].split(', ')
#             self.append(Zone(**row))
# 
#     def dump_zone_file(self):
#         """Generate a zoneinfo compatible zone description table.
# 
#         Returns:
#             list: zoneinfo descriptions
#         """
#         data = []
#         for zone in sorted(self, key=attrgetter('country')):
#             text = [
#                 '%s	%s	%s'
#                 % (
#                     zone.country,
#                     utils.to_iso6709(
#                         zone.latitude, zone.longitude, format='dms'
#                     )[:-1],
#                     zone.zone,
#                 ),
#             ]
#             if zone.comments:
#                 text.append('	%s' % ', '.join(zone.comments))
#             data.append(''.join(text))
#         return data


from operator import attrgetter
from pytest import mark
from upoints.tzdata import Zone, Zones
                (
                    '+0658-15813',
                    'FM',
                    'Pacific/Ponape',
                    [
                        'Ponape (Pohnpei)',
                    ],
                ),
                """Pacific/Ponape (FM: 06°58′00″N, 158°13′00″W also Ponape (Pohnpei))""",
            ),
        ],
    )
    def test___str__(self, args, result):
        assert str(Zone(*args)) == result


class TestZones:
    def setup(self):
        with open('tests/data/timezones') as f:
            self.zones = Zones(f)

    def test_import_locations(self):
        data = [str(v) for v in sorted(self.zones, key=attrgetter('zone'))]
        assert data == [
            """Africa/Luanda (AO: 08°48′00″S, 013°14′00″E)""",
            """America/Curacao (AN: 12°11′00″N, 069°00′00″W)""",
            """Antarctica/McMurdo (AQ: 77°50′00″S, 166°36′00″E also McMurdo Station, Ross Island)""",
        ]

    def test_dump_zone_file(self):

# Path: upoints/tzdata.py
# class Zone(point.Point):
#     """Class for representing timezone descriptions from zoneinfo data.
# 
#     .. versionadded:: 0.6.0
#     """
# 
#     def __init__(self, location, country, zone, comments=None):
#         """Initialise a new ``Zone`` object.
# 
#         Args:
#             location (str): Primary location in |ISO|-6709 format
#             country (str): Location’s |ISO|-3166 country code
#             zone (str): Location’s zone name as used in zoneinfo database
#             comments (list): Location’s alternate names
#         """
#         latitude, longitude = utils.from_iso6709(location + '/')[:2]
#         super(Zone, self).__init__(latitude, longitude)
# 
#         self.country = country
#         self.zone = zone
#         self.comments = comments
# 
#     def __repr__(self):
#         """Self-documenting string representation.
# 
#         Returns:
#             str: String to recreate ``Zone`` object
#         """
#         location = utils.to_iso6709(
#             self.latitude, self.longitude, format='dms'
#         )[:-1]
#         return utils.repr_assist(self, {'location': location})
# 
#     def __str__(self):
#         """Pretty printed location string.
# 
#         Args:
#             mode (str): Coordinate formatting system to use
# 
#         Returns:
#             str: Human readable string representation of ``Zone`` object
#         """
#         text = [
#             '%s (%s: %s'
#             % (self.zone, self.country, super(Zone, self).__format__('dms')),
#         ]
#         if self.comments:
#             text.append(' also ' + ', '.join(self.comments))
#         text.append(')')
#         return ''.join(text)
# 
# class Zones(point.Points):
#     """Class for representing a group of :class:`Zone` objects.
# 
#     .. versionadded:: 0.6.0
#     """
# 
#     def __init__(self, zone_file=None):
#         """Initialise a new Zones object."""
#         super(Zones, self).__init__()
#         self._zone_file = zone_file
#         if zone_file:
#             self.import_locations(zone_file)
# 
#     def import_locations(self, zone_file):
#         """Parse zoneinfo zone description data files.
# 
#         ``import_locations()`` returns a list of :class:`Zone` objects.
# 
#         It expects data files in one of the following formats::
# 
#             AN	+1211-06900	America/Curacao
#             AO	-0848+01314	Africa/Luanda
#             AQ	-7750+16636	Antarctica/McMurdo	McMurdo Station, Ross Island
# 
#         Files containing the data in this format can be found in the
#         :file:`zone.tab` file that is normally found in
#         :file:`/usr/share/zoneinfo` on UNIX-like systems, or from the `standard
#         distribution site`_.
# 
#         When processed by ``import_locations()`` a ``list`` object of the
#         following style will be returned::
# 
#             [Zone(None, None, 'AN', 'America/Curacao', None),
#              Zone(None, None, 'AO', 'Africa/Luanda', None),
#              Zone(None, None, 'AO', 'Antartica/McMurdo',
#                   ['McMurdo Station', 'Ross Island'])]
# 
#         Args:
#             zone_file (iter): ``zone.tab`` data to read
# 
#         Returns:
#             list: Locations as :class:`Zone` objects
# 
#         Raises:
#             FileFormatError: Unknown file format
# 
#         .. _standard distribution site: ftp://elsie.nci.nih.gov/pub/
#         """
#         self._zone_file = zone_file
#         field_names = ('country', 'location', 'zone', 'comments')
# 
#         data = utils.prepare_csv_read(zone_file, field_names, delimiter=r'	')
# 
#         for row in (x for x in data if not x['country'].startswith('#')):
#             if row['comments']:
#                 row['comments'] = row['comments'].split(', ')
#             self.append(Zone(**row))
# 
#     def dump_zone_file(self):
#         """Generate a zoneinfo compatible zone description table.
# 
#         Returns:
#             list: zoneinfo descriptions
#         """
#         data = []
#         for zone in sorted(self, key=attrgetter('country')):
#             text = [
#                 '%s	%s	%s'
#                 % (
#                     zone.country,
#                     utils.to_iso6709(
#                         zone.latitude, zone.longitude, format='dms'
#                     )[:-1],
#                     zone.zone,
#                 ),
#             ]
#             if zone.comments:
#                 text.append('	%s' % ', '.join(zone.comments))
#             data.append(''.join(text))
#         return data


# Path: tests/test_tzdata.py
from operator import attrgetter
from pytest import mark
from upoints.tzdata import Zone, Zones

                (
                    '+0658-15813',
                    'FM',
                    'Pacific/Ponape',
                    [
                        'Ponape (Pohnpei)',
                    ],
                ),
                """Pacific/Ponape (FM: 06°58′00″N, 158°13′00″W also Ponape (Pohnpei))""",
            ),
        ],
    )
    def test___str__(self, args, result):
        assert str(Zone(*args)) == result


class TestZones:
    def setup(self):
        with open('tests/data/timezones') as f:
            self.zones = Zones(f)

    def test_import_locations(self):
        data = [str(v) for v in sorted(self.zones, key=attrgetter('zone'))]
        assert data == [
            """Africa/Luanda (AO: 08°48′00″S, 013°14′00″E)""",
            """America/Curacao (AN: 12°11′00″N, 069°00′00″W)""",
            """Antarctica/McMurdo (AQ: 77°50′00″S, 166°36′00″E also McMurdo Station, Ross Island)""",
        ]

    def test_dump_zone_file(self):

        assert Zones.dump_zone_file(self.zones) == [