From 9a58c28d3241cb57b2fba9c13997d96d43eaa5a6 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang Date: Wed, 17 Sep 2025 16:29:03 -0400 Subject: [PATCH 1/3] Migrate test fixtures discovery to be with pathlib --- test/unit/fixtures.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/unit/fixtures.py b/test/unit/fixtures.py index 52d41d84c..ed0e0f044 100644 --- a/test/unit/fixtures.py +++ b/test/unit/fixtures.py @@ -1,9 +1,8 @@ import json -import os import re -import sys +from pathlib import Path -FIXTURES_DIR = sys.path[0] + "/test/fixtures" +FIXTURES_DIR = Path(__file__).parent.parent / "fixtures" # This regex is useful for finding individual underscore characters, # which is necessary to allow us to use underscores in URL paths. @@ -30,18 +29,18 @@ def _load_fixtures(self): """ self.fixtures = {} - for json_file in os.listdir(FIXTURES_DIR): - if not json_file.endswith(".json"): + for json_file in FIXTURES_DIR.iterdir(): + if not json_file.suffix == ".json": continue - with open(FIXTURES_DIR + "/" + json_file) as f: + with open(FIXTURES_DIR / json_file) as f: raw = f.read() data = json.loads(raw) - fixture_url = PATH_REPLACEMENT_REGEX.sub("/", json_file).replace( - "__", "_" - )[:-5] + fixture_url = PATH_REPLACEMENT_REGEX.sub( + "/", json_file.name + ).replace("__", "_")[:-5] self.fixtures[fixture_url] = data From c8b9a88dec72d60faefe6b2ac90204bb45b3c597 Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Tue, 23 Sep 2025 19:53:06 -0400 Subject: [PATCH 2/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/unit/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/fixtures.py b/test/unit/fixtures.py index ed0e0f044..cecff8336 100644 --- a/test/unit/fixtures.py +++ b/test/unit/fixtures.py @@ -30,7 +30,7 @@ def _load_fixtures(self): self.fixtures = {} for json_file in FIXTURES_DIR.iterdir(): - if not json_file.suffix == ".json": + if json_file.suffix != ".json": continue with open(FIXTURES_DIR / json_file) as f: From 84e1ef68553518824bd1a95756d29c6f1fb1480a Mon Sep 17 00:00:00 2001 From: Zhiwei Liang <121905282+zliang-akamai@users.noreply.github.com> Date: Tue, 23 Sep 2025 19:54:18 -0400 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- test/unit/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/fixtures.py b/test/unit/fixtures.py index cecff8336..c943da95c 100644 --- a/test/unit/fixtures.py +++ b/test/unit/fixtures.py @@ -33,7 +33,7 @@ def _load_fixtures(self): if json_file.suffix != ".json": continue - with open(FIXTURES_DIR / json_file) as f: + with open(json_file) as f: raw = f.read() data = json.loads(raw)