Chore: switch from os.path to pathlib.Path (#10539)

This commit is contained in:
Sebastian Steinbeißer
2025-09-03 17:12:41 +02:00
committed by GitHub
parent cc621cf729
commit d2064a2535
11 changed files with 151 additions and 165 deletions

View File

@@ -654,7 +654,7 @@ class TestClassifier(DirectoriesMixin, TestCase):
},
)
@override_settings(
MODEL_FILE=(Path(__file__).parent / "data" / "model.pickle").as_posix(),
MODEL_FILE=str(Path(__file__).parent / "data" / "model.pickle"),
)
@pytest.mark.skip(
reason="Disabled caching due to high memory usage - need to investigate.",

View File

@@ -254,7 +254,7 @@ class TestConsumer(
# https://github.com/jonaswinkler/paperless-ng/discussions/1037
filename = self.get_test_file()
shadow_file = Path(self.dirs.scratch_dir / "._sample.pdf")
shadow_file = Path(self.dirs.scratch_dir) / "._sample.pdf"
shutil.copy(filename, shadow_file)

View File

@@ -258,66 +258,66 @@ class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
def test_is_ignored(self):
test_paths = [
{
"path": (Path(self.dirs.consumption_dir) / "foo.pdf").as_posix(),
"path": str(Path(self.dirs.consumption_dir) / "foo.pdf"),
"ignore": False,
},
{
"path": (
Path(self.dirs.consumption_dir) / "foo" / "bar.pdf"
).as_posix(),
"path": str(
Path(self.dirs.consumption_dir) / "foo" / "bar.pdf",
),
"ignore": False,
},
{
"path": (Path(self.dirs.consumption_dir) / ".DS_STORE").as_posix(),
"path": str(Path(self.dirs.consumption_dir) / ".DS_STORE"),
"ignore": True,
},
{
"path": (Path(self.dirs.consumption_dir) / ".DS_Store").as_posix(),
"path": str(Path(self.dirs.consumption_dir) / ".DS_Store"),
"ignore": True,
},
{
"path": (
Path(self.dirs.consumption_dir) / ".stfolder" / "foo.pdf"
).as_posix(),
"path": str(
Path(self.dirs.consumption_dir) / ".stfolder" / "foo.pdf",
),
"ignore": True,
},
{
"path": (Path(self.dirs.consumption_dir) / ".stfolder.pdf").as_posix(),
"path": str(Path(self.dirs.consumption_dir) / ".stfolder.pdf"),
"ignore": False,
},
{
"path": (
Path(self.dirs.consumption_dir) / ".stversions" / "foo.pdf"
).as_posix(),
"path": str(
Path(self.dirs.consumption_dir) / ".stversions" / "foo.pdf",
),
"ignore": True,
},
{
"path": (
Path(self.dirs.consumption_dir) / ".stversions.pdf"
).as_posix(),
"path": str(
Path(self.dirs.consumption_dir) / ".stversions.pdf",
),
"ignore": False,
},
{
"path": (Path(self.dirs.consumption_dir) / "._foo.pdf").as_posix(),
"path": str(Path(self.dirs.consumption_dir) / "._foo.pdf"),
"ignore": True,
},
{
"path": (Path(self.dirs.consumption_dir) / "my_foo.pdf").as_posix(),
"path": str(Path(self.dirs.consumption_dir) / "my_foo.pdf"),
"ignore": False,
},
{
"path": (
Path(self.dirs.consumption_dir) / "._foo" / "bar.pdf"
).as_posix(),
"path": str(
Path(self.dirs.consumption_dir) / "._foo" / "bar.pdf",
),
"ignore": True,
},
{
"path": (
"path": str(
Path(self.dirs.consumption_dir)
/ "@eaDir"
/ "SYNO@.fileindexdb"
/ "_1jk.fnm"
).as_posix(),
/ "_1jk.fnm",
),
"ignore": True,
},
]
@@ -330,7 +330,7 @@ class TestConsumer(DirectoriesMixin, ConsumerThreadMixin, TransactionTestCase):
f'_is_ignored("{filepath}") != {expected_ignored_result}',
)
@mock.patch("documents.management.commands.document_consumer.open")
@mock.patch("documents.management.commands.document_consumer.Path.open")
def test_consume_file_busy(self, open_mock):
# Calling this mock always raises this
open_mock.side_effect = OSError

View File

@@ -230,9 +230,9 @@ class TestExportImport(
for element in manifest:
if element["model"] == "documents.document":
fname = (
self.target / element[document_exporter.EXPORTER_FILE_NAME]
).as_posix()
fname = str(
self.target / element[document_exporter.EXPORTER_FILE_NAME],
)
self.assertIsFile(fname)
self.assertIsFile(
self.target / element[document_exporter.EXPORTER_THUMBNAIL_NAME],
@@ -462,9 +462,9 @@ class TestExportImport(
call_command(*args)
expected_file = (
self.target / f"export-{timezone.localdate().isoformat()}.zip"
).as_posix()
expected_file = str(
self.target / f"export-{timezone.localdate().isoformat()}.zip",
)
self.assertIsFile(expected_file)
@@ -498,9 +498,9 @@ class TestExportImport(
):
call_command(*args)
expected_file = (
self.target / f"export-{timezone.localdate().isoformat()}.zip"
).as_posix()
expected_file = str(
self.target / f"export-{timezone.localdate().isoformat()}.zip",
)
self.assertIsFile(expected_file)
@@ -544,9 +544,9 @@ class TestExportImport(
call_command(*args)
expected_file = (
self.target / f"export-{timezone.localdate().isoformat()}.zip"
).as_posix()
expected_file = str(
self.target / f"export-{timezone.localdate().isoformat()}.zip",
)
self.assertIsFile(expected_file)
self.assertIsNotFile(existing_file)

View File

@@ -19,15 +19,15 @@ migration_1012_obj = importlib.import_module(
)
def archive_name_from_filename(filename):
return Path(filename).stem + ".pdf"
def archive_name_from_filename(filename: Path) -> Path:
return Path(filename.stem + ".pdf")
def archive_path_old(self):
def archive_path_old(self) -> Path:
if self.filename:
fname = archive_name_from_filename(self.filename)
fname = archive_name_from_filename(Path(self.filename))
else:
fname = f"{self.pk:07}.pdf"
fname = Path(f"{self.pk:07}.pdf")
return Path(settings.ARCHIVE_DIR) / fname