nanofuzz-runtime 0.3.9__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,11 +38,7 @@ bower_components
38
38
  .lock-wscript
39
39
 
40
40
  # Compiled binary addons (https://nodejs.org/api/addons.html)
41
- build/Release
42
- build/dist
43
- build/extension
44
- build/ui
45
- build/workers
41
+ build/
46
42
 
47
43
  # Dependency directories
48
44
  node_modules/
@@ -120,6 +116,7 @@ dist
120
116
  /telemetry
121
117
 
122
118
  # Python residue
119
+ /.venv/
123
120
  __pycache__/
124
121
 
125
122
  # direnv files
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Penrose
3
+ Copyright (c) 2021-2026 Penrose
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: nanofuzz-runtime
3
- Version: 0.3.9
3
+ Version: 0.4.0
4
4
  Summary: Runtime support and types for NaNofuzz
5
5
  Project-URL: Homepage, https://github.com/nanofuzz/nanofuzz
6
6
  Project-URL: Repository, https://github.com/nanofuzz/nanofuzz
@@ -0,0 +1,43 @@
1
+ """Synchronize package metadata before building the Python runtime."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import shutil
7
+ import tomllib
8
+ from pathlib import Path
9
+
10
+
11
+ PACKAGE_DIR = Path(__file__).resolve().parent
12
+ REPOSITORY_ROOT = PACKAGE_DIR.parents[2]
13
+
14
+
15
+ def _release_version(version: str) -> str:
16
+ """Return the major, minor, and patch portion used by the npm runtime check."""
17
+ return version.split("-", 1)[0]
18
+
19
+
20
+ def sync_package_metadata(
21
+ repository_root: Path = REPOSITORY_ROOT,
22
+ package_dir: Path = PACKAGE_DIR,
23
+ ) -> None:
24
+ """Verify package versions and copy the repository license into the package."""
25
+ root_package = json.loads((repository_root / "package.json").read_text())
26
+ with (package_dir / "pyproject.toml").open("rb") as pyproject_file:
27
+ python_package = tomllib.load(pyproject_file)
28
+
29
+ root_version = _release_version(root_package["version"])
30
+ python_version = _release_version(python_package["project"]["version"])
31
+ if python_version != root_version:
32
+ raise RuntimeError(
33
+ "Package versions are not the same! "
34
+ f"Package: {root_version}; Python runtime: {python_version}"
35
+ )
36
+
37
+ shutil.copyfile(repository_root / "LICENSE", package_dir / "LICENSE")
38
+ print("Package versions match")
39
+ print("Copied repository license")
40
+
41
+
42
+ if __name__ == "__main__":
43
+ sync_package_metadata()
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nanofuzz-runtime"
7
- version = "0.3.9"
7
+ version = "0.4.0"
8
8
  description = "Runtime support and types for NaNofuzz"
9
9
  readme = "README.md"
10
10
  authors = [
@@ -30,4 +30,7 @@ Repository = "https://github.com/nanofuzz/nanofuzz"
30
30
  "Source Code" = "https://github.com/nanofuzz/nanofuzz/packages/runtime/python"
31
31
 
32
32
  [tool.hatch.build.targets.wheel]
33
- packages = ["src/nanofuzz-runtime"]
33
+ packages = ["src/nanofuzz_runtime"]
34
+
35
+ [tool.pytest.ini_options]
36
+ pythonpath = ["src"]
@@ -0,0 +1,25 @@
1
+ from typing import Any, Literal, List, Optional, TypedDict
2
+
3
+
4
+ FuzzTestResult = TypedDict('FuzzTestResult', {
5
+ 'in': List[Any], 'out': Any, 'exception': bool, 'timeout': bool})
6
+
7
+
8
+ class UnsatisfiedAssumption(Exception):
9
+ """Exception raised when a test input assumption is not satisfied."""
10
+ pass
11
+
12
+
13
+ def assume(condition: Any, message: Optional[str] = None) -> Literal[True]:
14
+ """
15
+ Evaluates condition for truthiness. If condition is truthy, returns True.
16
+ If condition is falsy, raises UnsatisfiedAssumption to skip the test input.
17
+
18
+ Optional message parameter provides an explanation for why the condition failed.
19
+ """
20
+ if not condition:
21
+ raise UnsatisfiedAssumption(message or "Unsatisfied assumption")
22
+ return True
23
+
24
+
25
+ __all__ = ["FuzzTestResult", "UnsatisfiedAssumption", "assume"]
@@ -0,0 +1,18 @@
1
+ import pytest
2
+ from nanofuzz_runtime import UnsatisfiedAssumption, assume
3
+
4
+
5
+ def test_assume_truthy():
6
+ assert assume(True) is True
7
+ assert assume(1, "should pass") is True
8
+ assert assume([1, 2, 3]) is True
9
+
10
+
11
+ def test_assume_falsy_without_message():
12
+ with pytest.raises(UnsatisfiedAssumption, match="Unsatisfied assumption"):
13
+ assume(False)
14
+
15
+
16
+ def test_assume_falsy_with_message():
17
+ with pytest.raises(UnsatisfiedAssumption, match="not == 0"):
18
+ assume(False, "not == 0")
@@ -0,0 +1,44 @@
1
+ import importlib.util
2
+ import json
3
+ from pathlib import Path
4
+
5
+ import pytest
6
+
7
+
8
+ SCRIPT_PATH = Path(__file__).parents[1] / "prebuild.py"
9
+ SPEC = importlib.util.spec_from_file_location("python_runtime_prebuild", SCRIPT_PATH)
10
+ assert SPEC is not None and SPEC.loader is not None
11
+ PREBUILD = importlib.util.module_from_spec(SPEC)
12
+ SPEC.loader.exec_module(PREBUILD)
13
+
14
+
15
+ def _write_package_files(
16
+ root: Path, package: Path, root_version: str, package_version: str
17
+ ):
18
+ root.mkdir()
19
+ package.mkdir(parents=True)
20
+ (root / "package.json").write_text(json.dumps({"version": root_version}))
21
+ (root / "LICENSE").write_text("current license\n")
22
+ (package / "pyproject.toml").write_text(
23
+ f'[project]\nversion = "{package_version}"\n'
24
+ )
25
+
26
+
27
+ def test_sync_package_metadata_copies_license(tmp_path):
28
+ root = tmp_path / "repository"
29
+ package = root / "packages" / "runtime" / "python"
30
+ _write_package_files(root, package, "1.2.3-beta.1", "1.2.3")
31
+ (package / "LICENSE").write_text("stale license\n")
32
+
33
+ PREBUILD.sync_package_metadata(root, package)
34
+
35
+ assert (package / "LICENSE").read_text() == "current license\n"
36
+
37
+
38
+ def test_sync_package_metadata_rejects_version_mismatch(tmp_path):
39
+ root = tmp_path / "repository"
40
+ package = root / "packages" / "runtime" / "python"
41
+ _write_package_files(root, package, "1.2.3", "1.2.4")
42
+
43
+ with pytest.raises(RuntimeError, match="Package versions are not the same"):
44
+ PREBUILD.sync_package_metadata(root, package)
@@ -1,5 +0,0 @@
1
- from typing import Any, Literal, List, TypedDict
2
-
3
-
4
- FuzzTestResult = TypedDict('FuzzTestResult', {
5
- 'in': List[Any], 'out': Any, 'exception': bool, 'timeout': bool})