Skip to content

Commit f81221c

Browse files
authored
chore: added tests for generation scripts (#99)
1 parent de03667 commit f81221c

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: Install
7676
run: python -m playwright install
7777
- name: Test
78-
run: pytest -vv --browser=${{ matrix.browser }} --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.browser }}.xml --cov=playwright --cov-report xml
78+
run: pytest -vv --browser=${{ matrix.browser }} --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.browser }}.xml --cov=playwright --cov=scripts --cov-report xml
7979
- name: Coveralls
8080
run: coveralls
8181
env:

buildbots/test-sync-generation.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#!/bin/bash
22

3-
newfile="sync_api.py"
4-
oldfile="playwright/sync_api.py"
3+
function assert_script {
4+
newfile="$2"
5+
oldfile="playwright/$2"
6+
echo "Testing $newfile against $oldfile"
57

6-
python scripts/generate_sync_api.py > $newfile
8+
python $1 > $newfile
79

8-
pre-commit run --files $newfile
10+
pre-commit run --files $newfile
911

10-
cmp $oldfile $newfile
11-
exit_code=$?
12+
cmp $oldfile $newfile
13+
exit_code=$?
14+
rm $newfile
15+
return $exit_code
16+
}
1217

13-
rm $newfile
14-
15-
exit $exit_code
18+
assert_script "scripts/generate_sync_api.py" "sync_api.py"
19+
assert_script "scripts/generate_async_api.py" "async_api.py"

playwright/transport.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,6 @@ def send(self, message: Dict) -> None:
7171
if "DEBUGP" in os.environ: # pragma: no cover
7272
print("\x1b[32mSEND>\x1b[0m", json.dumps(message, indent=2))
7373
data = bytes(msg, "utf-8")
74-
self._output.write(len(data).to_bytes(4, byteorder="little", signed=False))
75-
self._output.write(data)
74+
self._output.write(
75+
len(data).to_bytes(4, byteorder="little", signed=False) + data
76+
)

tests/test_generation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
from io import StringIO
3+
from unittest.mock import patch
4+
5+
import pytest
6+
7+
CAN_RUN_GENERATION_SCRIPT = sys.version_info >= (3, 8)
8+
9+
if CAN_RUN_GENERATION_SCRIPT:
10+
from scripts.generate_async_api import main as generate_async_api
11+
from scripts.generate_sync_api import main as generate_sync_api
12+
13+
14+
@pytest.mark.skipif(
15+
not CAN_RUN_GENERATION_SCRIPT, reason="requires python3.8 or higher"
16+
)
17+
def test_generate_sync_api():
18+
with patch("sys.stdout", new_callable=StringIO):
19+
generate_sync_api()
20+
21+
22+
@pytest.mark.skipif(
23+
not CAN_RUN_GENERATION_SCRIPT, reason="requires python3.8 or higher"
24+
)
25+
def test_generate_async_api():
26+
with patch("sys.stdout", new_callable=StringIO):
27+
generate_async_api()

0 commit comments

Comments
 (0)