Debian Codegraph @

tests/asciicast/v2_test.py

raw
1 import json
2 import tempfile
3
4 from asciinema.asciicast import v2
5
6 from ..test_helper import Test
7
8
9 class TestWriter(Test):
10 @staticmethod
11 def test_writing() -> None:
12 _file, path = tempfile.mkstemp()
13
14 with v2.writer(path, width=80, height=24) as w:
15 w.write_stdout(1, "x") # ensure it supports both str and bytes
16 w.write_stdout(2, bytes.fromhex("78 c5 bc c3 b3 c5"))
17 w.write_stdout(3, bytes.fromhex("82 c4 87"))
18 w.write_stdout(4, bytes.fromhex("78 78"))
19
20 with open(path, "rt", encoding="utf_8") as f:
21 lines = list(map(json.loads, f.read().strip().split("\n")))
22 assert lines == [
23 {"version": 2, "width": 80, "height": 24},
24 [1, "o", "x"],
25 [2, "o", "xżó"],
26 [3, "o", "łć"],
27 [4, "o", "xx"],
28 ], f"got:\n\n{lines}"