Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pygeoip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pygeoip
Commits
da3be8ac
Commit
da3be8ac
authored
Aug 22, 2013
by
William Tisäter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increase test coverage
parent
6015ddaa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
3 deletions
+14
-3
pygeoip/__init__.py
+2
-2
tests/config.py
+1
-0
tests/test.py
+11
-1
No files found.
pygeoip/__init__.py
View file @
da3be8ac
...
...
@@ -29,7 +29,7 @@ from threading import Lock
try
:
import
mmap
except
ImportError
:
except
ImportError
:
# pragma: no cover
mmap
=
None
try
:
...
...
@@ -99,7 +99,7 @@ class GeoIP(object):
"""
self
.
_flags
=
flags
if
self
.
_flags
&
const
.
MMAP_CACHE
and
mmap
is
None
:
if
self
.
_flags
&
const
.
MMAP_CACHE
and
mmap
is
None
:
# pragma: no cover
import
warnings
warnings
.
warn
(
"MMAP_CACHE cannot be used without a mmap module"
)
self
.
_flags
&=
~
const
.
MMAP_CACHE
...
...
tests/config.py
View file @
da3be8ac
...
...
@@ -9,3 +9,4 @@ CITY_DB_PATH = path.join(DATA_DIR, 'GeoLiteCity.dat')
ORG_DB_PATH
=
path
.
join
(
DATA_DIR
,
'GeoIPOrg.dat'
)
ASNUM_DB_PATH
=
path
.
join
(
DATA_DIR
,
'GeoIPASNum.dat'
)
ISP_DB_PATH
=
path
.
join
(
DATA_DIR
,
'GeoIPISP.dat'
)
CORRUPT_DB_PATH
=
path
.
join
(
DATA_DIR
,
'../config.py'
)
tests/test.py
View file @
da3be8ac
...
...
@@ -5,7 +5,7 @@ from nose.tools import raises
import
pygeoip
from
pygeoip
import
const
from
tests.config
import
COUNTRY_DB_PATH
from
tests.config
import
COUNTRY_DB_PATH
,
CORRUPT_DB_PATH
class
TestGenerals
(
unittest
.
TestCase
):
def
testContructing
(
self
):
...
...
@@ -17,6 +17,16 @@ class TestGenerals(unittest.TestCase):
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
COUNTRY_NAMES
)
assert
len
(
const
.
COUNTRY_CODES
)
==
len
(
const
.
CONTINENT_NAMES
)
def
testMetaclass
(
self
):
a
=
pygeoip
.
GeoIP
(
filename
=
COUNTRY_DB_PATH
)
b
=
pygeoip
.
GeoIP
(
filename
=
COUNTRY_DB_PATH
)
assert
a
is
b
@raises
(
pygeoip
.
GeoIPError
)
def
testCorruptDatabase
(
self
):
gi
=
pygeoip
.
GeoIP
(
filename
=
CORRUPT_DB_PATH
)
gi
.
country_code_by_name
(
'google.com'
)
@raises
(
socket
.
gaierror
)
def
testFailedLookup
(
self
):
gi
=
pygeoip
.
GeoIP
(
filename
=
COUNTRY_DB_PATH
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment