|
10 | 10 | import threading |
11 | 11 | import time |
12 | 12 | import traceback |
| 13 | +from unittest import mock |
13 | 14 |
|
14 | 15 | import pytest |
15 | 16 |
|
|
40 | 41 | _get_conn_data, |
41 | 42 | _probe_ipv6_sock, |
42 | 43 | ) |
43 | | -from unittest import mock |
44 | 44 | from ..wsgi import Gateway_10 |
45 | 45 |
|
46 | 46 |
|
@@ -627,38 +627,42 @@ def test_ssl_env( # noqa: C901 # FIXME |
627 | 627 | ), |
628 | 628 | ) |
629 | 629 |
|
| 630 | + |
630 | 631 | class TestBufferedWriterSSLWantErrors: |
631 | | - |
| 632 | + """Test SSL want error handling in BufferedWriter.""" |
| 633 | + |
632 | 634 | def setup_method(self): |
| 635 | + """Set up test fixtures with mock raw socket and BufferedWriter.""" |
633 | 636 | self.mock_raw = mock.Mock() |
634 | 637 | self.mock_raw.closed = False |
635 | 638 | self.writer = BufferedWriter(self.mock_raw) |
636 | 639 |
|
637 | 640 | def test_want_write_error_retry(self): |
638 | 641 | """Test that WantWriteError causes retry with same data.""" |
639 | | - test_data = b"hello world" |
640 | | - |
| 642 | + test_data = b'hello world' |
| 643 | + |
641 | 644 | self.mock_raw.write.side_effect = [ |
642 | 645 | OpenSSL.SSL.WantWriteError(), |
643 | | - len(test_data) |
| 646 | + len(test_data), |
644 | 647 | ] |
645 | | - |
| 648 | + |
646 | 649 | result = self.writer.write(test_data) |
647 | 650 | assert result == len(test_data) |
648 | 651 | assert self.mock_raw.write.call_count == 2 |
649 | 652 |
|
650 | 653 | def test_want_read_error_retry(self): |
651 | 654 | """Test that WantReadError causes retry with same data.""" |
652 | | - test_data = b"test data" |
653 | | - |
| 655 | + test_data = b'test data' |
| 656 | + |
654 | 657 | self.mock_raw.write.side_effect = [ |
655 | | - OpenSSL.SSL.WantReadError(), |
656 | | - len(test_data) |
| 658 | + OpenSSL.SSL.WantReadError(), |
| 659 | + len(test_data), |
657 | 660 | ] |
658 | | - |
| 661 | + |
659 | 662 | result = self.writer.write(test_data) |
660 | 663 | assert result == len(test_data) |
661 | 664 |
|
| 665 | + |
662 | 666 | @pytest.mark.parametrize( |
663 | 667 | 'ip_addr', |
664 | 668 | ( |
|
0 commit comments