diff --git a/picard/log.py b/picard/log.py index b2b1b25580..47a4b77861 100644 --- a/picard/log.py +++ b/picard/log.py @@ -36,7 +36,7 @@ import logging from pathlib import ( Path, - PurePosixPath, + PurePath, ) from threading import Lock @@ -200,7 +200,7 @@ def name_filter(record): # 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(PurePath(*parts)) return True diff --git a/test/test_log.py b/test/test_log.py index bdfad8cfa6..6ab2630258 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -288,7 +288,7 @@ class NameFilterTestRelWin(PicardTestCase): def test_1(self): record = FakeRecord(name=None, pathname='C:/path1/path2/module/file.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, 'module/file') + self.assertEqual(record.name, 'module\\file') def test_2(self): record = FakeRecord(name=None, pathname='C:/path1/path2/module/__init__.py') @@ -298,7 +298,7 @@ def test_2(self): def test_3(self): record = FakeRecord(name=None, pathname='C:/path1/path2/module/subpath/file.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, 'module/subpath/file') + self.assertEqual(record.name, 'module\\subpath\\file') def test_4(self): record = FakeRecord(name=None, pathname='') @@ -308,43 +308,43 @@ def test_4(self): def test_5(self): record = FakeRecord(name=None, pathname='C:/path1/path2/__init__/module/__init__.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '__init__/module') + self.assertEqual(record.name, '__init__\\module') def test_plugin_path_long_1(self): DebugOpt.PLUGIN_FULLPATH.enabled = True record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/plugin.zip') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/user/picard/plugins/path3/plugins/plugin') + self.assertEqual(record.name, '\\user\\picard\\plugins\\path3\\plugins\\plugin') 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.py') 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') def test_plugin_path_short_1(self): DebugOpt.PLUGIN_FULLPATH.enabled = False record = FakeRecord(name=None, pathname='C:/user/picard/plugins/path3/plugins/plugin.zip') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, 'plugins/path3/plugins/plugin') + self.assertEqual(record.name, 'plugins\\path3\\plugins\\plugin') 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.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, 'plugins/path3/plugins/plugin.zip/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') + 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') + self.assertEqual(record.name, 'plugins\\path3\\plugins\\myplugin.zip') @unittest.skipUnless(IS_WIN, "Windows test") @@ -355,17 +355,17 @@ class NameFilterTestAbsWin(PicardTestCase): def test_1(self): record = FakeRecord(name=None, pathname='C:/path/module/file.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path/module/file') + self.assertEqual(record.name, '\\path\\module\\file') def test_2(self): record = FakeRecord(name=None, pathname='C:/path/module/__init__.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path/module') + self.assertEqual(record.name, '\\path\\module') def test_3(self): record = FakeRecord(name=None, pathname='C:/path/module/subpath/file.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path/module/subpath/file') + self.assertEqual(record.name, '\\path\\module\\subpath\\file') def test_4(self): record = FakeRecord(name=None, pathname='') @@ -376,37 +376,37 @@ def test_plugin_path_long_1(self): DebugOpt.PLUGIN_FULLPATH.enabled = True record = FakeRecord(name=None, pathname='C:/path1/path2/plugins/plugin.zip') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path1/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:/path1/path2/plugins/plugin.zip/xxx.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path1/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:/path1/path2/plugins/plugin.zip') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path1/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:/path1/path2/plugins/plugin.zip/xxx.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path1/path2/plugins/plugin.zip/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') + 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') + self.assertEqual(record.name, '\\path1\\path2\\plugins\\myplugin.zip') @unittest.skipUnless(IS_WIN, "Windows test") @@ -417,4 +417,4 @@ class NameFilterTestEndingSlashWin(PicardTestCase): def test_1(self): record = FakeRecord(name=None, pathname='C:/path3/module/file.py') self.assertTrue(name_filter(record)) - self.assertEqual(record.name, '/path3/module/file') + self.assertEqual(record.name, '\\path3\\module\\file')