Skip to content

Commit

Permalink
Fix log path name_filter on Windows with Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
phw committed Dec 29, 2024
1 parent fb2c5ec commit 21c5dbf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions picard/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import logging
from pathlib import (
Path,
PurePosixPath,
PurePath,
)
from threading import Lock

Expand Down Expand Up @@ -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


Expand Down
38 changes: 19 additions & 19 deletions test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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='')
Expand All @@ -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")
Expand All @@ -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='')
Expand All @@ -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")
Expand All @@ -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')

0 comments on commit 21c5dbf

Please sign in to comment.