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