From a807ede818e0690949aca41020e75a96f0110ece Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Thu, 14 Dec 2023 11:23:30 -0800 Subject: [PATCH] Fix backend tests on Windows (#6781) * hotfix * testing * test * fix * fix * add changeset * add changeset --------- Co-authored-by: gradio-pr-bot --- .changeset/vast-kings-deny.md | 5 +++++ gradio/components/file_explorer.py | 2 +- test/test_components.py | 14 ++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 .changeset/vast-kings-deny.md diff --git a/.changeset/vast-kings-deny.md b/.changeset/vast-kings-deny.md new file mode 100644 index 000000000000..a2a874a499d6 --- /dev/null +++ b/.changeset/vast-kings-deny.md @@ -0,0 +1,5 @@ +--- +"gradio": patch +--- + +feat:Fix backend tests on Windows diff --git a/gradio/components/file_explorer.py b/gradio/components/file_explorer.py index bbdb65c8c413..7ed5909fea93 100644 --- a/gradio/components/file_explorer.py +++ b/gradio/components/file_explorer.py @@ -170,7 +170,7 @@ def expand_braces(text, seen=None): def make_tree(files): tree = [] for file in files: - parts = file.split("/") + parts = file.split(os.path.sep) make_node(parts, tree) return tree diff --git a/test/test_components.py b/test/test_components.py index bf7b14caf815..5e13513e5256 100644 --- a/test/test_components.py +++ b/test/test_components.py @@ -2138,16 +2138,18 @@ def test_gallery(self): postprocessed_gallery = gallery.postprocess( [ - ("test/test_files/foo.png", "foo_caption"), + (str(Path("test/test_files/foo.png")), "foo_caption"), (Path("test/test_files/bar.png"), "bar_caption"), - "test/test_files/baz.png", + str(Path("test/test_files/baz.png")), Path("test/test_files/qux.png"), ] ).model_dump() + + # Using str(Path(...)) to ensure that the test passes on all platforms assert postprocessed_gallery == [ { "image": { - "path": "test/test_files/foo.png", + "path": str(Path("test") / "test_files" / "foo.png"), "orig_name": "foo.png", "mime_type": None, "size": None, @@ -2157,7 +2159,7 @@ def test_gallery(self): }, { "image": { - "path": "test/test_files/bar.png", + "path": str(Path("test") / "test_files" / "bar.png"), "orig_name": "bar.png", "mime_type": None, "size": None, @@ -2167,7 +2169,7 @@ def test_gallery(self): }, { "image": { - "path": "test/test_files/baz.png", + "path": str(Path("test") / "test_files" / "baz.png"), "orig_name": "baz.png", "mime_type": None, "size": None, @@ -2177,7 +2179,7 @@ def test_gallery(self): }, { "image": { - "path": "test/test_files/qux.png", + "path": str(Path("test") / "test_files" / "qux.png"), "orig_name": "qux.png", "mime_type": None, "size": None,