-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's fast and seems to be the direction Python projects are going. We also now spin up a server for each test, for better isolation. This required some changes to the piping on the server side, to allow us to use port `0` to get the OS to assign an available port. This means we need to compute the connection string _after_ we have bound the port, so that the connection string contains the actual bound port and not port `0`. This also sets up Python tests to run in CI/CD, but only when the Python code changes (at least for now).
- Loading branch information
Showing
11 changed files
with
397 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run Python tests | ||
|
||
on: | ||
pull_request: | ||
branches: [ "main" ] | ||
paths: | ||
- "python/**" | ||
- ".github/workflows/python-tests.yml" | ||
|
||
jobs: | ||
uv-example: | ||
name: python | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: ./python | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Install uv | ||
uses: astral-sh/setup-uv@v4 | ||
|
||
- name: Set up Python | ||
run: uv python install | ||
|
||
- name: Install the project | ||
run: uv sync --all-extras --dev | ||
|
||
- name: Run tests | ||
run: uv run pytest tests | ||
|
||
- name: Check formatting | ||
run: uv run ruff format --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ var/ | |
.pytest_cache/ | ||
.venv/ | ||
.ruff_cache/ | ||
test-out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import subprocess | ||
import signal | ||
from typing import Optional | ||
from os import path, environ | ||
import json | ||
import time | ||
import re | ||
|
||
|
||
BASE_DIR = path.join(path.dirname(__file__), "..", "..", "crates", "y-sweet") | ||
|
||
|
||
class Server: | ||
@staticmethod | ||
def build(): | ||
subprocess.run( | ||
["cargo", "build"], | ||
cwd=BASE_DIR, | ||
check=True, | ||
) | ||
|
||
def __init__(self, test_id: str): | ||
self.data_dir = path.join(path.dirname(__file__), "..", "test-out", test_id) | ||
self.process = subprocess.Popen( | ||
["cargo", "run", "--", "serve", self.data_dir, "--port", "0"], | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
cwd=BASE_DIR, | ||
env={"Y_SWEET_LOG_JSON": "true", **environ}, | ||
text=True, | ||
bufsize=1, | ||
) | ||
|
||
# Wait for connection string in the output | ||
while self.process.poll() is None: | ||
line = self.process.stdout.readline() | ||
print("here", line) | ||
match = re.search(r"CONNECTION_STRING=([^ ]+)", line) | ||
if match: | ||
self.connection_string = match.group(1) | ||
break | ||
|
||
if not self.connection_string: | ||
raise RuntimeError("Server failed to start and provide connection string") | ||
|
||
def shutdown(self): | ||
if self.process: | ||
self.process.terminate() | ||
try: | ||
self.process.wait(timeout=5) | ||
except subprocess.TimeoutExpired: | ||
self.process.kill() | ||
|
||
# Clean up the process | ||
self.process = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.