Skip to content

Commit 1ff1561

Browse files
committed
FilePath -> pathlib
1 parent 9cdc7a9 commit 1ff1561

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

jsonschema/benchmarks/issue232.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
55
See https://github.com/Julian/jsonschema/pull/232.
66
"""
7-
from twisted.python.filepath import FilePath
7+
from pathlib import Path
8+
89
from pyperf import Runner
910
from pyrsistent import m
1011

@@ -13,7 +14,7 @@
1314

1415

1516
issue232 = Version(
16-
path=FilePath(__file__).sibling("issue232"),
17+
path=Path(__file__).parent / "issue232",
1718
remotes=m(),
1819
name="issue232",
1920
)

jsonschema/tests/_suite.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import sys
1111
import unittest
1212

13-
from twisted.python.filepath import FilePath
13+
try:
14+
from pathlib import Path
15+
except ImportError:
16+
from pathlib2 import Path
17+
1418
import attr
1519

1620
from jsonschema.compat import PY3
@@ -21,10 +25,10 @@
2125
def _find_suite():
2226
root = os.environ.get("JSON_SCHEMA_TEST_SUITE")
2327
if root is not None:
24-
return FilePath(root)
28+
return Path(root)
2529

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
2832
raise ValueError(
2933
(
3034
"Can't find the JSON-Schema-Test-Suite directory. "
@@ -42,9 +46,9 @@ class Suite(object):
4246
_root = attr.ib(default=attr.Factory(_find_suite))
4347

4448
def _remotes(self):
45-
jsonschema_suite = self._root.descendant(["bin", "jsonschema_suite"])
49+
jsonschema_suite = self._root.joinpath("bin", "jsonschema_suite")
4650
remotes = subprocess.check_output(
47-
[sys.executable, jsonschema_suite.path, "remotes"],
51+
[sys.executable, str(jsonschema_suite), "remotes"],
4852
)
4953
return {
5054
"http://localhost:1234/" + name: schema
@@ -61,7 +65,7 @@ def benchmark(self, runner): # pragma: no cover
6165
def version(self, name):
6266
return Version(
6367
name=name,
64-
path=self._root.descendant(["tests", name]),
68+
path=self._root.joinpath("tests", name),
6569
remotes=self._remotes(),
6670
)
6771

@@ -85,34 +89,34 @@ def benchmark(self, runner, **kwargs): # pragma: no cover
8589
def tests(self):
8690
return (
8791
test
88-
for child in self._path.globChildren("*.json")
92+
for child in self._path.glob("*.json")
8993
for test in self._tests_in(
90-
subject=child.basename()[:-5],
94+
subject=child.name[:-5],
9195
path=child,
9296
)
9397
)
9498

9599
def format_tests(self):
96-
path = self._path.descendant(["optional", "format"])
100+
path = self._path.joinpath("optional", "format")
97101
return (
98102
test
99-
for child in path.globChildren("*.json")
103+
for child in path.glob("*.json")
100104
for test in self._tests_in(
101-
subject=child.basename()[:-5],
105+
subject=child.name[:-5],
102106
path=child,
103107
)
104108
)
105109

106110
def tests_of(self, name):
107111
return self._tests_in(
108112
subject=name,
109-
path=self._path.child(name + ".json"),
113+
path=self._path / (name + ".json"),
110114
)
111115

112116
def optional_tests_of(self, name):
113117
return self._tests_in(
114118
subject=name,
115-
path=self._path.descendant(["optional", name + ".json"]),
119+
path=self._path.joinpath("optional", name + ".json"),
116120
)
117121

118122
def to_unittest_testcase(self, *suites, **kwargs):
@@ -136,7 +140,7 @@ def to_unittest_testcase(self, *suites, **kwargs):
136140
return cls
137141

138142
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()):
140144
yield (
141145
_Test(
142146
version=self,

test-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Twisted
1+
pathlib2; python_version == '2.7'

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ deps =
3434
perf: pyperf
3535

3636
tests,tests_nongpl,coverage,codecov,perf: -r{toxinidir}/test-requirements.txt
37+
tests,tests_nongpl,coverage,codecov: twisted
3738

3839
coverage,codecov: coverage
3940
codecov: codecov

0 commit comments

Comments
 (0)