From 495736a369736d22f7946488c39e154774e5e717 Mon Sep 17 00:00:00 2001 From: Bob Swift Date: Mon, 15 Apr 2024 12:47:16 -0600 Subject: [PATCH] Include zip file in short path. Improve tests regarding plugin paths. --- picard/log.py | 7 +++- test/test_log.py | 98 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 82 insertions(+), 23 deletions(-) diff --git a/picard/log.py b/picard/log.py index 2ac035cec..06a6d20ff 100644 --- a/picard/log.py +++ b/picard/log.py @@ -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 diff --git a/test/test_log.py b/test/test_log.py index 0034cfafd..bdfad8cfa 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -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")