Skip to content

Commit

Permalink
chore: Add Justfile
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Dygalo <[email protected]>
  • Loading branch information
Stranger6667 committed Sep 15, 2024
1 parent 299b504 commit ff285d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ To open an issue, [follow this link](https://github.com/Stranger6667/jsonschema-

When making a feature request, please make it clear what problem you intend to solve with the feature and provide some ideas on how to implement it.

**NOTE**: Many commands are available via a [Justfile](https://github.com/casey/just) located in the root of the repository.

## Running the Tests

The tests in jsonschema depend on the [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite). Before running the tests, you need to download the suite.
Expand Down
23 changes: 23 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
default:
@just --list

fuzz TARGET:
cargo +nightly fuzz run --release {{TARGET}} fuzz/corpus/{{TARGET}} fuzz/seeds/{{TARGET}} -- -dict=fuzz/dict

lint-rs:
cargo +nightly fmt --all
cargo clippy --all-features --all-targets

lint-py:
uvx ruff check crates/jsonschema-py/python crates/jsonschema-py/tests-py crates/jsonschema-py/benches
uvx ruff check --select I --fix crates/jsonschema-py/python crates/jsonschema-py/tests-py crates/jsonschema-py/benches
uvx mypy crates/jsonschema-py/python

lint: lint-rs lint-py

test-py *FLAGS:
uvx --with="crates/jsonschema-py[tests]" pytest crates/jsonschema-py/tests-py -rs {{FLAGS}}

bench-py *FLAGS:
uvx --with="crates/jsonschema-py[bench]" pytest crates/jsonschema-py/benches/bench.py --benchmark-columns=min {{FLAGS}}

6 changes: 5 additions & 1 deletion crates/jsonschema-py/benches/bench.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import sys
from contextlib import suppress
from pathlib import Path

import fastjsonschema
import jsonschema
Expand All @@ -12,6 +13,9 @@
jsonschema_rs = None


BENCHMARK_DATA = Path(__file__).parent.parent.parent / "benchmark/data"


def load_json(filename):
with open(filename) as fd:
return json.load(fd)
Expand All @@ -23,7 +27,7 @@ def load_json_str(filename):


def load_from_benches(filename, loader=load_json):
return loader(f"../benchmark/data/{filename}")
return loader(BENCHMARK_DATA / filename)


OPENAPI = load_from_benches("openapi.json")
Expand Down
2 changes: 1 addition & 1 deletion crates/jsonschema-py/python/jsonschema_rs/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Any, Callable, TypeVar
from collections.abc import Iterator
from typing import Any, Callable, TypeVar

_SchemaT = TypeVar("_SchemaT", bool, dict[str, Any])
_FormatFunc = TypeVar("_FormatFunc", bound=Callable[[str], bool])
Expand Down
7 changes: 4 additions & 3 deletions crates/jsonschema-py/tests-py/test_suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import socket
import subprocess
import sys
from pathlib import Path
from time import sleep
from urllib.parse import urlparse

import pytest

import jsonschema_rs

TEST_SUITE_PATH = "../jsonschema/tests/suite"
TEST_SUITE_PATH = Path(__file__).parent.parent.parent / "jsonschema/tests/suite"
EXPONENTIAL_BASE = 2
JITTER = (0.0, 0.5)
INITIAL_RETRY_DELAY = 0.05
Expand Down Expand Up @@ -41,7 +42,7 @@ def wait_until_responsive(url: str, retries: int = MAX_WAITING_RETRIES, delay: f

@pytest.fixture(scope="session", autouse=True)
def mock_server():
process = subprocess.Popen(args=[sys.executable, f"{TEST_SUITE_PATH}/bin/jsonschema_suite", "serve"])
process = subprocess.Popen(args=[sys.executable, TEST_SUITE_PATH / "bin/jsonschema_suite", "serve"])
wait_until_responsive("http://127.0.0.1:1234")
try:
yield
Expand Down Expand Up @@ -89,7 +90,7 @@ def pytest_generate_tests(metafunc):
filename,
)
for draft in SUPPORTED_DRAFTS
for root, _, files in os.walk(f"{TEST_SUITE_PATH}/tests/draft{draft}/")
for root, _, files in os.walk(TEST_SUITE_PATH / f"tests/draft{draft}/")
for filename in files
for block in load_file(os.path.join(root, filename))
for test in block["tests"]
Expand Down

0 comments on commit ff285d5

Please sign in to comment.