Tests that flush() returns None when the file is open, and raises ValueError when the file is closed. CPython reference: Modules/_io/bytesio.c:325-335
()
| 75 | |
| 76 | |
| 77 | def test_07(): |
| 78 | """ |
| 79 | Tests that flush() returns None when the file is open, |
| 80 | and raises ValueError when the file is closed. |
| 81 | CPython reference: Modules/_io/bytesio.c:325-335 |
| 82 | """ |
| 83 | f = BytesIO(b"Test String 7") |
| 84 | |
| 85 | # flush() on an open BytesIO returns None |
| 86 | assert f.flush() is None |
| 87 | |
| 88 | # flush() is defined directly on BytesIO (not just inherited) |
| 89 | assert "flush" in BytesIO.__dict__ |
| 90 | |
| 91 | f.close() |
| 92 | |
| 93 | # flush() on a closed BytesIO raises ValueError |
| 94 | try: |
| 95 | f.flush() |
| 96 | assert False, "Expected ValueError not raised" |
| 97 | except ValueError: |
| 98 | pass |
| 99 | |
| 100 | |
| 101 | if __name__ == "__main__": |
no test coverage detected