File: test_pathlib.py

package info (click to toggle)
json-tricks 3.17.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 372 kB
  • sloc: python: 2,319; makefile: 159
file content (39 lines) | stat: -rw-r--r-- 742 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This tests Paths, which need pathlib.
"""

from pathlib import Path

from json_tricks import dumps, loads


# These paths are not necessarily actual paths that exist, but are sufficient
# for testing to ensure that we can properly serialize/deserialize them.
PATHS = [
	Path(),
	Path('c:/users/pyjson_tricks'),
	Path('/home/users/pyjson_tricks'),
	Path('../'),
	Path('..'),
	Path('./'),
	Path('.'),
	Path('test_pathlib.py'),
	Path('/home/users/pyjson_tricks/test_pathlib.py'),
]


def test_path():
	json = dumps(PATHS)
	back = loads(json)
	assert PATHS == back

	for orig, bck in zip(PATHS, back):
		assert orig == bck

	txt = '{"__pathlib__": "."}'
	obj = loads(txt)
	assert obj == Path()