Skip to content

Commit 7d1dd7e

Browse files
srbhaakamaiCopilot
andcommitted
Migrate test fixtures discovery to be with pathlib (#599)
* Migrate test fixtures discovery to be with pathlib * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 31198da commit 7d1dd7e

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

test/unit/fixtures.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import json
2-
import os
32
import re
4-
import sys
3+
from pathlib import Path
54

6-
FIXTURES_DIR = sys.path[0] + "/test/fixtures"
5+
FIXTURES_DIR = Path(__file__).parent.parent / "fixtures"
76

87
# This regex is useful for finding individual underscore characters,
98
# which is necessary to allow us to use underscores in URL paths.
@@ -30,18 +29,18 @@ def _load_fixtures(self):
3029
"""
3130
self.fixtures = {}
3231

33-
for json_file in os.listdir(FIXTURES_DIR):
34-
if not json_file.endswith(".json"):
32+
for json_file in FIXTURES_DIR.iterdir():
33+
if json_file.suffix != ".json":
3534
continue
3635

37-
with open(FIXTURES_DIR + "/" + json_file) as f:
36+
with open(json_file) as f:
3837
raw = f.read()
3938

4039
data = json.loads(raw)
4140

42-
fixture_url = PATH_REPLACEMENT_REGEX.sub("/", json_file).replace(
43-
"__", "_"
44-
)[:-5]
41+
fixture_url = PATH_REPLACEMENT_REGEX.sub(
42+
"/", json_file.name
43+
).replace("__", "_")[:-5]
4544

4645
self.fixtures[fixture_url] = data
4746

0 commit comments

Comments
 (0)