Files
packages/lang/python/python-jmespath/test.sh
T
Alexandru Ardelean e7aff35e97 python-jmespath: install jp as a non-byte-compiled command
Upstream ships its jp command-line tool as a plain "jp.py" script. Under
that name OpenWrt byte-compiles it into a non-executable /usr/bin/jp.pyc
(and the -src package keeps a "#!/usr/bin/env python" jp.py, which has no
interpreter on OpenWrt), so it fails the CI generic executable check.

Install it as /usr/bin/jp instead: the missing .py extension stops it from
being byte-compiled and Python3/FixShebang rewrites the shebang to
/usr/bin/python3. Add a test-version.sh override since jp takes a required
expression argument and has no version flag for the generic check to probe.

Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>
2026-06-09 09:27:30 +03:00

48 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
[ "$1" = "python3-jmespath" ] || exit 0
python3 - << EOF
import sys
import jmespath
if jmespath.__version__ != "$2":
print("Wrong version: " + jmespath.__version__)
sys.exit(1)
# Basic field access
data = {"name": "Alice", "age": 30}
assert jmespath.search("name", data) == "Alice"
assert jmespath.search("age", data) == 30
assert jmespath.search("missing", data) is None
# Nested access
data = {"a": {"b": {"c": 42}}}
assert jmespath.search("a.b.c", data) == 42
# Array indexing and slicing
data = {"items": [1, 2, 3, 4, 5]}
assert jmespath.search("items[0]", data) == 1
assert jmespath.search("items[-1]", data) == 5
assert jmespath.search("items[1:3]", data) == [2, 3]
# Wildcard and filter
data = {"people": [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]}
assert jmespath.search("people[].name", data) == ["Alice", "Bob"]
assert jmespath.search("people[?age > \`28\`].name", data) == ["Alice"]
# Pre-compiled expression
expr = jmespath.compile("a.b")
assert expr.search({"a": {"b": 99}}) == 99
sys.exit(0)
EOF
[ $? -eq 0 ] || exit 1
# Verify the jp command-line tool
result=$(echo '{"a": {"b": 42}}' | jp 'a.b')
[ "$result" = "42" ] || {
echo "jp returned '$result', expected 42"
exit 1
}