summaryrefslogtreecommitdiffstats
path: root/tests/asciicast
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:59:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:59:18 +0000
commitfa60720fe95711a68dd4f1cb57fbc79fc6fc2e5c (patch)
treea8712923a49e76a6241f151af877900e056ce65d /tests/asciicast
parentInitial commit. (diff)
downloadasciinema-upstream.tar.xz
asciinema-upstream.zip
Adding upstream version 2.4.0.upstream/2.4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/asciicast')
-rw-r--r--tests/asciicast/__init__.py0
-rw-r--r--tests/asciicast/v2_test.py28
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/asciicast/__init__.py b/tests/asciicast/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/asciicast/__init__.py
diff --git a/tests/asciicast/v2_test.py b/tests/asciicast/v2_test.py
new file mode 100644
index 0000000..113ddf7
--- /dev/null
+++ b/tests/asciicast/v2_test.py
@@ -0,0 +1,28 @@
+import json
+import tempfile
+
+from asciinema.asciicast import v2
+
+from ..test_helper import Test
+
+
+class TestWriter(Test):
+ @staticmethod
+ def test_writing() -> None:
+ _file, path = tempfile.mkstemp()
+
+ with v2.writer(path, width=80, height=24) as w:
+ 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"))
+
+ with open(path, "rt", encoding="utf_8") as f:
+ 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"],
+ ], f"got:\n\n{lines}"