From ae1d6887aae890897457afd63add2bfe132127b2 Mon Sep 17 00:00:00 2001 From: Shawn Crawley Date: Mon, 7 Oct 2024 08:03:44 -0600 Subject: [PATCH] Fix bug with pathlib update to static_finders --- .../test_tethys_apps/test_static_finders.py | 36 ++++++++++--------- tethys_apps/static_finders.py | 9 ++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/tests/unit_tests/test_tethys_apps/test_static_finders.py b/tests/unit_tests/test_tethys_apps/test_static_finders.py index 668f93023..0c5f7f293 100644 --- a/tests/unit_tests/test_tethys_apps/test_static_finders.py +++ b/tests/unit_tests/test_tethys_apps/test_static_finders.py @@ -25,44 +25,48 @@ def test_init(self): def test_find(self): tethys_static_finder = TethysStaticFinder() path = Path("test_app") / "css" / "main.css" - ret = tethys_static_finder.find(path) - self.assertEqual(str(self.root / "css" / "main.css").lower(), ret.lower()) + path_ret = tethys_static_finder.find(path) + self.assertEqual(self.root / "css" / "main.css", path_ret) + str_ret = tethys_static_finder.find(str(path)) + self.assertEqual(self.root / "css" / "main.css", str_ret) def test_find_all(self): tethys_static_finder = TethysStaticFinder() path = Path("test_app") / "css" / "main.css" - ret = tethys_static_finder.find(path, all=True) - self.assertIn( - str(self.root / "css" / "main.css").lower(), - list(map(lambda x: x.lower(), ret)), - ) + path_ret = tethys_static_finder.find(path, all=True) + self.assertIn(self.root / "css" / "main.css", path_ret) + str_ret = tethys_static_finder.find(str(path), all=True) + self.assertIn(self.root / "css" / "main.css", str_ret) def test_find_location_with_no_prefix(self): prefix = None path = Path("css") / "main.css" tethys_static_finder = TethysStaticFinder() - ret = tethys_static_finder.find_location(str(self.root), path, prefix) - - self.assertEqual(str(self.root / path), ret) + path_ret = tethys_static_finder.find_location(self.root, path, prefix) + self.assertEqual(self.root / path, path_ret) + str_ret = tethys_static_finder.find_location(str(self.root), path, prefix) + self.assertEqual(self.root / path, str_ret) def test_find_location_with_prefix_not_in_path(self): prefix = "tethys_app" path = Path("css") / "main.css" tethys_static_finder = TethysStaticFinder() - ret = tethys_static_finder.find_location(str(self.root), path, prefix) - - self.assertIsNone(ret) + path_ret = tethys_static_finder.find_location(self.root, path, prefix) + self.assertIsNone(path_ret) + str_ret = tethys_static_finder.find_location(str(self.root), path, prefix) + self.assertIsNone(str_ret) def test_find_location_with_prefix_in_path(self): prefix = "tethys_app" path = Path("tethys_app") / "css" / "main.css" tethys_static_finder = TethysStaticFinder() - ret = tethys_static_finder.find_location(str(self.root), path, prefix) - - self.assertEqual(str(self.root / "css" / "main.css"), ret) + path_ret = tethys_static_finder.find_location(self.root, path, prefix) + self.assertEqual(self.root / "css" / "main.css", path_ret) + str_ret = tethys_static_finder.find_location(str(self.root), path, prefix) + self.assertEqual(self.root / "css" / "main.css", str_ret) def test_list(self): tethys_static_finder = TethysStaticFinder() diff --git a/tethys_apps/static_finders.py b/tethys_apps/static_finders.py index 498d41086..bdd621373 100644 --- a/tethys_apps/static_finders.py +++ b/tethys_apps/static_finders.py @@ -23,7 +23,7 @@ class TethysStaticFinder(BaseFinder): This finder search for static files in a directory called 'public' or 'static'. """ - def __init__(self, apps=None, *args, **kwargs): + def __init__(self, *args, **kwargs): # List of locations with static files self.locations = get_directories_in_tethys( ("static", "public"), with_app_name=True @@ -57,13 +57,14 @@ def find_location(self, root, path, prefix=None): Finds a requested static file in a location, returning the found absolute path (or ``None`` if no match). """ + path = Path(path) if prefix: prefix = Path(f"{prefix}/") - if not Path(path).is_relative_to(prefix): + if not path.is_relative_to(prefix): return None path = path.relative_to(prefix) - path = safe_join(str(root), str(path)) - if Path(path).exists(): + path = Path(safe_join(str(root), str(path))) + if path.exists(): return path def list(self, ignore_patterns):