From b202c6db547ee91254da655d700088f2dd47deae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 20 May 2021 15:42:37 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Remove=20Py2=20related=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/filemanager/test_localstorage.py | 72 +++++--------------------- tests/util/test_files.py | 40 +------------- 2 files changed, 14 insertions(+), 98 deletions(-) diff --git a/tests/filemanager/test_localstorage.py b/tests/filemanager/test_localstorage.py index f31cad4ff..4875ca1e6 100644 --- a/tests/filemanager/test_localstorage.py +++ b/tests/filemanager/test_localstorage.py @@ -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 ): diff --git a/tests/util/test_files.py b/tests/util/test_files.py index a5edb3fce..3eb713f4b 100644 --- a/tests/util/test_files.py +++ b/tests/util/test_files.py @@ -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)