Passed
Push — main ( ed7d21...87238c )
by Douglas
01:43
created

tests.pocketutils.core.test_input_output   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 39
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestIo.test_open_mode_normalize() 0 11 1
A TestIo.test_delegating() 0 15 1
A TestIo.test_capture() 0 4 1
1
from io import StringIO
2
from typing import Self
3
4
import pytest
5
from pocketutils.core.input_output import Capture, DelegatingWriter, OpenMode
6
from pocketutils.core.mocks import MockWritable
7
8
9
class TestIo:
10
    def test_delegating(self: Self) -> None:
11
        a, b = MockWritable(), MockWritable()
12
        d = DelegatingWriter(a, b)
13
        d.write("abc")
14
        assert a.data == "write:abc"
15
        assert b.data == "write:abc"
16
        d.flush()
17
        assert a.data == "write:abcflush"
18
        assert b.data == "write:abcflush"
19
        d.close()
20
        assert a.data == "write:abcflushclose"
21
        assert b.data == "write:abcflushclose"
22
        a.write("00")
23
        assert a.data == "write:00"
24
        assert b.data == "write:abcflushclose"
25
26
    def test_capture(self: Self) -> None:
27
        w = StringIO("abc")
28
        c = Capture(w)
29
        assert c.value == "abc"
30
31
    def test_open_mode_normalize(self: Self) -> None:
32
        o = OpenMode
33
        assert str(o("").normalize()) == "rt"
34
        assert str(o("r").normalize()) == "rt"
35
        assert str(o("wU").normalize()) == "wt"
36
        assert str(o("a").normalize()) == "at"
37
        assert str(o("w+").normalize()) == "wt+"
38
        assert str(o("wt+").normalize()) == "wt+"
39
        assert str(o("wb+").normalize()) == "wb+"
40
        assert str(o("Ux").normalize()) == "xt"
41
        assert str(o("Uxb").normalize()) == "xb"
42
43
44
if __name__ == "__main__":
45
    pytest.main()
46