2018-03-04 10:42:58 +01:00
|
|
|
import json
|
2021-11-03 02:32:02 -04:00
|
|
|
import tempfile
|
2018-03-03 20:03:02 +01:00
|
|
|
|
2022-02-21 18:30:09 -05:00
|
|
|
from asciinema.asciicast import v2
|
2018-03-03 20:03:02 +01:00
|
|
|
|
2021-11-03 02:32:02 -04:00
|
|
|
from ..test_helper import Test
|
2018-03-03 20:03:02 +01:00
|
|
|
|
2021-11-03 02:32:02 -04:00
|
|
|
|
|
|
|
|
class TestWriter(Test):
|
2022-02-21 18:30:09 -05:00
|
|
|
@staticmethod
|
|
|
|
|
def test_writing() -> None:
|
2018-03-03 20:03:02 +01:00
|
|
|
_file, path = tempfile.mkstemp()
|
|
|
|
|
|
|
|
|
|
with v2.writer(path, width=80, height=24) as w:
|
2021-11-03 02:32:02 -04:00
|
|
|
w.write_stdout(1, "x") # ensure it supports both str and bytes
|
|
|
|
|
w.write_stdout(2, bytes.fromhex("78 c5 bc c3 b3 c5"))
|
|
|
|
|
w.write_stdout(3, bytes.fromhex("82 c4 87"))
|
|
|
|
|
w.write_stdout(4, bytes.fromhex("78 78"))
|
2018-03-03 20:03:02 +01:00
|
|
|
|
2022-02-21 18:30:09 -05:00
|
|
|
with open(path, "rt", encoding="utf_8") as f:
|
2021-11-03 02:32:02 -04:00
|
|
|
lines = list(map(json.loads, f.read().strip().split("\n")))
|
|
|
|
|
assert lines == [
|
|
|
|
|
{"version": 2, "width": 80, "height": 24},
|
|
|
|
|
[1, "o", "x"],
|
|
|
|
|
[2, "o", "xżó"],
|
|
|
|
|
[3, "o", "łć"],
|
|
|
|
|
[4, "o", "xx"],
|
2022-02-21 18:30:09 -05:00
|
|
|
], f"got:\n\n{lines}"
|