-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathtest_parser.py
37 lines (27 loc) · 931 Bytes
/
test_parser.py
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
from __future__ import unicode_literals
import collections
import sys
if sys.version_info < (2, 7):
from StringIO import StringIO
else:
from io import StringIO
import pytest
import pytoml as toml
def test_name_of_fileobj_is_used_in_errors():
source = StringIO("[")
source.name = "<source>"
error = pytest.raises(toml.TomlError, lambda: toml.load(source))
assert error.value.filename == "<source>"
def test_when_fileobj_has_no_name_attr_then_repr_of_fileobj_is_used_in_errors():
source = StringIO("[")
error = pytest.raises(toml.TomlError, lambda: toml.load(source))
assert error.value.filename == repr(source)
def test_object_pairs_hook():
source = StringIO(u"""\
[x.a]
[x.b]
[x.c]
""")
d = toml.load(source, object_pairs_hook=collections.defaultdict)
assert isinstance(d, collections.defaultdict)
assert isinstance(d['x'], collections.defaultdict)