mirror of
https://github.com/fergalmoran/picard.git
synced 2025-12-22 09:18:18 +00:00
Include zip file in short path. Improve tests regarding plugin paths.
This commit is contained in:
@@ -183,7 +183,7 @@ def name_filter(record):
|
|||||||
if path.is_absolute() and not DebugOpt.PLUGIN_FULLPATH.enabled:
|
if path.is_absolute() and not DebugOpt.PLUGIN_FULLPATH.enabled:
|
||||||
try:
|
try:
|
||||||
path = path.resolve().relative_to(USER_PLUGIN_DIR)
|
path = path.resolve().relative_to(USER_PLUGIN_DIR)
|
||||||
parts = list(p for p in path.parts if not p.endswith('.zip'))
|
parts = list(path.parts)
|
||||||
parts.insert(0, 'plugins')
|
parts.insert(0, 'plugins')
|
||||||
path = Path(*parts)
|
path = Path(*parts)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@@ -194,6 +194,11 @@ def name_filter(record):
|
|||||||
del parts[-1]
|
del parts[-1]
|
||||||
if parts[0] == path.anchor:
|
if parts[0] == path.anchor:
|
||||||
parts[0] = '/'
|
parts[0] = '/'
|
||||||
|
# Remove the plugin module file if the file name is the same as
|
||||||
|
# the immediately preceeding plugin zip file name, similar to the
|
||||||
|
# way that the final `__init__.py` file is removed.
|
||||||
|
if len(parts) > 1 and parts[-1] + '.zip' == parts[-2]:
|
||||||
|
del parts[-1]
|
||||||
record.name = str(PurePosixPath(*parts))
|
record.name = str(PurePosixPath(*parts))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ class NameFilterTestRel(PicardTestCase):
|
|||||||
|
|
||||||
def test_plugin_path_long_2(self):
|
def test_plugin_path_long_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
record = FakeRecord(name=None, pathname='/user/picard/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='/user/picard/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, '/user/picard/plugins/plugin.zip/xxx')
|
self.assertEqual(record.name, '/user/picard/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
@@ -184,9 +184,21 @@ class NameFilterTestRel(PicardTestCase):
|
|||||||
|
|
||||||
def test_plugin_path_short_2(self):
|
def test_plugin_path_short_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
record = FakeRecord(name=None, pathname='/user/picard/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='/user/picard/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, 'plugins/xxx')
|
self.assertEqual(record.name, 'plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
|
def test_plugin_path_short_3(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='/user/picard/plugins/myplugin.zip/myplugin.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, 'plugins/myplugin.zip')
|
||||||
|
|
||||||
|
def test_plugin_path_short_4(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='/user/picard/plugins/myplugin.zip/__init__.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, 'plugins/myplugin.zip')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(IS_WIN, "Posix test")
|
@unittest.skipIf(IS_WIN, "Posix test")
|
||||||
@@ -216,27 +228,45 @@ class NameFilterTestAbs(PicardTestCase):
|
|||||||
|
|
||||||
def test_plugin_path_long_1(self):
|
def test_plugin_path_long_1(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
record = FakeRecord(name=None, pathname='/user/picard/plugins/path2/plugins/plugin.zip')
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/plugin.zip')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, '/user/picard/plugins/path2/plugins/plugin')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
|
||||||
|
|
||||||
def test_plugin_path_long_2(self):
|
def test_plugin_path_long_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
record = FakeRecord(name=None, pathname='/user/picard/plugins/path2/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, '/user/picard/plugins/path2/plugins/plugin.zip/xxx')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
|
def test_plugin_path_long_3(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/plugin.zip/__init__.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin.zip')
|
||||||
|
|
||||||
def test_plugin_path_short_1(self):
|
def test_plugin_path_short_1(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
record = FakeRecord(name=None, pathname='/user/picard/plugins/path2/plugins/plugin.zip')
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/plugin.zip')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, 'plugins/path2/plugins/plugin')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
|
||||||
|
|
||||||
def test_plugin_path_short_2(self):
|
def test_plugin_path_short_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
record = FakeRecord(name=None, pathname='/user/picard/plugins/path2/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, 'plugins/path2/plugins/xxx')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
|
def test_plugin_path_short_3(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/myplugin.zip/myplugin.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, '/path1/path2/plugins/myplugin.zip')
|
||||||
|
|
||||||
|
def test_plugin_path_short_4(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='/path1/path2/plugins/myplugin.zip/__init__.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, '/path1/path2/plugins/myplugin.zip')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipIf(IS_WIN, "Posix test")
|
@unittest.skipIf(IS_WIN, "Posix test")
|
||||||
@@ -288,7 +318,7 @@ class NameFilterTestRelWin(PicardTestCase):
|
|||||||
|
|
||||||
def test_plugin_path_long_2(self):
|
def test_plugin_path_long_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, '/user/picard/plugins/path3/plugins/plugin.zip/xxx')
|
self.assertEqual(record.name, '/user/picard/plugins/path3/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
@@ -300,9 +330,21 @@ class NameFilterTestRelWin(PicardTestCase):
|
|||||||
|
|
||||||
def test_plugin_path_short_2(self):
|
def test_plugin_path_short_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, 'plugins/path3/plugins/xxx')
|
self.assertEqual(record.name, 'plugins/path3/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
|
def test_plugin_path_short_3(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/myplugin.zip/myplugin.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, 'plugins/path3/plugins/myplugin.zip')
|
||||||
|
|
||||||
|
def test_plugin_path_short_4(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/myplugin.zip/__init__.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, 'plugins/path3/plugins/myplugin.zip')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(IS_WIN, "Windows test")
|
@unittest.skipUnless(IS_WIN, "Windows test")
|
||||||
@@ -332,27 +374,39 @@ class NameFilterTestAbsWin(PicardTestCase):
|
|||||||
|
|
||||||
def test_plugin_path_long_1(self):
|
def test_plugin_path_long_1(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path2/plugins/plugin.zip')
|
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/plugin.zip')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, '/user/picard/plugins/path2/plugins/plugin')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
|
||||||
|
|
||||||
def test_plugin_path_long_2(self):
|
def test_plugin_path_long_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
DebugOpt.PLUGIN_FULLPATH.enabled = True
|
||||||
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path2/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, '/user/picard/plugins/path2/plugins/plugin.zip/xxx')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
def test_plugin_path_short_1(self):
|
def test_plugin_path_short_1(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path2/plugins/plugin.zip')
|
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/plugin.zip')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, 'plugins/path2/plugins/plugin')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
|
||||||
|
|
||||||
def test_plugin_path_short_2(self):
|
def test_plugin_path_short_2(self):
|
||||||
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path2/plugins/plugin.zip/xxx')
|
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/plugin.zip/xxx.py')
|
||||||
self.assertTrue(name_filter(record))
|
self.assertTrue(name_filter(record))
|
||||||
self.assertEqual(record.name, 'plugins/path2/plugins/xxx')
|
self.assertEqual(record.name, '/path1/path2/plugins/plugin.zip/xxx')
|
||||||
|
|
||||||
|
def test_plugin_path_short_3(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/myplugin.zip/myplugin.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, '/path1/path2/plugins/myplugin.zip')
|
||||||
|
|
||||||
|
def test_plugin_path_short_4(self):
|
||||||
|
DebugOpt.PLUGIN_FULLPATH.enabled = False
|
||||||
|
record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/myplugin.zip/__init__.py')
|
||||||
|
self.assertTrue(name_filter(record))
|
||||||
|
self.assertEqual(record.name, '/path1/path2/plugins/myplugin.zip')
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(IS_WIN, "Windows test")
|
@unittest.skipUnless(IS_WIN, "Windows test")
|
||||||
|
|||||||
Reference in New Issue
Block a user