Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Rework tests to write to /tmp

Daniel Quinnc90ed2da1dc9
diff --git a/src/paperless_tesseract/tests/test_date.py b/src/paperless_tesseract/tests/test_date.py
index 019d5199a..9f81b0a56 100644
--- a/src/paperless_tesseract/tests/test_date.py
+++ b/src/paperless_tesseract/tests/test_date.py
@@ -1,20 +1,29 @@
+import datetime
import os
-from unittest import skipIf, mock
+import shutil
+from unittest import mock
+from uuid import uuid4
-import pyocr
+from dateutil import tz
from django.test import TestCase
from ..parsers import RasterisedDocumentParser
-import datetime
-from dateutil import tz
class TestDate(TestCase):
+
SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples")
+ SCRATCH = "/tmp/paperless-tests-{}".format(str(uuid4())[:8])
+
+ def setUp(self):
+ os.makedirs(self.SCRATCH, exist_ok=True)
+
+ def tearDown(self):
+ shutil.rmtree(self.SCRATCH)
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_1_pdf(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_1.pdf")
@@ -27,7 +36,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_1_png(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_1.png")
@@ -40,7 +49,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_2_pdf(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_2.pdf")
@@ -53,7 +62,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_2_png(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_2.png")
@@ -66,7 +75,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_3_pdf(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_3.pdf")
@@ -79,7 +88,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_3_png(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_3.png")
@@ -92,7 +101,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_4_pdf(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_4.pdf")
@@ -105,7 +114,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_4_png(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_4.png")
@@ -118,7 +127,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_5_pdf(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_5.pdf")
@@ -131,7 +140,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_5_png(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_5.png")
@@ -144,7 +153,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_6_pdf_us(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.pdf")
@@ -158,7 +167,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_6_png_us(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.png")
@@ -172,7 +181,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_6_pdf_eu(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.pdf")
@@ -183,7 +192,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_6_png_eu(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_6.png")
@@ -194,7 +203,7 @@ class TestDate(TestCase):
@mock.patch(
"paperless_tesseract.parsers.RasterisedDocumentParser.SCRATCH",
- SAMPLE_FILES
+ SCRATCH
)
def test_get_text_7_pdf(self):
input_file = os.path.join(self.SAMPLE_FILES, "tests_date_7.pdf")