예제 #1
0
def test_nested_dict():
    obj = {
        5: {
            'a': 3
        },
        'b': {
            'c': {
                3: 5
            }
        },
        True: False,
        None: [1, 2, 3, 4, 5],
    }
    assert dumps(obj) == \
        json.dumps(obj)
예제 #2
0
def test_none():
    assert dumps(None) == 'null'
예제 #3
0
def test_infinity():
    with pytest.raises(ValueError):
        dumps(float('inf'))
예제 #4
0
def test_wrong_type():
    with pytest.raises(TypeError):
        dumps(...)
예제 #5
0
def test_nested_dict():
    assert dumps({5: {'a': 3}, 'b': {'c': 4}}) == \
        '{"5": {"a": 3}, "b": {"c": 4}}'
예제 #6
0
def test_dict():
    assert dumps({1: 'a', 'abc': None}) == '{"1": "a", "abc": null}'
예제 #7
0
def test_list():
    assert dumps([1, 2, True, None]) == '[1, 2, true, null]'
예제 #8
0
def test_bool():
    assert dumps(True) == json.dumps(True)
예제 #9
0
def test_string():
    assert dumps('string') == '"string"'
예제 #10
0
def test_number():
    assert dumps(123) == json.dumps(123)
예제 #11
0
def test_none():
    assert dumps(None) == json.dumps(None)
예제 #12
0
def test_dict():
    assert dumps({1: 'a', 'abc': None}) == json.dumps({1: 'a', 'abc': None})
예제 #13
0
def test_list():
    assert dumps([1, 2, True, None]) == json.dumps([1, 2, True, None])
예제 #14
0
def test_nan():
    with pytest.raises(ValueError):
        dumps(float('nan'))
예제 #15
0
def test_bool():
    assert dumps(True) == 'true'
예제 #16
0
def test_number():
    assert dumps(123) == '123'
예제 #17
0
def test_string():
    assert dumps('string') == json.dumps('string')