Skip to content

Commit

Permalink
test_api: Normalize file name and path (#608)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
toonn authored Nov 22, 2021
1 parent 5931903 commit c5c515b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jupyter_server/tests/services/contents/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
from base64 import decodebytes
from base64 import encodebytes
from unicodedata import normalize

import pytest
import tornado
Expand Down Expand Up @@ -101,8 +102,8 @@ async def test_list_notebooks(jp_fetch, contents, path, name):
data = json.loads(response.body.decode())
nbs = notebooks_only(data)
assert len(nbs) > 0
assert name + ".ipynb" in [n["name"] for n in nbs]
assert url_path_join(path, name + ".ipynb") in [n["path"] for n in nbs]
assert name + ".ipynb" in [normalize("NFC", n["name"]) for n in nbs]
assert url_path_join(path, name + ".ipynb") in [normalize("NFC", n["path"]) for n in nbs]


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

0 comments on commit c5c515b

Please sign in to comment.