run black

Signed-off-by: florian on nixos (Florian Brandes) <florian.brandes@posteo.de>
This commit is contained in:
florian on nixos (Florian Brandes) 2022-03-24 21:30:34 +01:00 committed by Florian Brandes
parent 78ca2ffaba
commit 50f474ae92
2 changed files with 24 additions and 7 deletions

View File

@ -21,6 +21,7 @@ from pdf2image import convert_from_path
from pikepdf import Pdf from pikepdf import Pdf
from pyzbar import pyzbar from pyzbar import pyzbar
from whoosh.writing import AsyncWriter from whoosh.writing import AsyncWriter
# barcode decoder # barcode decoder
logger = logging.getLogger("paperless.tasks") logger = logging.getLogger("paperless.tasks")
@ -156,6 +157,7 @@ def separate_pages(filepath: str, pages_to_split_on: list) -> list:
logger.debug(f"Temp files are {str(document_paths)}") logger.debug(f"Temp files are {str(document_paths)}")
return document_paths return document_paths
def save_to_dir(filepath, target_dir=settings.CONSUMPTION_DIR): def save_to_dir(filepath, target_dir=settings.CONSUMPTION_DIR):
""" """
Copies filepath to target_dir. Copies filepath to target_dir.
@ -165,6 +167,7 @@ def save_to_dir(filepath, target_dir=settings.CONSUMPTION_DIR):
else: else:
logger.warning(f"{str(filepath)} or {str(target_dir)} don't exist.") logger.warning(f"{str(filepath)} or {str(target_dir)} don't exist.")
def consume_file( def consume_file(
path, path,
override_filename=None, override_filename=None,

View File

@ -93,7 +93,9 @@ class TestTasks(DirectoriesMixin, TestCase):
def test_barcode_reader(self): def test_barcode_reader(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t.pbm", os.path.dirname(__file__),
"samples",
"patch-code-t.pbm",
) )
img = Image.open(test_file) img = Image.open(test_file)
self.assertEqual(tasks.barcode_reader(img), ["b'PATCHT'"]) self.assertEqual(tasks.barcode_reader(img), ["b'PATCHT'"])
@ -105,7 +107,9 @@ class TestTasks(DirectoriesMixin, TestCase):
def test_scan_file_for_separating_barcodes(self): def test_scan_file_for_separating_barcodes(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t.pdf", os.path.dirname(__file__),
"samples",
"patch-code-t.pdf",
) )
pages = tasks.scan_file_for_separating_barcodes(test_file) pages = tasks.scan_file_for_separating_barcodes(test_file)
self.assertEqual(pages, [0]) self.assertEqual(pages, [0])
@ -117,21 +121,27 @@ class TestTasks(DirectoriesMixin, TestCase):
def test_scan_file_for_separating_barcodes3(self): def test_scan_file_for_separating_barcodes3(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t-middle.pdf", os.path.dirname(__file__),
"samples",
"patch-code-t-middle.pdf",
) )
pages = tasks.scan_file_for_separating_barcodes(test_file) pages = tasks.scan_file_for_separating_barcodes(test_file)
self.assertEqual(pages, [1]) self.assertEqual(pages, [1])
def test_separate_pages(self): def test_separate_pages(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t-middle.pdf", os.path.dirname(__file__),
"samples",
"patch-code-t-middle.pdf",
) )
pages = tasks.separate_pages(test_file, [1]) pages = tasks.separate_pages(test_file, [1])
self.assertEqual(len(pages), 2) self.assertEqual(len(pages), 2)
def test_save_to_dir(self): def test_save_to_dir(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t.pdf", os.path.dirname(__file__),
"samples",
"patch-code-t.pdf",
) )
tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR) tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR)
tasks.save_to_dir(test_file, tempdir) tasks.save_to_dir(test_file, tempdir)
@ -140,7 +150,9 @@ class TestTasks(DirectoriesMixin, TestCase):
def test_save_to_dir2(self): def test_save_to_dir2(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t.pdf", os.path.dirname(__file__),
"samples",
"patch-code-t.pdf",
) )
nonexistingdir = "/nowhere" nonexistingdir = "/nowhere"
if os.path.isdir(nonexistingdir): if os.path.isdir(nonexistingdir):
@ -157,7 +169,9 @@ class TestTasks(DirectoriesMixin, TestCase):
def test_barcode_splitter(self): def test_barcode_splitter(self):
test_file = os.path.join( test_file = os.path.join(
os.path.dirname(__file__), "samples", "patch-code-t-middle.pdf", os.path.dirname(__file__),
"samples",
"patch-code-t-middle.pdf",
) )
tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR) tempdir = tempfile.mkdtemp(prefix="paperless-", dir=settings.SCRATCH_DIR)
separators = tasks.scan_file_for_separating_barcodes(test_file) separators = tasks.scan_file_for_separating_barcodes(test_file)