diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2018-11-18 21:53:06 -0800 |
---|---|---|
committer | Seth Morton <seth.m.morton@gmail.com> | 2019-03-03 21:17:49 -0800 |
commit | 44f54c05721f49964f1686416913730167e0815c (patch) | |
tree | 3b82b963d74f8af86ee20f9104d651b0d795f194 /tests | |
parent | d953b3d8e2e4bb211825d92b47b7a92437c1ed33 (diff) | |
download | natsort-44f54c05721f49964f1686416913730167e0815c.tar.gz |
Remove pathlib compatibility layer
pathlib comes with Python 3.4 stdlib, so no need to add a compatibility
layer.
The path_splitter function has been re-written in terms of pathlib
since that is now guaranteed to exist. Much simpler.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_natsorted.py | 13 | ||||
-rw-r--r-- | tests/test_utils.py | 19 |
2 files changed, 17 insertions, 15 deletions
diff --git a/tests/test_natsorted.py b/tests/test_natsorted.py index d8ef8c0..f0940aa 100644 --- a/tests/test_natsorted.py +++ b/tests/test_natsorted.py @@ -134,12 +134,14 @@ def test_natsorted_returns_list_in_reversed_order_with_reverse_option(float_list def test_natsorted_handles_filesystem_paths(): given = [ "/p/Folder (10)/file.tar.gz", - "/p/Folder/file.tar.gz", "/p/Folder (1)/file (1).tar.gz", + "/p/Folder/file.x1.9.tar.gz", "/p/Folder (1)/file.tar.gz", + "/p/Folder/file.x1.10.tar.gz", ] expected_correct = [ - "/p/Folder/file.tar.gz", + "/p/Folder/file.x1.10.tar.gz", + "/p/Folder/file.x1.9.tar.gz", "/p/Folder (1)/file.tar.gz", "/p/Folder (1)/file (1).tar.gz", "/p/Folder (10)/file.tar.gz", @@ -148,12 +150,13 @@ def test_natsorted_handles_filesystem_paths(): "/p/Folder (1)/file (1).tar.gz", "/p/Folder (1)/file.tar.gz", "/p/Folder (10)/file.tar.gz", - "/p/Folder/file.tar.gz", + "/p/Folder/file.x1.10.tar.gz", + "/p/Folder/file.x1.9.tar.gz", ] # Is incorrect by default. - assert natsorted(given) == expected_incorrect + assert natsorted(given, alg=ns.FLOAT) == expected_incorrect # Need ns.PATH to make it correct. - assert natsorted(given, alg=ns.PATH) == expected_correct + assert natsorted(given, alg=ns.FLOAT | ns.PATH) == expected_correct def test_natsorted_handles_numbers_and_filesystem_paths_simultaneously(): diff --git a/tests/test_utils.py b/tests/test_utils.py index 964876a..76d8e23 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """These test the utils.py functions.""" +import os import pathlib import string from itertools import chain @@ -128,10 +129,11 @@ def test_sep_inserter_inserts_separator_between_two_numbers(x): def test_path_splitter_splits_path_string_by_separator_example(): - z = "/this/is/a/path" - assert tuple(utils.path_splitter(z)) == tuple(pathlib.Path(z).parts) - z = pathlib.Path("/this/is/a/path") - assert tuple(utils.path_splitter(z)) == tuple(pathlib.Path(z).parts) + given = "/this/is/a/path" + expected = (os.sep, "this", "is", "a", "path") + assert tuple(utils.path_splitter(given)) == tuple(expected) + given = pathlib.Path(given) + assert tuple(utils.path_splitter(given)) == tuple(expected) @given(lists(sampled_from(string.ascii_letters), min_size=2).filter(all)) @@ -141,12 +143,9 @@ def test_path_splitter_splits_path_string_by_separator(x): def test_path_splitter_splits_path_string_by_separator_and_removes_extension_example(): - z = "/this/is/a/path/file.exe" - y = tuple(pathlib.Path(z).parts) - assert tuple(utils.path_splitter(z)) == y[:-1] + ( - pathlib.Path(z).stem, - pathlib.Path(z).suffix, - ) + given = "/this/is/a/path/file.x1.10.tar.gz" + expected = (os.sep, "this", "is", "a", "path", "file.x1.10", ".tar", ".gz") + assert tuple(utils.path_splitter(given)) == tuple(expected) @given(lists(sampled_from(string.ascii_letters), min_size=3).filter(all)) |