Include zip file in short path. Improve tests regarding plugin paths.

This commit is contained in:
Bob Swift
2024-04-15 12:47:16 -06:00
parent 44b1d028a8
commit 495736a369
2 changed files with 82 additions and 23 deletions

View File

@@ -183,7 +183,7 @@ def name_filter(record):
if path.is_absolute() and not DebugOpt.PLUGIN_FULLPATH.enabled:
try:
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')
path = Path(*parts)
except ValueError:
@@ -194,6 +194,11 @@ def name_filter(record):
del parts[-1]
if parts[0] == path.anchor:
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))
return True

View File

@@ -172,7 +172,7 @@ class NameFilterTestRel(PicardTestCase):
def test_plugin_path_long_2(self):
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.assertEqual(record.name, '/user/picard/plugins/plugin.zip/xxx')
@@ -184,9 +184,21 @@ class NameFilterTestRel(PicardTestCase):
def test_plugin_path_short_2(self):
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.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")
@@ -216,27 +228,45 @@ class NameFilterTestAbs(PicardTestCase):
def test_plugin_path_long_1(self):
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.assertEqual(record.name, '/user/picard/plugins/path2/plugins/plugin')
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
def test_plugin_path_long_2(self):
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.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):
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.assertEqual(record.name, 'plugins/path2/plugins/plugin')
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
def test_plugin_path_short_2(self):
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.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")
@@ -288,7 +318,7 @@ class NameFilterTestRelWin(PicardTestCase):
def test_plugin_path_long_2(self):
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.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):
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.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")
@@ -332,27 +374,39 @@ class NameFilterTestAbsWin(PicardTestCase):
def test_plugin_path_long_1(self):
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.assertEqual(record.name, '/user/picard/plugins/path2/plugins/plugin')
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
def test_plugin_path_long_2(self):
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.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):
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.assertEqual(record.name, 'plugins/path2/plugins/plugin')
self.assertEqual(record.name, '/path1/path2/plugins/plugin')
def test_plugin_path_short_2(self):
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.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")