|
1 | | -#!/usr/bin/env python |
2 | | - |
3 | 1 | import ipaddress |
4 | 2 | import multiprocessing |
5 | 3 | import os |
@@ -180,14 +178,15 @@ def test_get_with_prefix_len(self) -> None: |
180 | 178 | self.mode, |
181 | 179 | ) as reader: |
182 | 180 | (record, prefix_len) = reader.get_with_prefix_len( |
183 | | - cast("str", test["ip"]) |
| 181 | + cast("str", test["ip"]), |
184 | 182 | ) |
185 | 183 |
|
186 | 184 | self.assertEqual( |
187 | 185 | prefix_len, |
188 | 186 | test["expected_prefix_len"], |
189 | | - f"expected prefix_len of {test['expected_prefix_len']} for {test['ip']}" |
190 | | - + f" in {test['file_name']} but got {prefix_len}", |
| 187 | + f"expected prefix_len of {test['expected_prefix_len']}" |
| 188 | + f" for {test['ip']}" |
| 189 | + f" in {test['file_name']} but got {prefix_len}", |
191 | 190 | ) |
192 | 191 | self.assertEqual( |
193 | 192 | record, |
@@ -241,7 +240,10 @@ def test_iterator(self) -> None: |
241 | 240 |
|
242 | 241 | for record_size in [24, 28, 32]: |
243 | 242 | for test in tests: |
244 | | - f = f"tests/data/test-data/MaxMind-DB-test-{test['database']}-{record_size}.mmdb" |
| 243 | + f = ( |
| 244 | + f"tests/data/test-data/MaxMind-DB-test-{test['database']}" |
| 245 | + f"-{record_size}.mmdb" |
| 246 | + ) |
245 | 247 | reader = open_database(f, self.mode) |
246 | 248 | networks = [str(n) for (n, _) in reader] |
247 | 249 | self.assertEqual(networks, test["expected"], f) |
@@ -326,7 +328,7 @@ def test_no_extension_exception(self) -> None: |
326 | 328 | "tests/data/test-data/MaxMind-DB-test-decoder.mmdb", |
327 | 329 | MODE_MMAP_EXT, |
328 | 330 | ) |
329 | | - maxminddb._extension = real_extension |
| 331 | + maxminddb._extension = real_extension # noqa: SLF001 |
330 | 332 |
|
331 | 333 | def test_broken_database(self) -> None: |
332 | 334 | reader = open_database( |
@@ -455,10 +457,8 @@ def test_double_close(self) -> None: |
455 | 457 | self.mode, |
456 | 458 | ) |
457 | 459 | reader.close() |
458 | | - self.assertIsNone( |
459 | | - reader.close(), |
460 | | - "Double close does not throw an exception", # type: ignore |
461 | | - ) |
| 460 | + # Check that calling close again doesn't raise an exception |
| 461 | + reader.close() |
462 | 462 |
|
463 | 463 | def test_closed_get(self) -> None: |
464 | 464 | if self.mode in [MODE_MEMORY, MODE_FD]: |
@@ -503,10 +503,6 @@ def test_closed(self) -> None: |
503 | 503 | reader.close() |
504 | 504 | self.assertEqual(reader.closed, True) |
505 | 505 |
|
506 | | - # XXX - Figure out whether we want to have the same behavior on both the |
507 | | - # extension and the pure Python reader. If we do, the pure Python |
508 | | - # reader will need to throw an exception or the extension will need |
509 | | - # to keep the metadata in memory. |
510 | 506 | def test_closed_metadata(self) -> None: |
511 | 507 | reader = open_database( |
512 | 508 | "tests/data/test-data/MaxMind-DB-test-decoder.mmdb", |
@@ -535,26 +531,26 @@ def test_multiprocessing(self): |
535 | 531 | def test_threading(self): |
536 | 532 | self._check_concurrency(threading.Thread) |
537 | 533 |
|
538 | | - def _check_concurrency(self, worker_class) -> None: |
| 534 | + def _check_concurrency(self, worker_class) -> None: # noqa: ANN001 |
539 | 535 | reader = open_database( |
540 | 536 | "tests/data/test-data/GeoIP2-Domain-Test.mmdb", |
541 | 537 | self.mode, |
542 | 538 | ) |
543 | 539 |
|
544 | | - def lookup(pipe) -> None: |
| 540 | + def lookup(pipe) -> None: # noqa: ANN001 |
545 | 541 | try: |
546 | 542 | for i in range(32): |
547 | 543 | reader.get(self.ipf(f"65.115.240.{i}")) |
548 | 544 | pipe.send(1) |
549 | | - except: |
| 545 | + except: # noqa: E722 |
550 | 546 | pipe.send(0) |
551 | 547 | finally: |
552 | 548 | if worker_class is self.mp.Process: # type: ignore[attr-defined] |
553 | 549 | reader.close() |
554 | 550 | pipe.close() |
555 | 551 |
|
556 | 552 | pipes = [self.mp.Pipe() for _ in range(32)] |
557 | | - procs = [worker_class(target=lookup, args=(c,)) for (p, c) in pipes] |
| 553 | + procs = [worker_class(target=lookup, args=(c,)) for (_, c) in pipes] |
558 | 554 | for proc in procs: |
559 | 555 | proc.start() |
560 | 556 | for proc in procs: |
|
0 commit comments