]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix log matches related to newlines, add newlines to stdout.writelines
authorshamoon <4887959+shamoon@users.noreply.github.com>
Wed, 6 Aug 2025 20:09:31 +0000 (16:09 -0400)
committershamoon <4887959+shamoon@users.noreply.github.com>
Wed, 6 Aug 2025 20:09:31 +0000 (16:09 -0400)
src/documents/management/commands/document_fuzzy_match.py
src/documents/tests/test_management_fuzzy.py

index 9e01ff1b06cb850a4d86b51d3390e1fa4389b23d..5eebeb1720a2b90f08c97eb745f5ca0e4537d585 100644 (file)
@@ -125,14 +125,14 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand):
                 messages.append(
                     self.style.NOTICE(
                         f"Document {result.doc_one_pk} fuzzy match"
-                        f" to {result.doc_two_pk} (confidence {result.ratio:.3f})",
+                        f" to {result.doc_two_pk} (confidence {result.ratio:.3f})\n",
                     ),
                 )
                 maybe_delete_ids.append(result.doc_two_pk)
 
         if len(messages) == 0:
             messages.append(
-                self.style.SUCCESS("No matches found"),
+                self.style.SUCCESS("No matches found\n"),
             )
         self.stdout.writelines(
             messages,
index 7cc1f265ea9a6a9c98f56d2ac89dbc9a48b580cd..2d7d3735af762e6b6bcf6424cb863430b3a62c6e 100644 (file)
@@ -87,7 +87,7 @@ class TestFuzzyMatchCommand(TestCase):
             filename="other_test.pdf",
         )
         stdout, _ = self.call_command()
-        self.assertEqual(stdout, "No matches found\n")
+        self.assertIn("No matches found", stdout)
 
     def test_with_matches(self):
         """
@@ -116,7 +116,7 @@ class TestFuzzyMatchCommand(TestCase):
             filename="other_test.pdf",
         )
         stdout, _ = self.call_command("--processes", "1")
-        self.assertRegex(stdout, self.MSG_REGEX + "\n")
+        self.assertRegex(stdout, self.MSG_REGEX)
 
     def test_with_3_matches(self):
         """
@@ -152,11 +152,10 @@ class TestFuzzyMatchCommand(TestCase):
             filename="final_test.pdf",
         )
         stdout, _ = self.call_command()
-        lines = [x.strip() for x in stdout.split("\n") if len(x.strip())]
+        lines = [x.strip() for x in stdout.splitlines() if x.strip()]
         self.assertEqual(len(lines), 3)
-        self.assertRegex(lines[0], self.MSG_REGEX)
-        self.assertRegex(lines[1], self.MSG_REGEX)
-        self.assertRegex(lines[2], self.MSG_REGEX)
+        for line in lines:
+            self.assertRegex(line, self.MSG_REGEX)
 
     def test_document_deletion(self):
         """
@@ -197,14 +196,12 @@ class TestFuzzyMatchCommand(TestCase):
 
         stdout, _ = self.call_command("--delete")
 
-        lines = [x.strip() for x in stdout.split("\n") if len(x.strip())]
-        self.assertEqual(len(lines), 3)
-        self.assertEqual(
-            lines[0],
+        self.assertIn(
             "The command is configured to delete documents.  Use with caution",
+            stdout,
         )
-        self.assertRegex(lines[1], self.MSG_REGEX)
-        self.assertEqual(lines[2], "Deleting 1 documents based on ratio matches")
+        self.assertRegex(stdout, self.MSG_REGEX)
+        self.assertIn("Deleting 1 documents based on ratio matches", stdout)
 
         self.assertEqual(Document.objects.count(), 2)
         self.assertIsNotNone(Document.objects.get(pk=1))