1
0
mirror of https://github.com/gryf/mc_adbfs.git synced 2025-12-18 12:00:19 +01:00

Fix for removing files with space/parentheses.

Also, some further py2 cleanup.
This commit is contained in:
2020-04-26 09:32:17 +02:00
parent 390f1b1112
commit 2776668913
4 changed files with 15 additions and 49 deletions

View File

@@ -1,24 +1,15 @@
# -*- coding: utf-8 -*-
import os
import six
from importlib.util import spec_from_loader, module_from_spec
from importlib.machinery import SourceFileLoader
import unittest
try:
from unittest import mock
except ImportError:
import mock
from unittest import mock
FILE = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'adbfs')
try:
from importlib.util import spec_from_loader, module_from_spec
from importlib.machinery import SourceFileLoader
spec = spec_from_loader("adbfs", SourceFileLoader("adbfs", FILE))
adbfs = module_from_spec(spec)
spec.loader.exec_module(adbfs)
except ImportError:
# py27
import imp
adbfs = imp.load_source('adbfs', FILE)
module_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'adbfs')
spec = spec_from_loader("adbfs", SourceFileLoader("adbfs", module_path))
adbfs = module_from_spec(spec)
spec.loader.exec_module(adbfs)
LISTING = '''\
-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 /storage/emulated/0/Grüß Gott
@@ -44,10 +35,7 @@ class TestCheckOutput(unittest.TestCase):
Python3 treats string as unicode objects, but subprocess.check_output
returns bytes object, which is equvalend for py2 string… annoying.
"""
if six.PY3:
out.return_value = bytes(LISTING, 'utf-8')
else:
out.return_value = LISTING
out.return_value = bytes(LISTING, 'utf-8')
result = adbfs.check_output(None)
self.assertEqual(result, LISTING)
@@ -57,9 +45,6 @@ class TestCheckOutput(unittest.TestCase):
Special case for py3. We have bytes with some weird character - like
some system write something with codepage, instead of utf8.
"""
if six.PY2:
# doesn't affect Python 2
return
line = (b'-rw-rw---- 1 0 1015 0 01/01/2010 22:11:01 '
b'/storage/emulated/0/\xe2\n') # Latin 1 char â
out.return_value = bytes(line)