Fix log matches related to newlines, add newlines to stdout.writelines

This commit is contained in:
shamoon 2025-05-13 09:21:10 -07:00
parent 777299fcb9
commit b8419671c9
No known key found for this signature in database
2 changed files with 11 additions and 14 deletions

View 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,

View 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))