Skip to content

Explicitly test mode setting #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading