Skip to content

Commit 4c4f757

Browse files
authored
Add smoke tests (mypyc#12)
Ref mypyc#11
1 parent bf55aa3 commit 4c4f757

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed

.github/workflows/buildwheels.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ jobs:
6262
"arch": the_arch,
6363
}
6464
# For some OS/arch we need to specify OS version
65-
if the_os == "macos":
66-
them["os-version"] = "13"
6765
if the_os == "windows" and the_arch == "ARM64":
6866
them["os-version"] = "11-arm"
6967
if the_arch == "aarch64":

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ Homepage = "https://github.com/mypyc/librt"
4242
Issues = "https://github.com/mypyc/mypyc/issues"
4343

4444
[tool.cibuildwheel]
45-
4645
build-frontend = "build"
4746
linux.manylinux-x86_64-image = "manylinux_2_28"
4847
linux.manylinux-aarch64-image = "manylinux_2_28"
@@ -55,6 +54,16 @@ linux.before-all = [
5554
"yum install -y llvm-toolset || yum -v install -y llvm-toolset",
5655
]
5756

57+
before-test = [
58+
"pip install pytest mypy_extensions",
59+
]
60+
61+
test-sources = [
62+
"smoke_tests.py",
63+
]
64+
65+
test-command = "pytest smoke_tests.py"
66+
5867
[tool.cibuildwheel.linux.environment]
5968
CC="clang"
6069

smoke_tests.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
from typing import Final
2+
from mypy_extensions import u8
3+
4+
from librt.internal import (
5+
Buffer,
6+
write_bool, read_bool,
7+
write_str, read_str,
8+
write_float, read_float,
9+
write_int, read_int,
10+
write_tag, read_tag,
11+
)
12+
13+
Tag = u8
14+
TAG_A: Final[Tag] = 33
15+
TAG_B: Final[Tag] = 255
16+
TAG_SPECIAL: Final[Tag] = 239
17+
18+
19+
def test_buffer_basic() -> None:
20+
b = Buffer(b"foo")
21+
assert b.getvalue() == b"foo"
22+
23+
24+
def test_buffer_empty() -> None:
25+
b = Buffer(b"")
26+
write_int(b, 42)
27+
b = Buffer(b.getvalue())
28+
assert read_int(b) == 42
29+
30+
31+
def test_buffer_roundtrip() -> None:
32+
b = Buffer()
33+
write_str(b, "foo")
34+
write_bool(b, True)
35+
write_str(b, "bar" * 1000)
36+
write_bool(b, False)
37+
write_float(b, 0.1)
38+
write_tag(b, TAG_A)
39+
write_tag(b, TAG_SPECIAL)
40+
write_tag(b, TAG_B)
41+
write_int(b, 1)
42+
write_int(b, 2)
43+
write_int(b, 2 ** 85)
44+
write_int(b, 1234512344)
45+
write_int(b, 1234512345)
46+
47+
b = Buffer(b.getvalue())
48+
assert read_str(b) == "foo"
49+
assert read_bool(b) is True
50+
assert read_str(b) == "bar" * 1000
51+
assert read_bool(b) is False
52+
assert read_float(b) == 0.1
53+
assert read_tag(b) == TAG_A
54+
assert read_tag(b) == TAG_SPECIAL
55+
assert read_tag(b) == TAG_B
56+
assert read_int(b) == 1
57+
assert read_int(b) == 2
58+
assert read_int(b) == 2 ** 85
59+
assert read_int(b) == 1234512344
60+
assert read_int(b) == 1234512345
61+
62+
63+
def test_buffer_int_size() -> None:
64+
for i in (-10, -9, 0, 116, 117):
65+
b = Buffer()
66+
write_int(b, i)
67+
assert len(b.getvalue()) == 1
68+
b = Buffer(b.getvalue())
69+
assert read_int(b) == i
70+
for i in (-12345, -12344, -11, 118, 12344, 12345):
71+
b = Buffer()
72+
write_int(b, i)
73+
assert len(b.getvalue()) <= 9 # sizeof(size_t) + 1
74+
b = Buffer(b.getvalue())
75+
assert read_int(b) == i
76+
77+
78+
def test_buffer_str_size() -> None:
79+
for s in ("", "a", "a" * 127):
80+
b = Buffer()
81+
write_str(b, s)
82+
assert len(b.getvalue()) == len(s) + 1
83+
b = Buffer(b.getvalue())
84+
assert read_str(b) == s

0 commit comments

Comments
 (0)