# -*- coding: utf-8 -*-
import pytz
from pytest import raises, approx

from astral.geocoder import Geocoder, lookup


def test_Lookup():
    l = lookup("London")
    assert l.name == "London"
    assert l.region == "England"
    assert approx(l.latitude, 51.5)
    assert approx(l.longitude, -0.166)
    tz = pytz.timezone("Europe/London")
    tzl = pytz.timezone(l.timezone)
    assert tz == tzl
    assert l.elevation == 24


def test_Group():
    db = Geocoder()
    _e = db.europe


def test_UnknownGroup():
    with raises(AttributeError):
        db = Geocoder()
        _e = db.wallyland


def test_CityContainment():
    db = Geocoder()
    assert "london" in db


def test_GroupContainment():
    db = Geocoder()
    assert "africa" in db


def test_CityCountry():
    city_name = "Birmingham,England"

    db = Geocoder()
    city = db[city_name]
    assert city.name == "Birmingham"
    assert city.region == "England"


def test_MultiCountry():
    db = Geocoder()
    city = db["Abu Dhabi"]
    assert city.name == "Abu Dhabi"


def test_MultiCountryWithCountry():
    """Test for fix made due to bug report from Klaus Alexander Seistrup"""

    db = Geocoder()
    city = db["Abu Dhabi,United Arab Emirates"]
    assert city.name == "Abu Dhabi"

    city = db["Abu Dhabi,UAE"]
    assert city.name == "Abu Dhabi"


def test_Adelaide():
    """Test for fix made due to bug report from Klaus Alexander Seistrup"""

    db = Geocoder()
    _city = db["Adelaide"]


def test_CandianCities():
    db = Geocoder()

    city = db["Fredericton"]
    assert city.elevation == 8


def test_AllCities():
    db = Geocoder()
    locations = db.locations
    locations.sort()

    for city_name in locations:
        _city = db[city_name]

@@ -64,20 +64,22 @@
 approx%0A%0A
-from
+import
  astral.
@@ -90,32 +90,8 @@
 oder
- import Geocoder, lookup
 %0A%0A%0Ad
@@ -113,19 +113,37 @@
 ):%0A    l
+oc
  = 
+astral.geocoder.
 lookup(%22
@@ -163,16 +163,18 @@
 assert l
+oc
 .name ==
@@ -195,16 +195,18 @@
 assert l
+oc
 .region 
@@ -237,16 +237,18 @@
 approx(l
+oc
 .latitud
@@ -275,16 +275,18 @@
 approx(l
+oc
 .longitu
@@ -362,16 +362,18 @@
 mezone(l
+oc
 .timezon
@@ -408,16 +408,18 @@
 assert l
+oc
 .elevati
@@ -448,32 +448,48 @@
 oup():%0A    db = 
+astral.geocoder.
 Geocoder()%0A    _
@@ -486,21 +486,16 @@
 er()%0A   
- _e =
  db.euro
@@ -562,32 +562,48 @@
 ):%0A        db = 
+astral.geocoder.
 Geocoder()%0A     
@@ -608,13 +608,8 @@
     
- _e =
  db.
@@ -649,32 +649,48 @@
 ent():%0A    db = 
+astral.geocoder.
 Geocoder()%0A    a
@@ -742,32 +742,48 @@
 ent():%0A    db = 
+astral.geocoder.
 Geocoder()%0A    a
@@ -868,32 +868,48 @@
 land%22%0A%0A    db = 
+astral.geocoder.
 Geocoder()%0A    c
@@ -1029,32 +1029,48 @@
 try():%0A    db = 
+astral.geocoder.
 Geocoder()%0A    c
@@ -1243,32 +1243,48 @@
 up%22%22%22%0A%0A    db = 
+astral.geocoder.
 Geocoder()%0A    c
@@ -1531,32 +1531,48 @@
 up%22%22%22%0A%0A    db = 
+astral.geocoder.
 Geocoder()%0A    _
@@ -1569,24 +1569,16 @@
 er()%0A   
- _city =
  db%5B%22Ade
@@ -1614,32 +1614,48 @@
 ies():%0A    db = 
+astral.geocoder.
 Geocoder()%0A%0A    
@@ -1743,16 +1743,32 @@
    db = 
+astral.geocoder.
 Geocoder
@@ -1864,16 +1864,8 @@
     
- _city =
  db%5B

Fix linter errors