|
6 | 6 | import ipaddress
|
7 | 7 | import sys
|
8 | 8 | import unittest
|
| 9 | +from unittest.mock import patch, MagicMock |
9 | 10 |
|
10 | 11 | sys.path.append("..")
|
11 | 12 |
|
|
19 | 20 | maxminddb.extension = None # type: ignore
|
20 | 21 |
|
21 | 22 |
|
22 |
| -class BaseTestReader(unittest.TestCase): |
| 23 | +class TestReader(unittest.TestCase): |
23 | 24 | def test_language_list(self) -> None:
|
24 | 25 | reader = geoip2.database.Reader(
|
25 | 26 | "tests/data/test-data/GeoIP2-Country-Test.mmdb",
|
@@ -262,27 +263,13 @@ def test_context_manager(self) -> None:
|
262 | 263 | record = reader.country("81.2.69.160")
|
263 | 264 | self.assertEqual(record.traits.ip_address, "81.2.69.160")
|
264 | 265 |
|
| 266 | + @patch("maxminddb.open_database") |
| 267 | + def test_modes(self, mock_open) -> None: |
| 268 | + mock_open.return_value = MagicMock() |
265 | 269 |
|
266 |
| -@unittest.skipUnless(maxminddb.extension, "No C extension module found. Skipping tests") |
267 |
| -class TestExtensionReader(BaseTestReader): |
268 |
| - mode = geoip2.database.MODE_MMAP_EXT |
269 |
| - |
270 |
| - |
271 |
| -class TestMMAPReader(BaseTestReader): |
272 |
| - mode = geoip2.database.MODE_MMAP |
273 |
| - |
274 |
| - |
275 |
| -class TestFileReader(BaseTestReader): |
276 |
| - mode = geoip2.database.MODE_FILE |
277 |
| - |
278 |
| - |
279 |
| -class TestMemoryReader(BaseTestReader): |
280 |
| - mode = geoip2.database.MODE_MEMORY |
281 |
| - |
282 |
| - |
283 |
| -class TestFDReader(unittest.TestCase): |
284 |
| - mode = geoip2.database.MODE_FD |
285 |
| - |
286 |
| - |
287 |
| -class TestAutoReader(BaseTestReader): |
288 |
| - mode = geoip2.database.MODE_AUTO |
| 270 | + path = "tests/data/test-data/GeoIP2-Country-Test.mmdb" |
| 271 | + with geoip2.database.Reader( |
| 272 | + path, |
| 273 | + mode=geoip2.database.MODE_MMAP_EXT, |
| 274 | + ) as reader: |
| 275 | + mock_open.assert_called_once_with(path, geoip2.database.MODE_MMAP_EXT) |
0 commit comments