File: test_separators.py

package info (click to toggle)
python-sdjson 0.5.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 560 kB
  • sloc: python: 1,566; makefile: 6; sh: 6
file content (64 lines) | stat: -rw-r--r-- 1,147 bytes parent folder | download
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
57
58
59
60
61
62
63
64
# stdlib
import textwrap

# 3rd party
import pytest

# this package
import sdjson


def test_separators() -> None:
	h = [
			["blorpie"],
			["whoops"],
			[],
			"d-shtaeou",
			"d-nthiouh",
			"i-vhbjkhnth",
			{"nifty": 87},
			{"field": "yes", "morefield": False},
			]

	expect = textwrap.dedent(
			"""\
    [
      [
        "blorpie"
      ] ,
      [
        "whoops"
      ] ,
      [] ,
      "d-shtaeou" ,
      "d-nthiouh" ,
      "i-vhbjkhnth" ,
      {
        "nifty" : 87
      } ,
      {
        "field" : "yes" ,
        "morefield" : false
      }
    ]"""
			)

	d1 = sdjson.dumps(h)
	d2 = sdjson.dumps(h, indent=2, sort_keys=True, separators=(" ,", " : "))

	h1 = sdjson.loads(d1)
	h2 = sdjson.loads(d2)

	assert h1 == h
	assert h2 == h
	assert d2 == expect


def test_illegal_separators() -> None:
	h = {1: 2, 3: 4}
	with pytest.raises(TypeError):
		sdjson.dumps(h, separators=(b", ", ": "))  # type: ignore[arg-type]
	with pytest.raises(TypeError):
		sdjson.dumps(h, separators=(", ", b": "))  # type: ignore[arg-type]
	with pytest.raises(TypeError):
		sdjson.dumps(h, separators=(b", ", b": "))  # type: ignore[arg-type]