🔥 Remove Py2 related code
This commit is contained in:
1 parent
3778bcc423
commit
b202c6db54
2 files changed
+14
-98
No files matched your search
@@ -7,25 +7,10 @@ import os.path
|
||||
import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
import pytest
|
||||
from ddt import data, ddt, unpack
|
||||
|
||||
from octoprint.filemanager.storage import LocalFileStorage, StorageError
|
||||
|
||||
try:
|
||||
import pathvalidate # noqa: F401
|
||||
|
||||
HAS_PATHVALIDATE = True
|
||||
except ImportError:
|
||||
HAS_PATHVALIDATE = False
|
||||
|
||||
pathvalidate_unavailable_only = pytest.mark.skipif(
|
||||
HAS_PATHVALIDATE, reason="pathvalidate available"
|
||||
)
|
||||
pathvalidate_available_only = pytest.mark.skipif(
|
||||
not HAS_PATHVALIDATE, reason="pathvalidate unavailable"
|
||||
)
|
||||
|
||||
|
||||
class FileWrapper:
|
||||
def __init__(self, filename):
|
||||
@@ -728,21 +713,6 @@ class LocalStorageTest(unittest.TestCase):
|
||||
self.assertEqual(0, len(gcode_metadata["links"]))
|
||||
self.assertEqual(1, len(stl_metadata["links"]))
|
||||
|
||||
@pathvalidate_unavailable_only
|
||||
@data(
|
||||
("some_file.gco", "some_file.gco"),
|
||||
(
|
||||
"some_file with (parentheses) and ümläuts and digits 123.gco",
|
||||
"some_file_with_(parentheses)_and_umlauts_and_digits_123.gco",
|
||||
),
|
||||
("pengüino pequeño.stl", "penguino_pequeno.stl"),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_name_pvu(self, input, expected):
|
||||
actual = self.storage.sanitize_name(input)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@pathvalidate_available_only
|
||||
@data(
|
||||
("some_file.gco", "some_file.gco"),
|
||||
(
|
||||
@@ -752,7 +722,7 @@ class LocalStorageTest(unittest.TestCase):
|
||||
("pengüino pequeño.stl", "pengüino pequeño.stl"),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_name_pva(self, input, expected):
|
||||
def test_sanitize_name(self, input, expected):
|
||||
actual = self.storage.sanitize_name(input)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@@ -786,7 +756,17 @@ class LocalStorageTest(unittest.TestCase):
|
||||
except ValueError as e:
|
||||
self.assertTrue(e.args[0].startswith("path not contained in base folder: "))
|
||||
|
||||
def _test_sanitize(self, input, expected_path, expected_name):
|
||||
@data(
|
||||
("some/folder/and/some file.gco", "/some/folder/and", "some file.gco"),
|
||||
(("some", "folder", "and", "some file.gco"), "/some/folder/and", "some file.gco"),
|
||||
("some file.gco", "/", "some file.gco"),
|
||||
(("some file.gco",), "/", "some file.gco"),
|
||||
("", "/", ""),
|
||||
("some/folder/with/trailing/slash/", "/some/folder/with/trailing/slash", ""),
|
||||
(("some", "folder", ""), "/some/folder", ""),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize(self, input, expected_path, expected_name):
|
||||
actual = self.storage.sanitize(input)
|
||||
self.assertTrue(isinstance(actual, tuple))
|
||||
self.assertEqual(2, len(actual))
|
||||
@@ -803,34 +783,6 @@ class LocalStorageTest(unittest.TestCase):
|
||||
self.assertEqual(expected_path, actual_path)
|
||||
self.assertEqual(expected_name, actual_name)
|
||||
|
||||
@pathvalidate_unavailable_only
|
||||
@data(
|
||||
("some/folder/and/some file.gco", "/some/folder/and", "some_file.gco"),
|
||||
(("some", "folder", "and", "some file.gco"), "/some/folder/and", "some_file.gco"),
|
||||
("some file.gco", "/", "some_file.gco"),
|
||||
(("some file.gco",), "/", "some_file.gco"),
|
||||
("", "/", ""),
|
||||
("some/folder/with/trailing/slash/", "/some/folder/with/trailing/slash", ""),
|
||||
(("some", "folder", ""), "/some/folder", ""),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_pvu(self, input, expected_path, expected_name):
|
||||
self._test_sanitize(input, expected_path, expected_name)
|
||||
|
||||
@pathvalidate_available_only
|
||||
@data(
|
||||
("some/folder/and/some file.gco", "/some/folder/and", "some file.gco"),
|
||||
(("some", "folder", "and", "some file.gco"), "/some/folder/and", "some file.gco"),
|
||||
("some file.gco", "/", "some file.gco"),
|
||||
(("some file.gco",), "/", "some file.gco"),
|
||||
("", "/", ""),
|
||||
("some/folder/with/trailing/slash/", "/some/folder/with/trailing/slash", ""),
|
||||
(("some", "folder", ""), "/some/folder", ""),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_pva(self, input, expected_path, expected_name):
|
||||
self._test_sanitize(input, expected_path, expected_name)
|
||||
|
||||
def _add_and_verify_file(
|
||||
self, path, expected_path, file_object, links=None, overwrite=False, display=None
|
||||
):
|
||||
|
||||
@@ -1,30 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html"
|
||||
__copyright__ = "Copyright (C) 2021 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
from ddt import data, ddt, unpack
|
||||
|
||||
from octoprint.util.files import sanitize_filename
|
||||
|
||||
try:
|
||||
import pathvalidate # noqa: F401
|
||||
|
||||
HAS_PATHVALIDATE = True
|
||||
except ImportError:
|
||||
HAS_PATHVALIDATE = False
|
||||
|
||||
pathvalidate_unavailable_only = pytest.mark.skipif(
|
||||
HAS_PATHVALIDATE, reason="pathvalidate available"
|
||||
)
|
||||
pathvalidate_available_only = pytest.mark.skipif(
|
||||
not HAS_PATHVALIDATE, reason="pathvalidate unavailable"
|
||||
)
|
||||
|
||||
|
||||
@ddt
|
||||
class FilesUtilTest(unittest.TestCase):
|
||||
@@ -34,6 +16,8 @@ class FilesUtilTest(unittest.TestCase):
|
||||
("LPT1", "LPT1_"),
|
||||
(".test.gcode", "test.gcode"),
|
||||
("..test.gcode", "test.gcode"),
|
||||
("file with space.gcode", "file with space.gcode"),
|
||||
("Wölfe 🐺.gcode", "Wölfe 🐺.gcode"),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_filename(self, filename, expected):
|
||||
@@ -47,23 +31,3 @@ class FilesUtilTest(unittest.TestCase):
|
||||
self.fail("expected ValueError")
|
||||
except ValueError as ex:
|
||||
self.assertEqual(str(ex), "name must not contain / or \\")
|
||||
|
||||
@pathvalidate_unavailable_only
|
||||
@data(
|
||||
("file with space.gcode", "file_with_space.gcode"),
|
||||
("Wölfe 🐺.gcode", "Wolfe_wolf_face.gcode"),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_filename_pvu(self, filename, expected):
|
||||
actual = sanitize_filename(filename)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
@pathvalidate_available_only
|
||||
@data(
|
||||
("file with space.gcode", "file with space.gcode"),
|
||||
("Wölfe 🐺.gcode", "Wölfe 🐺.gcode"),
|
||||
)
|
||||
@unpack
|
||||
def test_sanitize_filename_pva(self, filename, expected):
|
||||
actual = sanitize_filename(filename)
|
||||
self.assertEqual(actual, expected)
|
||||
Reference in new issue
Block a user