mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[bazel][robotpy] Add mirror for robotpy's wpiuil and wpinet libraries (#8062)
Project import generated by Copybara. GitOrigin-RevId: 92ea93d1b47a82667044bd0af05f7fdb34d2c2c2
This commit is contained in:
71
wpiutil/src/test/python/test_json.py
Normal file
71
wpiutil/src/test/python/test_json.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from wpiutil_test.module import (
|
||||
cast_json_arg,
|
||||
cast_json_val,
|
||||
max_int64,
|
||||
min_int64,
|
||||
max_uint64,
|
||||
)
|
||||
import pytest
|
||||
import math
|
||||
|
||||
|
||||
def test_json_invalid():
|
||||
with pytest.raises(TypeError):
|
||||
cast_json_val(lambda: object())
|
||||
|
||||
|
||||
def test_json_none():
|
||||
assert cast_json_arg(None) == None
|
||||
|
||||
|
||||
def test_json_bool():
|
||||
assert cast_json_arg(True) == True
|
||||
assert cast_json_arg(False) == False
|
||||
|
||||
|
||||
def test_json_int():
|
||||
assert cast_json_arg(36) == 36
|
||||
|
||||
assert cast_json_arg(min_int64) == min_int64
|
||||
with pytest.raises(ValueError):
|
||||
cast_json_arg(min_int64 - 1)
|
||||
|
||||
assert cast_json_arg(max_int64) == max_int64
|
||||
assert cast_json_arg(max_uint64) == max_uint64
|
||||
with pytest.raises(ValueError):
|
||||
cast_json_arg(max_uint64 + 1)
|
||||
|
||||
|
||||
def test_json_float():
|
||||
assert cast_json_arg(36.37) == 36.37
|
||||
assert cast_json_arg(math.inf) == math.inf
|
||||
assert math.isnan(cast_json_arg(math.nan))
|
||||
|
||||
|
||||
def test_json_string():
|
||||
assert cast_json_arg("hi") == "hi"
|
||||
|
||||
|
||||
def test_json_list():
|
||||
v = [36, "hello", False]
|
||||
assert cast_json_arg(v) == v
|
||||
|
||||
assert cast_json_arg([]) == []
|
||||
|
||||
tv = (36, "hello", False)
|
||||
assert cast_json_arg(tv) == v
|
||||
|
||||
|
||||
def test_json_dict():
|
||||
d = {"number": 1234, "hello": "world"}
|
||||
assert cast_json_arg(d) == d
|
||||
|
||||
assert cast_json_arg({}) == {}
|
||||
|
||||
assert cast_json_arg({1: 2}) == {"1": 2}
|
||||
assert cast_json_arg({None: 2}) == {"None": 2}
|
||||
assert cast_json_arg({1.2: 2}) == {"1.2": 2}
|
||||
assert cast_json_arg({False: 2}) == {"False": 2}
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
cast_json_arg({object(): 2})
|
||||
Reference in New Issue
Block a user