Skip to content

Commit

Permalink
Introduce PyScriptTest, an helper class to write integration tests (#663
Browse files Browse the repository at this point in the history
)

This PR is about integration tests: they use playwright to load HTML pages in the browser and check that PyScript works as intended, as opposed to unit tests like the ones being introduced by #665 and #661.

The main goal of this PR is to introduce some machinery to make such tests easier to write, read and maintain, with some attention to capture enough information to produce useful error messages in case they fail in the CI.

In order to use the machinery, you need to subclass tests.support.PyScriptTest, which provides several useful API calls in the form self.xxx().

See the full description here:
#663

Co-authored-by: Mariana Meireles <marian.meireles@gmail.com>
Co-authored-by: mariana <marianameireles@protonmail.com>
  • Loading branch information
3 people committed Aug 10, 2022
1 parent bd7a203 commit 513dfe0
Show file tree
Hide file tree
Showing 8 changed files with 684 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyscriptjs/src/components/pyconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class PyodideRuntime extends Object {
for (const initializer of postInitializers_) {
await initializer();
}
console.log('===PyScript page fully initialized===');
}
}

Expand Down
16 changes: 14 additions & 2 deletions pyscriptjs/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

import pytest

from .support import Logger


@pytest.fixture(scope="session")
def logger():
return Logger()


class HTTPServer(SuperHTTPServer):
"""
Expand All @@ -23,12 +30,17 @@ def run(self):


@pytest.fixture(scope="session")
def http_server():
def http_server(logger):
class MyHTTPRequestHandler(SimpleHTTPRequestHandler):
def log_message(self, fmt, *args):
logger.log("http_server", fmt % args, color="blue")

host, port = "127.0.0.1", 8080
base_url = f"http://{host}:{port}"

# serve_Run forever under thread
server = HTTPServer((host, port), SimpleHTTPRequestHandler)
server = HTTPServer((host, port), MyHTTPRequestHandler)

thread = threading.Thread(None, server.run)
thread.start()

Expand Down

0 comments on commit 513dfe0

Please sign in to comment.