Skip to content

Commit

Permalink
Merge pull request #179 from maxmind/greg/test-mode-setting
Browse files Browse the repository at this point in the history
Explicitly test mode setting
  • Loading branch information
oschwald authored Aug 27, 2024
2 parents e8bed66 + f74f1d3 commit df415c7
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions tests/database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import ipaddress
import sys
import unittest
from unittest.mock import patch, MagicMock

sys.path.append("..")

Expand All @@ -19,7 +20,7 @@
maxminddb.extension = None # type: ignore


class BaseTestReader(unittest.TestCase):
class TestReader(unittest.TestCase):
def test_language_list(self) -> None:
reader = geoip2.database.Reader(
"tests/data/test-data/GeoIP2-Country-Test.mmdb",
Expand Down Expand Up @@ -262,27 +263,13 @@ def test_context_manager(self) -> None:
record = reader.country("81.2.69.160")
self.assertEqual(record.traits.ip_address, "81.2.69.160")

@patch("maxminddb.open_database")
def test_modes(self, mock_open) -> None:
mock_open.return_value = MagicMock()

@unittest.skipUnless(maxminddb.extension, "No C extension module found. Skipping tests")
class TestExtensionReader(BaseTestReader):
mode = geoip2.database.MODE_MMAP_EXT


class TestMMAPReader(BaseTestReader):
mode = geoip2.database.MODE_MMAP


class TestFileReader(BaseTestReader):
mode = geoip2.database.MODE_FILE


class TestMemoryReader(BaseTestReader):
mode = geoip2.database.MODE_MEMORY


class TestFDReader(unittest.TestCase):
mode = geoip2.database.MODE_FD


class TestAutoReader(BaseTestReader):
mode = geoip2.database.MODE_AUTO
path = "tests/data/test-data/GeoIP2-Country-Test.mmdb"
with geoip2.database.Reader(
path,
mode=geoip2.database.MODE_MMAP_EXT,
) as reader:
mock_open.assert_called_once_with(path, geoip2.database.MODE_MMAP_EXT)

0 comments on commit df415c7

Please sign in to comment.