testing-files-generator 0.6.0rc1__py3-none-any.whl
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.
- testing_files_generator/__init__.py +37 -0
- testing_files_generator/__main__.py +49 -0
- testing_files_generator/_binary.py +111 -0
- testing_files_generator/_fileset.py +678 -0
- testing_files_generator/_run.py +105 -0
- testing_files_generator/_testfile.py +158 -0
- testing_files_generator/py.typed +0 -0
- testing_files_generator/pytest_plugin.py +41 -0
- testing_files_generator-0.6.0rc1.dist-info/METADATA +494 -0
- testing_files_generator-0.6.0rc1.dist-info/RECORD +13 -0
- testing_files_generator-0.6.0rc1.dist-info/WHEEL +4 -0
- testing_files_generator-0.6.0rc1.dist-info/entry_points.txt +6 -0
- testing_files_generator-0.6.0rc1.dist-info/licenses/LICENSE +373 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
|
|
5
|
+
"""Real files of exact sizes and formats for your tests, and what the system under test should do with each one.
|
|
6
|
+
|
|
7
|
+
from testing_files_generator import file_set
|
|
8
|
+
|
|
9
|
+
uploads = file_set(preset="upload-validation", options={"limit": "2mb", "bulk": 0})
|
|
10
|
+
|
|
11
|
+
@pytest.mark.parametrize("file", uploads.params())
|
|
12
|
+
def test_upload(file):
|
|
13
|
+
... # hand file.path() to your system
|
|
14
|
+
file.check("accept" if taken else "reject")
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from ._binary import binary_path
|
|
18
|
+
from ._fileset import FileSet, UnfinishedSetWarning, file_set
|
|
19
|
+
from ._run import TfgError
|
|
20
|
+
from ._testfile import ExpectationError, TestFile
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
24
|
+
|
|
25
|
+
__version__ = version("testing-files-generator")
|
|
26
|
+
except PackageNotFoundError: # run from the repository, not installed
|
|
27
|
+
__version__ = "0.0.0.dev0"
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"ExpectationError",
|
|
31
|
+
"FileSet",
|
|
32
|
+
"TestFile",
|
|
33
|
+
"TfgError",
|
|
34
|
+
"UnfinishedSetWarning",
|
|
35
|
+
"binary_path",
|
|
36
|
+
"file_set",
|
|
37
|
+
]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
|
|
5
|
+
"""tfg, and python -m testing_files_generator, run the binary this package installed.
|
|
6
|
+
|
|
7
|
+
The same arguments, the same streams and the same exit code, so a script
|
|
8
|
+
cannot tell it from tfg run directly.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import signal
|
|
15
|
+
import subprocess
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from ._binary import binary_path
|
|
19
|
+
from ._run import not_started
|
|
20
|
+
|
|
21
|
+
# RUNTIME in docs/CLI.md section 3 - the tool could not do its work, and the
|
|
22
|
+
# arguments were never looked at.
|
|
23
|
+
_CANNOT_RUN = 1
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def main() -> int:
|
|
27
|
+
try:
|
|
28
|
+
binary = binary_path()
|
|
29
|
+
except RuntimeError as err:
|
|
30
|
+
print(f"tfg: {err}", file=sys.stderr)
|
|
31
|
+
return _CANNOT_RUN
|
|
32
|
+
args = [binary, *sys.argv[1:]]
|
|
33
|
+
try:
|
|
34
|
+
if sys.platform != "win32":
|
|
35
|
+
# tfg takes this process's place, so signals and the exit code are
|
|
36
|
+
# its own with nothing in between.
|
|
37
|
+
os.execv(binary, args)
|
|
38
|
+
# Windows has no such thing. A Ctrl+C in a console reaches tfg as well
|
|
39
|
+
# as this process, so this one waits for tfg to stop the way it stops
|
|
40
|
+
# on its own, and its exit code is the one a script sees.
|
|
41
|
+
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
42
|
+
return subprocess.call(args)
|
|
43
|
+
except OSError as err:
|
|
44
|
+
print(f"tfg: {not_started(binary, err)}", file=sys.stderr)
|
|
45
|
+
return _CANNOT_RUN
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
sys.exit(main())
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
|
|
5
|
+
"""Where the tfg binary this package runs is."""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
import platform as _platform
|
|
11
|
+
import sys
|
|
12
|
+
from collections.abc import Mapping
|
|
13
|
+
|
|
14
|
+
# The systems a release builds a command line for, named as Node names them so
|
|
15
|
+
# the list reads the same here and in the npm package. A guard holds it to the
|
|
16
|
+
# list of targets in .github/workflows/release.yml, and the release build in
|
|
17
|
+
# release/assemble.py makes one wheel with the binary for each of them. Intel
|
|
18
|
+
# Macs are on neither list, by the owner's decision of 2026-08-20.
|
|
19
|
+
PLATFORMS = ("win32 x64", "win32 arm64", "linux x64", "linux arm64", "darwin arm64")
|
|
20
|
+
|
|
21
|
+
# How a machine name reads as an architecture. Windows says AMD64 and ARM64,
|
|
22
|
+
# Linux x86_64 and aarch64, macOS x86_64 and arm64.
|
|
23
|
+
_ARCH = {"amd64": "x64", "x86_64": "x64", "arm64": "arm64", "aarch64": "arm64"}
|
|
24
|
+
|
|
25
|
+
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def binary_in(system: str) -> str:
|
|
29
|
+
"""Where the binary sits inside the package's bin directory, as the release archive lays it out.
|
|
30
|
+
|
|
31
|
+
On macOS that is inside the app the release signed and notarised: its
|
|
32
|
+
signature covers the app's Info.plist, and macOS kills the binary taken out
|
|
33
|
+
on its own (exit 137, measured 2026-11-09 on macOS 27.2 -
|
|
34
|
+
docs/NPM-PUBLISH-2026-11-09.md).
|
|
35
|
+
"""
|
|
36
|
+
if system == "win32":
|
|
37
|
+
return "tfg.exe"
|
|
38
|
+
if system == "darwin":
|
|
39
|
+
return "tfg.app/Contents/MacOS/tfg"
|
|
40
|
+
return "tfg"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def system_name(system: str | None = None, machine: str | None = None) -> str:
|
|
44
|
+
"""This system as PLATFORMS names one, such as linux x64."""
|
|
45
|
+
system = sys.platform if system is None else system
|
|
46
|
+
if system.startswith("linux"):
|
|
47
|
+
system = "linux"
|
|
48
|
+
machine = (_platform.machine() if machine is None else machine).lower()
|
|
49
|
+
return f"{system} {_ARCH.get(machine, machine)}"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _why_none(system: str, bits: int) -> str:
|
|
53
|
+
# Why pip took the wheel without a binary on a system that has one. The
|
|
54
|
+
# wheel pip takes is decided by the Python that installs it, and a 32-bit
|
|
55
|
+
# Python on 64-bit Windows is matched to wheels for 32-bit Python. On
|
|
56
|
+
# macOS the wheel with the binary also names the oldest macOS the binary
|
|
57
|
+
# runs on, and pip passes it over on an older one.
|
|
58
|
+
if bits == 32:
|
|
59
|
+
return "this Python is 32-bit, and the binary comes in wheels for 64-bit Python"
|
|
60
|
+
if system == "darwin":
|
|
61
|
+
return ("pip found no wheel with a binary for this version of macOS. The name of the wheel for macOS "
|
|
62
|
+
"says the oldest version the binary runs on, such as macosx_13_0 for macOS 13")
|
|
63
|
+
return "pip found no wheel with a binary for this system"
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# A Python made for Intel runs on a Mac with Apple silicon under Rosetta, and
|
|
67
|
+
# says it is on an Intel Mac. A Python made for Apple silicon gets the wheel
|
|
68
|
+
# with the binary.
|
|
69
|
+
_ROSETTA = (" If this Mac has Apple silicon, this Python runs under Rosetta - install the package with a "
|
|
70
|
+
"Python made for Apple silicon.")
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def binary_path(*, env: Mapping[str, str] | None = None, system: str | None = None,
|
|
74
|
+
machine: str | None = None, bits: int | None = None, here: str | None = None) -> str:
|
|
75
|
+
"""The tfg binary this package runs.
|
|
76
|
+
|
|
77
|
+
TFG_BINARY comes first and is taken as given - a tfg installed another way,
|
|
78
|
+
or one built from the repository. PATH is never searched: a different tfg
|
|
79
|
+
found there would answer with its own version and say nothing about it.
|
|
80
|
+
Everything is passed in so the tests can ask about a system they are not on.
|
|
81
|
+
"""
|
|
82
|
+
env = os.environ if env is None else env
|
|
83
|
+
given = env.get("TFG_BINARY")
|
|
84
|
+
if given:
|
|
85
|
+
if not os.path.isfile(given):
|
|
86
|
+
raise RuntimeError(f"TFG_BINARY is set to {given} and there is no file there. "
|
|
87
|
+
"Point it at a tfg binary, or unset it to use the one this package installs.")
|
|
88
|
+
return given
|
|
89
|
+
raw = sys.platform if system is None else system
|
|
90
|
+
name = system_name(raw, machine)
|
|
91
|
+
bits = (64 if sys.maxsize > 2**32 else 32) if bits is None else bits
|
|
92
|
+
here = _HERE if here is None else here
|
|
93
|
+
bin_dir = os.path.join(here, "bin")
|
|
94
|
+
found = os.path.join(bin_dir, *binary_in(name.split(" ")[0]).split("/"))
|
|
95
|
+
if os.path.isfile(found):
|
|
96
|
+
return found
|
|
97
|
+
known = ", ".join(PLATFORMS)
|
|
98
|
+
if name not in PLATFORMS:
|
|
99
|
+
raise RuntimeError(f"testing-files-generator has no binary for {name}. It comes for {known}. "
|
|
100
|
+
"On another system, run the tests in a Linux container, where pip installs the "
|
|
101
|
+
"package for Linux, or install tfg another way and set TFG_BINARY to its path."
|
|
102
|
+
+ (_ROSETTA if name == "darwin x64" else ""))
|
|
103
|
+
if not os.path.isdir(bin_dir):
|
|
104
|
+
raise RuntimeError(f"This install of testing-files-generator has no tfg binary: {_why_none(name.split(' ')[0], bits)}. "
|
|
105
|
+
f"The binary comes for {known}, each in a wheel of its own. Install the package with "
|
|
106
|
+
"a 64-bit Python made for this system, or install tfg another way and set "
|
|
107
|
+
"TFG_BINARY to its path.")
|
|
108
|
+
raise RuntimeError(f"The tfg binary of this install is not at {found}, where the package puts it. "
|
|
109
|
+
"Something removed it after the install. Install the package again with "
|
|
110
|
+
"pip install --force-reinstall testing-files-generator, or set TFG_BINARY to the path "
|
|
111
|
+
"of a tfg binary.")
|