Skip to content

Commit

Permalink
Test file path with PathLib, note in doc that return is the full file…
Browse files Browse the repository at this point in the history
… path
  • Loading branch information
benkiel committed Nov 22, 2024
1 parent 76613ea commit cbda0c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Lib/fontParts/base/normalizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ def normalizeFilePath(value: Union[str, Path]) -> str:
Relative paths are resolved automatically.
:param value: The file path to normalize as a :class:`str` or :class:`pathlib.Path`.
:return: A :class:`str` representing the normalized file path.
:return: A :class:`str` representing the normalized full file path.
:raises TypeError if `value` is not a :class:`str` or :class:`pathlib.Path`.
:raises FileNotFoundError: If the file path cannot be resolved because it does not exist.
Expand Down
12 changes: 10 additions & 2 deletions Lib/fontParts/test/test_normalizers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest
import os
from fontParts.base import normalizers


Expand Down Expand Up @@ -1425,16 +1426,23 @@ def test_normalizeGlyphNote_notString(self):
normalizers.normalizeGlyphNote(123)

# normalizeFilePath
def test_normalizeFilePath_pathlib_path(self):
from pathlib import Path
path = Path(os.getcwd(), "Test.ufo")
self.assertIsInstance(path, Path)
result = normalizers.normalizeFilePath(path)
self.assertIsInstance(result, str)
self.assertEqual(result, os.path.join(os.getcwd(), "Test.ufo"))

def test_normalizeFilePath_string(self):
result = normalizers.normalizeFilePath("A")
self.assertIsInstance(result, str)
self.assertEqual(result, "A")
self.assertEqual(result, os.path.join(os.getcwd(), "A"))

def test_normalizeFilePath_emptyString(self):
result = normalizers.normalizeFilePath("")
self.assertIsInstance(result, str)
self.assertEqual(result, "")
self.assertEqual(result, os.getcwd())

def test_normalizeFilePath_notString(self):
with self.assertRaises(TypeError):
Expand Down

0 comments on commit cbda0c3

Please sign in to comment.