summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeth Morton <seth.m.morton@gmail.com>2022-01-29 17:17:15 -0800
committerSeth Morton <seth.m.morton@gmail.com>2022-01-29 17:31:37 -0800
commit961d3bbd28d134280ebff30552ae209ee4f26b5e (patch)
tree3825eac5f1b5ef6a95451f8da50a739af103cebc
parent4f0b3a8b005a0a43d2c21cf0b1e11c89186603b3 (diff)
downloadnatsort-961d3bbd28d134280ebff30552ae209ee4f26b5e.tar.gz
Add tests to demonstrate the PATH ext bug
I'm not sure sure it is *actually* a bug, but the PATH algorithm's way of splitting extensions was over-zealous and in practice will split off more extensions that is probably desired. To fix this, we will need to add a heuristic, but this commit adds tests to demonstrate the problem.
-rw-r--r--tests/test_natsorted.py15
-rw-r--r--tests/test_utils.py25
2 files changed, 36 insertions, 4 deletions
diff --git a/tests/test_natsorted.py b/tests/test_natsorted.py
index 4a64a27..eb3aefe 100644
--- a/tests/test_natsorted.py
+++ b/tests/test_natsorted.py
@@ -182,6 +182,21 @@ def test_natsorted_handles_numbers_and_filesystem_paths_simultaneously() -> None
assert natsorted(given, alg=ns.PATH) == expected
+def test_natsorted_path_extensions_heuristic() -> None:
+ # https://github.com/SethMMorton/natsort/issues/145
+ given = [
+ "Try.Me.Bug - 09 - One.Two.Three.[text].mkv",
+ "Try.Me.Bug - 07 - One.Two.5.[text].mkv",
+ "Try.Me.Bug - 08 - One.Two.Three[text].mkv",
+ ]
+ expected = [
+ "Try.Me.Bug - 07 - One.Two.5.[text].mkv",
+ "Try.Me.Bug - 08 - One.Two.Three[text].mkv",
+ "Try.Me.Bug - 09 - One.Two.Three.[text].mkv",
+ ]
+ assert natsorted(given, alg=ns.PATH) == expected
+
+
@pytest.mark.parametrize(
"alg, expected",
[
diff --git a/tests/test_utils.py b/tests/test_utils.py
index bb229b9..b140682 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -6,7 +6,7 @@ import pathlib
import string
from itertools import chain
from operator import neg as op_neg
-from typing import List, Pattern, Union
+from typing import List, Pattern, Tuple, Union
import pytest
from hypothesis import given
@@ -155,9 +155,26 @@ def test_path_splitter_splits_path_string_by_sep(x: List[str]) -> None:
assert tuple(utils.path_splitter(z)) == tuple(pathlib.Path(z).parts)
-def test_path_splitter_splits_path_string_by_sep_and_removes_extension_example() -> None:
- given = "/this/is/a/path/file.x1.10.tar.gz"
- expected = (os.sep, "this", "is", "a", "path", "file.x1.10", ".tar", ".gz")
+@pytest.mark.parametrize(
+ "given, expected",
+ [
+ (
+ "/this/is/a/path/file.x1.10.tar.gz",
+ (os.sep, "this", "is", "a", "path", "file.x1.10", ".tar", ".gz"),
+ ),
+ (
+ "/this/is/a/path/file.x1.10.tar",
+ (os.sep, "this", "is", "a", "path", "file.x1.10", ".tar"),
+ ),
+ (
+ "/this/is/a/path/file.x1.threethousand.tar",
+ (os.sep, "this", "is", "a", "path", "file.x1.threethousand", ".tar"),
+ ),
+ ],
+)
+def test_path_splitter_splits_path_string_by_sep_and_removes_extension_example(
+ given: str, expected: Tuple[str, ...]
+) -> None:
assert tuple(utils.path_splitter(given)) == tuple(expected)