♻️ Py3: Some more import & compat stragglers
This commit is contained in:
1 parent
55ddfdd314
commit
c02c1452e6
5 files changed
+5
-55
No files matched your search
@@ -413,7 +413,6 @@ class VirtualPrinter:
|
||||
continue
|
||||
elif len(self._prepared_errors):
|
||||
prepared = self._prepared_errors.pop(0)
|
||||
# noinspection PyCompatibility
|
||||
if callable(prepared):
|
||||
prepared(linenumber, self.lastN, data)
|
||||
continue
|
||||
|
||||
@@ -13,7 +13,6 @@ import re
|
||||
import signal
|
||||
import sys
|
||||
import uuid # noqa: F401
|
||||
from builtins import bytes, range
|
||||
from collections import OrderedDict, defaultdict
|
||||
|
||||
from babel import Locale
|
||||
|
||||
@@ -4728,7 +4728,6 @@ class MachineCom:
|
||||
def convert(data):
|
||||
result = []
|
||||
for d in data:
|
||||
# noinspection PyCompatibility
|
||||
if isinstance(d, tuple) and len(d) == 2:
|
||||
result.append((d[0], None, d[1]))
|
||||
elif isinstance(d, str):
|
||||
|
||||
@@ -8,7 +8,6 @@ import unittest
|
||||
import unittest.mock as mock
|
||||
|
||||
import ddt
|
||||
from past.builtins import unicode
|
||||
|
||||
import octoprint.util
|
||||
|
||||
@@ -531,9 +530,7 @@ class IsHiddenPathTest(unittest.TestCase):
|
||||
# only hidden on windows
|
||||
import ctypes
|
||||
|
||||
ctypes.windll.kernel32.SetFileAttributesW(
|
||||
unicode(self.path_hidden_on_windows), 2
|
||||
)
|
||||
ctypes.windll.kernel32.SetFileAttributesW(str(self.path_hidden_on_windows), 2)
|
||||
|
||||
def tearDown(self):
|
||||
import shutil
|
||||
@@ -550,45 +547,3 @@ class IsHiddenPathTest(unittest.TestCase):
|
||||
def test_is_hidden_path(self, path_id, expected):
|
||||
path = getattr(self, path_id) if path_id is not None else None
|
||||
self.assertEqual(octoprint.util.is_hidden_path(path), expected)
|
||||
|
||||
|
||||
try:
|
||||
from glob import escape # noqa: F401
|
||||
|
||||
except ImportError:
|
||||
# no glob.escape - tests for our ported implementation
|
||||
|
||||
@ddt.ddt
|
||||
class GlobEscapeTest(unittest.TestCase):
|
||||
"""
|
||||
Ported from Python 3.4
|
||||
|
||||
See https://github.com/python/cpython/commit/fd32fffa5ada8b8be8a65bd51b001d989f99a3d3
|
||||
"""
|
||||
|
||||
@ddt.data(
|
||||
("abc", "abc"),
|
||||
("[", "[[]"),
|
||||
("?", "[?]"),
|
||||
("*", "[*]"),
|
||||
("[[_/*?*/_]]", "[[][[]_/[*][?][*]/_]]"),
|
||||
("/[[_/*?*/_]]/", "/[[][[]_/[*][?][*]/_]]/"),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_glob_escape(self, text, expected):
|
||||
actual = octoprint.util.glob_escape(text)
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
@ddt.data(
|
||||
("?:?", "?:[?]"),
|
||||
("*:*", "*:[*]"),
|
||||
(r"\\?\c:\?", r"\\?\c:\[?]"),
|
||||
(r"\\*\*\*", r"\\*\*\[*]"),
|
||||
("//?/c:/?", "//?/c:/[?]"),
|
||||
("//*/*/*", "//*/*/[*]"),
|
||||
)
|
||||
@ddt.unpack
|
||||
@unittest.skipUnless(sys.platform == "win32", "Win32 specific test")
|
||||
def test_glob_escape_windows(self, text, expected):
|
||||
actual = octoprint.util.glob_escape(text)
|
||||
self.assertEqual(actual, expected)
|
||||
@@ -3,8 +3,6 @@ __copyright__ = "Copyright (C) 2019 The OctoPrint Project - Released under terms
|
||||
|
||||
import unittest
|
||||
|
||||
from past.builtins import unicode
|
||||
|
||||
import octoprint.util
|
||||
|
||||
|
||||
@@ -12,18 +10,18 @@ class StringHelperTest(unittest.TestCase):
|
||||
def test_to_unicode_unicode(self):
|
||||
result = octoprint.util.to_unicode("test")
|
||||
self.assertEqual(result, "test")
|
||||
self.assertIsInstance(result, unicode)
|
||||
self.assertIsInstance(result, str)
|
||||
|
||||
def test_to_unicode_bytes(self):
|
||||
result = octoprint.util.to_unicode(b"test")
|
||||
self.assertEqual(result, "test")
|
||||
self.assertIsInstance(result, unicode)
|
||||
self.assertIsInstance(result, str)
|
||||
|
||||
def test_to_unicode_bytes_utf8(self):
|
||||
data = "äöüß"
|
||||
result = octoprint.util.to_unicode(data.encode("utf-8"), encoding="utf-8")
|
||||
self.assertEqual(result, data)
|
||||
self.assertIsInstance(result, unicode)
|
||||
self.assertIsInstance(result, str)
|
||||
|
||||
def test_to_unicode_bytes_utf8_vs_ascii(self):
|
||||
self.assertRaises(
|
||||
@@ -39,7 +37,7 @@ class StringHelperTest(unittest.TestCase):
|
||||
data.encode("utf-8"), encoding="ascii", errors="replace"
|
||||
)
|
||||
self.assertEqual(result, data.encode("utf-8").decode("ascii", errors="replace"))
|
||||
self.assertIsInstance(result, unicode)
|
||||
self.assertIsInstance(result, str)
|
||||
|
||||
def test_to_bytes_bytes(self):
|
||||
result = octoprint.util.to_bytes(b"test")
|
||||
|
||||
Reference in new issue
Block a user