10
10
import sys
11
11
import unittest
12
12
13
- from twisted .python .filepath import FilePath
13
+ try :
14
+ from pathlib import Path
15
+ except ImportError :
16
+ from pathlib2 import Path
17
+
14
18
import attr
15
19
16
20
from jsonschema .compat import PY3
21
25
def _find_suite ():
22
26
root = os .environ .get ("JSON_SCHEMA_TEST_SUITE" )
23
27
if root is not None :
24
- return FilePath (root )
28
+ return Path (root )
25
29
26
- root = FilePath (jsonschema .__file__ ).parent (). sibling ( "json" )
27
- if not root .isdir (): # pragma: no cover
30
+ root = Path (jsonschema .__file__ ).parent . parent / "json"
31
+ if not root .is_dir (): # pragma: no cover
28
32
raise ValueError (
29
33
(
30
34
"Can't find the JSON-Schema-Test-Suite directory. "
@@ -42,9 +46,9 @@ class Suite(object):
42
46
_root = attr .ib (default = attr .Factory (_find_suite ))
43
47
44
48
def _remotes (self ):
45
- jsonschema_suite = self ._root .descendant ([ "bin" , "jsonschema_suite" ] )
49
+ jsonschema_suite = self ._root .joinpath ( "bin" , "jsonschema_suite" )
46
50
remotes = subprocess .check_output (
47
- [sys .executable , jsonschema_suite . path , "remotes" ],
51
+ [sys .executable , str ( jsonschema_suite ) , "remotes" ],
48
52
)
49
53
return {
50
54
"http://localhost:1234/" + name : schema
@@ -61,7 +65,7 @@ def benchmark(self, runner): # pragma: no cover
61
65
def version (self , name ):
62
66
return Version (
63
67
name = name ,
64
- path = self ._root .descendant ([ "tests" , name ] ),
68
+ path = self ._root .joinpath ( "tests" , name ),
65
69
remotes = self ._remotes (),
66
70
)
67
71
@@ -85,34 +89,34 @@ def benchmark(self, runner, **kwargs): # pragma: no cover
85
89
def tests (self ):
86
90
return (
87
91
test
88
- for child in self ._path .globChildren ("*.json" )
92
+ for child in self ._path .glob ("*.json" )
89
93
for test in self ._tests_in (
90
- subject = child .basename () [:- 5 ],
94
+ subject = child .name [:- 5 ],
91
95
path = child ,
92
96
)
93
97
)
94
98
95
99
def format_tests (self ):
96
- path = self ._path .descendant ([ "optional" , "format" ] )
100
+ path = self ._path .joinpath ( "optional" , "format" )
97
101
return (
98
102
test
99
- for child in path .globChildren ("*.json" )
103
+ for child in path .glob ("*.json" )
100
104
for test in self ._tests_in (
101
- subject = child .basename () [:- 5 ],
105
+ subject = child .name [:- 5 ],
102
106
path = child ,
103
107
)
104
108
)
105
109
106
110
def tests_of (self , name ):
107
111
return self ._tests_in (
108
112
subject = name ,
109
- path = self ._path . child (name + ".json" ),
113
+ path = self ._path / (name + ".json" ),
110
114
)
111
115
112
116
def optional_tests_of (self , name ):
113
117
return self ._tests_in (
114
118
subject = name ,
115
- path = self ._path .descendant ([ "optional" , name + ".json" ] ),
119
+ path = self ._path .joinpath ( "optional" , name + ".json" ),
116
120
)
117
121
118
122
def to_unittest_testcase (self , * suites , ** kwargs ):
@@ -136,7 +140,7 @@ def to_unittest_testcase(self, *suites, **kwargs):
136
140
return cls
137
141
138
142
def _tests_in (self , subject , path ):
139
- for each in json .loads (path .getContent (). decode ( "utf-8" )):
143
+ for each in json .loads (path .read_text ( )):
140
144
yield (
141
145
_Test (
142
146
version = self ,
0 commit comments