File: test_rawjson.py

package info (click to toggle)
python-rapidjson 1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,368 kB
  • sloc: cpp: 3,332; python: 1,990; makefile: 106
file content (36 lines) | stat: -rw-r--r-- 834 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
# :Project:   python-rapidjson -- Tests on RawJSON
# :Author:    Silvio Tomatis <silviot@gmail.com>
# :License:   MIT License
# :Copyright: © 2018 Silvio Tomatis
# :Copyright: © 2018, 2020 Lele Gaifax
#

import pytest

import rapidjson as rj


def test_instantiation_positional():
    value = 'a string'
    raw = rj.RawJSON(value)
    assert raw.value == value


def test_instantiation_named():
    value = 'a string'
    raw = rj.RawJSON(value=value)
    assert raw.value == value


def test_only_bytes_allowed():
    with pytest.raises(TypeError):
        rj.RawJSON(b'A bytes string')
    with pytest.raises(TypeError):
        rj.RawJSON({})
    with pytest.raises(TypeError):
        rj.RawJSON(None)


def test_mix_preserialized():
    assert rj.dumps({'a': rj.RawJSON('{1 : 2}')}) == '{"a":{1 : 2}}'