Debian Codegraph @

test-crates/pyo3-mixed/check_installed/check_installed.py

raw
1 #!/usr/bin/env python3
2 import json
3 import os.path
4 import platform
5 import sys
6 from pathlib import Path
7 from subprocess import check_output
8
9 from boltons.strutils import slugify
10
11 import pyo3_mixed
12
13 assert pyo3_mixed.get_42() == 42
14 assert slugify("First post! Hi!!!!~1 ") == "first_post_hi_1"
15
16 script_name = "print_cli_args"
17 args = ["a", "b", "c"]
18 [rust_args, python_args] = check_output([script_name, *args], text=True).splitlines()
19 # The rust vec debug format is also valid json
20 rust_args = json.loads(rust_args)
21 python_args = json.loads(python_args)
22
23 # On alpine/musl, rust_args is empty so we skip all tests on musl
24 if len(rust_args) > 0:
25 # On linux we get sys.executable, windows resolve the path and mac os gives us a third
26 # path (
27 # {prefix}/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python
28 # vs
29 # {prefix}/Python.framework/Versions/3.10/bin/python3.10
30 # on cirrus ci)
31 # On windows, cpython resolves while pypy doesn't.
32 # The script for cpython is actually a distinct file from the system interpreter for
33 # windows and mac
34 if platform.system() == "Linux":
35 assert os.path.samefile(rust_args[0], sys.executable), (
36 rust_args,
37 sys.executable,
38 os.path.realpath(rust_args[0]),
39 os.path.realpath(sys.executable),
40 )
41
42 # Windows can't decide if it's with or without .exe, FreeBSB just doesn't work for some reason
43 if platform.system() in ["Darwin", "Linux"]:
44 # Unix venv layout (and hopefully also on more exotic platforms)
45 print_cli_args = str(Path(sys.prefix).joinpath("bin").joinpath(script_name))
46 assert rust_args[1] == print_cli_args, (rust_args, print_cli_args)
47 assert python_args[0] == print_cli_args, (python_args, print_cli_args)
48
49 # FreeBSB just doesn't work for some reason
50 if platform.system() in ["Darwin", "Linux", "Windows"]:
51 # Rust contains the python executable as first argument but python does not
52 assert rust_args[2:] == args, rust_args
53 assert python_args[1:] == args, python_args
54
55 print("SUCCESS")