Skip to content

Commit c5c515b

Browse files
authored
test_api: Normalize file name and path (#608)
test_list_notebooks was failing on file systems with unicode normalization different from the encoding used in the strings. In particular on macOS with HFS+ I got failures for four of the file names. This is because HFS+ uses normalization form D while normalization form C is more commonly used, especially on Linux. By normalizing the name and path read from disk to NFC we avoid the mismatch as long as no NFD strings are added to the `dirs` tuples. There are other unicode normal forms and normalization is not necessarily invertible so this is not a perfect solution. I can think of two alternative solutions: 1. Refrain from using any unicode symbols that have different representations in the various normal forms. 2. Write temporary files to disk somewhere, the read back the paths and filenames and use those instead of the original strings in the test.
1 parent 5931903 commit c5c515b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

jupyter_server/tests/services/contents/test_api.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44
from base64 import decodebytes
55
from base64 import encodebytes
6+
from unicodedata import normalize
67

78
import pytest
89
import tornado
@@ -101,8 +102,8 @@ async def test_list_notebooks(jp_fetch, contents, path, name):
101102
data = json.loads(response.body.decode())
102103
nbs = notebooks_only(data)
103104
assert len(nbs) > 0
104-
assert name + ".ipynb" in [n["name"] for n in nbs]
105-
assert url_path_join(path, name + ".ipynb") in [n["path"] for n in nbs]
105+
assert name + ".ipynb" in [normalize("NFC", n["name"]) for n in nbs]
106+
assert url_path_join(path, name + ".ipynb") in [normalize("NFC", n["path"]) for n in nbs]
106107

107108

108109
@pytest.mark.parametrize("path,name", dirs)

0 commit comments

Comments
 (0)