mirror of
https://github.com/openwrt/packages.git
synced 2026-10-13 03:37:43 +04:00
python-marshmallow: add test script
Add a CI test.sh exercising basic package functionality. Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>
This commit is contained in:
1 parent
edc5f6e971
commit
fbd7c9fabb
1 file changed
+24
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ "$1" = python3-marshmallow ] || exit 0
|
||||
|
||||
python3 - << 'EOF'
|
||||
|
||||
from marshmallow import Schema, fields, ValidationError
|
||||
|
||||
# Round-trip a schema: dump a dict, load and type-coerce it back, then confirm
|
||||
# a missing required field is rejected with ValidationError.
|
||||
class UserSchema(Schema):
|
||||
name = fields.Str(required=True)
|
||||
age = fields.Int()
|
||||
|
||||
s = UserSchema()
|
||||
assert s.dump({"name": "ow", "age": 3}) == {"name": "ow", "age": 3}
|
||||
assert s.load({"name": "ow", "age": "5"}) == {"name": "ow", "age": 5}
|
||||
try:
|
||||
s.load({"age": 1})
|
||||
raise SystemExit("required field not enforced")
|
||||
except ValidationError:
|
||||
pass
|
||||
|
||||
EOF
|
||||
Reference in new issue
Block a user