Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
56 lines (30 loc) · 974 Bytes

File metadata and controls

56 lines (30 loc) · 974 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Test the tutorial from the documentation."""
# pylint: disable=invalid-name
from dataclasses import dataclass
import pytest # type: ignore
from typeclasses.json import to_json
@dataclass
class Person:
name: str
@to_json.instance(Person)
def _to_json_person(person):
return f'{{"name":{to_json(person.name)}}}'
def test_str():
assert to_json('hello') == '"hello"'
def test_int():
assert to_json(100) == '100'
def test_float():
assert to_json(3.14) == '3.14'
def test_ints():
assert to_json([1, 2, 3]) == '[1,2,3]'
def test_protocol_order():
assert to_json({'x': 1, 'y': 2}) == '{"x":1,"y":2}'
def test_persons():
assert to_json([Person(name='John')]) == '[{"name":"John"}]'
def test_missing_instance():
with pytest.raises(NotImplementedError):
to_json(object())
def test_name():
assert to_json.__name__ == 'to_json'
def test_docstring():
assert to_json.__doc__ == 'Serialize a value to JSON.'
Morty Proxy This is a proxified and sanitized view of the page, visit original site.