mirror of
https://github.com/openwrt/packages.git
synced 2026-04-15 19:02:09 +00:00
python-schema: bump to 0.7.8
Changes since 0.7.5: - Fix handling of Optional keys with default values - Improve error messages for nested schema failures - Various bug fixes and compatibility improvements Also add test.sh to verify version and data validation API. Link: https://github.com/keleshev/schema/blob/master/CHANGELOG.rst Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>
This commit is contained in:
committed by
Alexandru Ardelean
parent
16b0426b8e
commit
b07af9a38a
@@ -5,12 +5,12 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=python-schema
|
||||
PKG_VERSION:=0.7.5
|
||||
PKG_VERSION:=0.7.8
|
||||
PKG_RELEASE:=1
|
||||
PKG_MAINTAINER:=Josef Schlehofer <pepe.schlehofer@gmail.com>
|
||||
|
||||
PYPI_NAME:=schema
|
||||
PKG_HASH:=f06717112c61895cabc4707752b88716e8420a8819d71404501e114f91043197
|
||||
PKG_HASH:=e86cc08edd6fe6e2522648f4e47e3a31920a76e82cce8937535422e310862ab5
|
||||
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_LICENSE_FILES:=LICENSE-MIT
|
||||
|
||||
40
lang/python/python-schema/test.sh
Executable file
40
lang/python/python-schema/test.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$1" = "python3-schema" ] || exit 0
|
||||
|
||||
python3 - << EOF
|
||||
import sys
|
||||
import schema as sc
|
||||
|
||||
if sc.__version__ != "$2":
|
||||
print("Wrong version: " + sc.__version__)
|
||||
sys.exit(1)
|
||||
|
||||
from schema import Schema, SchemaError, Optional, And, Or
|
||||
|
||||
# Basic type validation
|
||||
s = Schema(int)
|
||||
assert s.validate(42) == 42
|
||||
try:
|
||||
s.validate("not an int")
|
||||
sys.exit(1)
|
||||
except SchemaError:
|
||||
pass
|
||||
|
||||
# Dict schema
|
||||
s = Schema({"name": str, "age": And(int, lambda n: n > 0)})
|
||||
data = s.validate({"name": "Alice", "age": 30})
|
||||
assert data["name"] == "Alice"
|
||||
assert data["age"] == 30
|
||||
|
||||
# Optional key
|
||||
s = Schema({"key": str, Optional("opt"): int})
|
||||
assert s.validate({"key": "val"}) == {"key": "val"}
|
||||
|
||||
# Or
|
||||
s = Schema(Or(int, str))
|
||||
assert s.validate(1) == 1
|
||||
assert s.validate("x") == "x"
|
||||
|
||||
sys.exit(0)
|
||||
EOF
|
||||
Reference in New Issue
Block a user