File: test_common.py

package info (click to toggle)
zigpy-znp 0.14.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,112 kB
  • sloc: python: 14,241; makefile: 6
file content (21 lines) | stat: -rw-r--r-- 450 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from zigpy_znp.tools.common import UnclosableFile


def test_unclosable_file(tmp_path):
    path = tmp_path / "test.txt"
    f = path.open("w")

    with UnclosableFile(f) as unclosable_f:
        unclosable_f.write("test")
        unclosable_f.close()

    assert unclosable_f.f is f
    assert not unclosable_f.closed
    assert not f.closed

    f.close()

    assert unclosable_f.closed
    assert f.closed

    assert path.read_text() == "test"