From 06cfc3113aaf97d41a58fbd3df43349e080499a4 Mon Sep 17 00:00:00 2001 From: jonaswinkler Date: Fri, 27 Nov 2020 14:06:37 +0100 Subject: [PATCH] test case fixes. --- src/paperless_tesseract/tests/test_ocr.py | 34 ------------------ src/paperless_tesseract/tests/test_parser.py | 36 ++++++++++++++------ 2 files changed, 26 insertions(+), 44 deletions(-) delete mode 100644 src/paperless_tesseract/tests/test_ocr.py diff --git a/src/paperless_tesseract/tests/test_ocr.py b/src/paperless_tesseract/tests/test_ocr.py deleted file mode 100644 index 7124fbed6..000000000 --- a/src/paperless_tesseract/tests/test_ocr.py +++ /dev/null @@ -1,34 +0,0 @@ -import os -from unittest import mock, skipIf - -from django.test import TestCase - -from ..parsers import strip_excess_whitespace - - -class TestOCR(TestCase): - - text_cases = [ - ("simple string", "simple string"), - ( - "simple newline\n testing string", - "simple newline\ntesting string" - ), - ( - "utf-8 строка с пробелами в конце ", - "utf-8 строка с пробелами в конце" - ) - ] - - def test_strip_excess_whitespace(self): - for source, result in self.text_cases: - actual_result = strip_excess_whitespace(source) - self.assertEqual( - result, - actual_result, - "strip_exceess_whitespace({}) != '{}', but '{}'".format( - source, - result, - actual_result - ) - ) diff --git a/src/paperless_tesseract/tests/test_parser.py b/src/paperless_tesseract/tests/test_parser.py index 70fb494ef..18af3ed59 100644 --- a/src/paperless_tesseract/tests/test_parser.py +++ b/src/paperless_tesseract/tests/test_parser.py @@ -1,6 +1,4 @@ import os -import shutil -import tempfile import uuid from typing import ContextManager from unittest import mock @@ -8,7 +6,8 @@ from unittest import mock from django.test import TestCase, override_settings from documents.parsers import ParseError, run_convert -from paperless_tesseract.parsers import RasterisedDocumentParser, get_text_from_pdf +from documents.tests.utils import DirectoriesMixin +from paperless_tesseract.parsers import RasterisedDocumentParser, get_text_from_pdf, strip_excess_whitespace image_to_string_calls = [] @@ -33,15 +32,32 @@ class FakeImageFile(ContextManager): return os.path.basename(self.fname) -class TestParser(TestCase): +class TestParser(DirectoriesMixin, TestCase): - def setUp(self): - self.scratch = tempfile.mkdtemp() + text_cases = [ + ("simple string", "simple string"), + ( + "simple newline\n testing string", + "simple newline\ntesting string" + ), + ( + "utf-8 строка с пробелами в конце ", + "utf-8 строка с пробелами в конце" + ) + ] - override_settings(SCRATCH_DIR=self.scratch).enable() - - def tearDown(self): - shutil.rmtree(self.scratch) + def test_strip_excess_whitespace(self): + for source, result in self.text_cases: + actual_result = strip_excess_whitespace(source) + self.assertEqual( + result, + actual_result, + "strip_exceess_whitespace({}) != '{}', but '{}'".format( + source, + result, + actual_result + ) + ) SAMPLE_FILES = os.path.join(os.path.dirname(__file__), "samples")