Commit ad5d1dbc authored by Christian Rohlfing's avatar Christian Rohlfing
Browse files

Add first unittests

parent a63ee3d7
import unittest
import time
import os
import tempfile
import shutil
class MainTest(unittest.TestCase):
def setUp(self):
self.tic = time.time() # todo this is sooo ugly
self.test_dir = tempfile.mkdtemp()
def tearDown(self):
self.toc = time.time()
t = self.toc - self.tic
print('Time: %.3f' % (t))
def test_supplements_watermark(self):
import supplements
import watermark
import utils.matnum as utils
expected_files = ['123456_Nachname_GDET3_20H_loes_w.pdf', '123456_Nachname_GDET3_20H_w.pdf',
'456789_Lastname_GDET3_20H_loes_w.pdf', '456789_Lastname_GDET3_20H_w.pdf']
# Prepare parameter
supp_dir = './supplements'
pdf_dir = './pdfs'
dpi = 250
supp_out_dir = os.path.join(self.test_dir, 'supplements_out')
os.mkdir(supp_out_dir)
tmp_dir = os.path.join(self.test_dir, 'tmp')
os.mkdir(tmp_dir)
out_dir = os.path.join(self.test_dir, 'out')
os.mkdir(out_dir)
# Copy supplements file
supplements.main(["-s", supp_dir, "-p", pdf_dir, "-o", supp_out_dir])
# Watermark files
watermark.main(["-i", supp_out_dir, "-o", out_dir,
"-t", tmp_dir, "--dpi", str(dpi)])
# Assert output
created_files = os.listdir(out_dir)
created_files.sort()
self.assertEqual(expected_files, created_files)
import unittest
import time
import os
import tempfile
import shutil
class MainTest(unittest.TestCase):
def setUp(self):
self.tic = time.time() # todo this is sooo ugly
self.test_dir = tempfile.mkdtemp()
def tearDown(self):
self.toc = time.time()
t = self.toc - self.tic
print('Time: %.3f' % (t))
# Clean up
shutil.rmtree(self.test_dir)
def test_watermark_single_pdf(self):
import watermark
# Prepare parameter
in_dir = './pdfs'
dpi = 250
pdf_file = '123456_Nachname.pdf'
tmp_dir = os.path.join(self.test_dir, 'tmp')
os.mkdir(tmp_dir)
out_dir = os.path.join(self.test_dir, 'out')
os.mkdir(out_dir)
# Call function
watermark.watermark_pdf(in_dir, tmp_dir, out_dir, dpi, pdf_file)
self.assertTrue(os.listdir(out_dir)[0], '123456_Nachname_w.pdf')
def test_watermark_pdfs(self):
import watermark
# Prepare parameter
in_dir = './pdfs'
dpi = 250
tmp_dir = os.path.join(self.test_dir, 'tmp')
os.mkdir(tmp_dir)
out_dir = os.path.join(self.test_dir, 'out')
os.mkdir(out_dir)
# Watermark files
watermark.main(["-i", in_dir, "-o", out_dir,
"-t", tmp_dir, "--dpi", str(dpi)])
self.assertTrue(True)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment