Skip to content

Commit b4d29c3

Browse files
authored
Merge pull request #59 from maxmind/greg/fix-travis
Fix Travis builds and add 3.7 to Travis
2 parents 55d2237 + e256afc commit b4d29c3

File tree

10 files changed

+77
-57
lines changed

10 files changed

+77
-57
lines changed

.travis-pylint.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
#!/bin/sh
1+
#!/bin/bash
2+
3+
set -eux
4+
25
python setup.py install
36
pylint geoip2

.travis-yapf.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
set -eux
4+
35
diff=$(yapf -rd geoip2 tests)
46

57
if [[ $? != 0 ]]; then

.travis.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
---
22
language: python
3-
python:
4-
- '2.7'
5-
- '3.3'
6-
- '3.4'
7-
- '3.5'
8-
- '3.6'
9-
- nightly
10-
- pypy
113
matrix:
4+
include:
5+
- python: 2.7
6+
dist: trusty
7+
- python: 3.3
8+
dist: trusty
9+
- python: 3.4
10+
dist: trusty
11+
- python: 3.5
12+
dist: trusty
13+
- python: 3.6
14+
dist: trusty
15+
- python: 3.7
16+
dist: xenial
17+
- python: nightly
18+
dist: xenial
19+
- python: pypy
20+
dist: trusty
1221
allow_failures:
1322
- python: nightly
1423

@@ -25,12 +34,12 @@ before_install:
2534
- pip install -e git+https://github.com/maxmind/MaxMind-DB-Reader-python#egg=maxminddb
2635
install:
2736
- pip install -r requirements.txt
28-
- pip install requests_mock pylint coveralls
37+
- pip install requests_mock pylint coveralls yapf
2938
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then pip install ipaddr; fi"
3039
script:
3140
- coverage run --source=geoip2 setup.py test
32-
- "if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then ./.travis-pylint.sh; fi"
33-
- "if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then ./.travis-yapf.sh; fi"
41+
- "if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then ./.travis-pylint.sh; fi"
42+
- "if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then ./.travis-yapf.sh; fi"
3443
after_success:
3544
- coveralls
3645
notifications:

geoip2/database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import geoip2.errors
1717

1818

19-
class Reader(object):
19+
class Reader:
2020
"""GeoIP2 database Reader object.
2121
2222
Instances of this class provide a reader for the GeoIP2 database format.
@@ -182,9 +182,9 @@ def isp(self, ip_address):
182182
def _get(self, database_type, ip_address):
183183
if database_type not in self.metadata().database_type:
184184
caller = inspect.stack()[2][3]
185-
raise TypeError("The %s method cannot be used with the "
186-
"%s database" % (caller,
187-
self.metadata().database_type))
185+
raise TypeError(
186+
"The %s method cannot be used with the "
187+
"%s database" % (caller, self.metadata().database_type))
188188
record = self._db_reader.get(ip_address)
189189
if record is None:
190190
raise geoip2.errors.AddressNotFoundError(

geoip2/mixins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from abc import ABCMeta
44

55

6-
class SimpleEquality(object):
6+
class SimpleEquality:
77
"""Naive __dict__ equality mixin"""
88

99
__metaclass__ = ABCMeta

geoip2/webservice.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
PermissionRequiredError)
4040

4141

42-
class Client(object):
42+
class Client:
4343
"""Creates a new client object.
4444
4545
It accepts the following required arguments:
@@ -176,10 +176,10 @@ def _handle_success(self, response, uri):
176176
try:
177177
return response.json()
178178
except ValueError as ex:
179-
raise GeoIP2Error('Received a 200 response for %(uri)s'
180-
' but could not decode the response as '
181-
'JSON: ' % locals() + ', '.join(ex.args), 200,
182-
uri)
179+
raise GeoIP2Error(
180+
'Received a 200 response for %(uri)s'
181+
' but could not decode the response as '
182+
'JSON: ' % locals() + ', '.join(ex.args), 200, uri)
183183

184184
def _exception_for_error(self, response, uri):
185185
status = response.status_code
@@ -192,25 +192,27 @@ def _exception_for_error(self, response, uri):
192192

193193
def _exception_for_4xx_status(self, response, status, uri):
194194
if not response.content:
195-
return HTTPError('Received a %(status)i error for %(uri)s '
196-
'with no body.' % locals(), status, uri)
195+
return HTTPError(
196+
'Received a %(status)i error for %(uri)s '
197+
'with no body.' % locals(), status, uri)
197198
elif response.headers['Content-Type'].find('json') == -1:
198-
return HTTPError('Received a %i for %s with the following '
199-
'body: %s' % (status, uri, response.content),
200-
status, uri)
199+
return HTTPError(
200+
'Received a %i for %s with the following '
201+
'body: %s' % (status, uri, response.content), status, uri)
201202
try:
202203
body = response.json()
203204
except ValueError as ex:
204205
return HTTPError(
205206
'Received a %(status)i error for %(uri)s but it did'
206-
' not include the expected JSON body: ' % locals() +
207-
', '.join(ex.args), status, uri)
207+
' not include the expected JSON body: ' % locals() + ', '.join(
208+
ex.args), status, uri)
208209
else:
209210
if 'code' in body and 'error' in body:
210211
return self._exception_for_web_service_error(
211212
body.get('error'), body.get('code'), status, uri)
212-
return HTTPError('Response contains JSON but it does not specify '
213-
'code or error keys', status, uri)
213+
return HTTPError(
214+
'Response contains JSON but it does not specify '
215+
'code or error keys', status, uri)
214216

215217
def _exception_for_web_service_error(self, message, code, status, uri):
216218
if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
@@ -227,9 +229,11 @@ def _exception_for_web_service_error(self, message, code, status, uri):
227229
return InvalidRequestError(message, code, status, uri)
228230

229231
def _exception_for_5xx_status(self, status, uri):
230-
return HTTPError('Received a server error (%(status)i) for '
231-
'%(uri)s' % locals(), status, uri)
232+
return HTTPError(
233+
'Received a server error (%(status)i) for '
234+
'%(uri)s' % locals(), status, uri)
232235

233236
def _exception_for_non_200_status(self, status, uri):
234-
return HTTPError('Received a very surprising HTTP status '
235-
'(%(status)i) for %(uri)s' % locals(), status, uri)
237+
return HTTPError(
238+
'Received a very surprising HTTP status '
239+
'(%(status)i) for %(uri)s' % locals(), status, uri)

pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[MESSAGES CONTROL]
2-
disable=R0201,W0105
2+
disable=R0201,R1705,W0105
33

44
[BASIC]
55

tests/database_test.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,28 @@ def test_language_list(self):
3737
def test_unknown_address(self):
3838
reader = geoip2.database.Reader(
3939
'tests/data/test-data/GeoIP2-City-Test.mmdb')
40-
with self.assertRaisesRegex(geoip2.errors.AddressNotFoundError,
41-
'The address 10.10.10.10 is not in the '
42-
'database.'):
40+
with self.assertRaisesRegex(
41+
geoip2.errors.AddressNotFoundError,
42+
'The address 10.10.10.10 is not in the '
43+
'database.'):
4344
reader.city('10.10.10.10')
4445
reader.close()
4546

4647
def test_wrong_database(self):
4748
reader = geoip2.database.Reader(
4849
'tests/data/test-data/GeoIP2-City-Test.mmdb')
49-
with self.assertRaisesRegex(TypeError,
50-
'The country method cannot be used with '
51-
'the GeoIP2-City database'):
50+
with self.assertRaisesRegex(
51+
TypeError, 'The country method cannot be used with '
52+
'the GeoIP2-City database'):
5253
reader.country('1.1.1.1')
5354
reader.close()
5455

5556
def test_invalid_address(self):
5657
reader = geoip2.database.Reader(
5758
'tests/data/test-data/GeoIP2-City-Test.mmdb')
58-
with self.assertRaisesRegex(ValueError,
59-
"u?'invalid' does not appear to be an "
60-
"IPv4 or IPv6 address"):
59+
with self.assertRaisesRegex(
60+
ValueError, "u?'invalid' does not appear to be an "
61+
"IPv4 or IPv6 address"):
6162
reader.city('invalid')
6263
reader.close()
6364

tests/models_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,10 @@ def test_three_locales(self):
366366

367367
def test_two_locales(self):
368368
model = geoip2.models.Country(self.raw, locales=['ak', 'fr'])
369-
self.assertEqual(model.continent.name, None,
370-
'continent name is undef (no Akan or French '
371-
'available)')
369+
self.assertEqual(
370+
model.continent.name, None,
371+
'continent name is undef (no Akan or French '
372+
'available)')
372373
self.assertEqual(model.country.name, 'États-Unis',
373374
'country name is in French')
374375

tests/webservice_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def test_200_error(self, mock):
120120
self.client.country('1.1.1.1')
121121

122122
def test_bad_ip_address(self):
123-
with self.assertRaisesRegex(ValueError,
124-
"'1.2.3' does not appear to be an IPv4 "
125-
"or IPv6 address"):
123+
with self.assertRaisesRegex(
124+
ValueError, "'1.2.3' does not appear to be an IPv4 "
125+
"or IPv6 address"):
126126
self.client.country('1.2.3')
127127

128128
@requests_mock.mock()
@@ -143,9 +143,9 @@ def test_weird_body_error(self, mock):
143143
text='{"wierd": 42}',
144144
status_code=400,
145145
headers={'Content-Type': self._content_type('country')})
146-
with self.assertRaisesRegex(HTTPError,
147-
'Response contains JSON but it does not '
148-
'specify code or error keys'):
146+
with self.assertRaisesRegex(
147+
HTTPError, 'Response contains JSON but it does not '
148+
'specify code or error keys'):
149149
self.client.country('1.2.3.8')
150150

151151
@requests_mock.mock()
@@ -172,9 +172,9 @@ def test_300_error(self, mock):
172172
self.base_uri + 'country/' + '1.2.3.11',
173173
status_code=300,
174174
headers={'Content-Type': self._content_type('country')})
175-
with self.assertRaisesRegex(HTTPError,
176-
'Received a very surprising HTTP status '
177-
'\(300\) for'):
175+
with self.assertRaisesRegex(
176+
HTTPError, 'Received a very surprising HTTP status '
177+
'\(300\) for'):
178178

179179
self.client.country('1.2.3.11')
180180

0 commit comments

Comments
 (0)