]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Changes the simple-alpha parsing test to use a tempdir so the original isn't modified...
authorTrenton Holmes <holmes.trenton@gmail.com>
Tue, 14 Jun 2022 00:14:38 +0000 (17:14 -0700)
committerTrenton Holmes <holmes.trenton@gmail.com>
Sat, 2 Jul 2022 14:19:22 +0000 (16:19 +0200)
src/paperless_tesseract/tests/test_parser.py

index 97ec26ca99d0330b4ced3115a771a92f2e87bd69..6bf8bd5f45b6c5cf0a21e8e38c5b7ebd2d18d036 100644 (file)
@@ -1,4 +1,6 @@
 import os
+import shutil
+import tempfile
 import uuid
 from typing import ContextManager
 from unittest import mock
@@ -225,11 +227,18 @@ class TestParser(DirectoriesMixin, TestCase):
     def test_image_simple_alpha(self):
         parser = RasterisedDocumentParser(None)
 
-        parser.parse(os.path.join(self.SAMPLE_FILES, "simple-alpha.png"), "image/png")
+        with tempfile.TemporaryDirectory() as tempdir:
+            # Copy sample file to temp directory, as the parsing changes the file
+            # and this makes it modified to Git
+            sample_file = os.path.join(self.SAMPLE_FILES, "simple-alpha.png")
+            dest_file = os.path.join(tempdir, "simple-alpha.png")
+            shutil.copy(sample_file, dest_file)
 
-        self.assertTrue(os.path.isfile(parser.archive_path))
+            parser.parse(dest_file, "image/png")
 
-        self.assertContainsStrings(parser.get_text(), ["This is a test document."])
+            self.assertTrue(os.path.isfile(parser.archive_path))
+
+            self.assertContainsStrings(parser.get_text(), ["This is a test document."])
 
     def test_image_calc_a4_dpi(self):
         parser = RasterisedDocumentParser(None)