TST: Remove unittest boilerplate.

parent 2595593a
......@@ -41,7 +41,7 @@ class BaseTest(object):
def set_builder(self):
raise NotImplementedError("Implemented in subclasses.")
def setUp(self):
def setup(self):
self.set_builder()
def _test_txt(self, image_file, expected_output_file, lang='eng'):
......
......@@ -3,17 +3,16 @@ import codecs
import tempfile
import pytest
import unittest
from pyocr import cuneiform
from . import tests_base as base
class TestContext(unittest.TestCase):
class TestContext(object):
"""
These tests make sure the requirements for the tests are met.
"""
def setUp(self):
def setup(self):
pass
def test_available(self):
......@@ -27,7 +26,7 @@ class TestContext(unittest.TestCase):
assert "eng" in langs
assert "fra" in langs
def tearDown(self):
def teardown(self):
pass
......@@ -43,13 +42,13 @@ class BaseCuneiform(base.BaseTest):
)
class TestTxt(unittest.TestCase, base.BaseTestText, BaseCuneiform):
class TestTxt(base.BaseTestText, BaseCuneiform):
"""
These tests make sure the "usual" OCR works fine. (the one generating
a .txt file)
"""
def setUp(self):
super(TestTxt, self).setUp()
def setup(self):
super(TestTxt, self).setup()
self.tool = cuneiform
self.set_builder()
......@@ -62,13 +61,13 @@ class TestTxt(unittest.TestCase, base.BaseTestText, BaseCuneiform):
def test_french(self):
self._test_txt('test-french.jpg', 'test-french.txt', 'fra')
def tearDown(self):
def teardown(self):
pass
class TestDigit(base.BaseTestDigit, BaseCuneiform, unittest.TestCase):
def setUp(self):
super(TestDigit, self).setUp()
class TestDigit(base.BaseTestDigit, BaseCuneiform):
def setup(self):
super(TestDigit, self).setup()
self.tool = cuneiform
self.set_builder()
......@@ -78,12 +77,12 @@ class TestDigit(base.BaseTestDigit, BaseCuneiform, unittest.TestCase):
self._read_from_img(image_path)
class TestWordBox(base.BaseTestWordBox, BaseCuneiform, unittest.TestCase):
class TestWordBox(base.BaseTestWordBox, BaseCuneiform):
"""
These tests make sure that cuneiform box handling works fine.
"""
def setUp(self):
super(TestWordBox, self).setUp()
def setup(self):
super(TestWordBox, self).setup()
self.tool = cuneiform
self.set_builder()
......@@ -120,49 +119,6 @@ class TestWordBox(base.BaseTestWordBox, BaseCuneiform, unittest.TestCase):
os.remove(tmp_path)
class TestOrientation(unittest.TestCase):
class TestOrientation(object):
def test_can_detect_orientation(self):
assert not cuneiform.can_detect_orientation()
def get_all_tests():
all_tests = unittest.TestSuite()
test_names = [
'test_available',
'test_version',
'test_langs',
]
tests = unittest.TestSuite(map(TestContext, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
'test_european',
'test_french',
]
tests = unittest.TestSuite(map(TestTxt, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
'test_european',
'test_french',
'test_write_read',
]
tests = unittest.TestSuite(map(TestWordBox, test_names))
all_tests.addTest(tests)
test_names = [
'test_digits_not_implemented'
]
tests = unittest.TestSuite(map(TestDigit, test_names))
all_tests.addTest(tests)
test_names = [
'test_can_detect_orientation',
]
tests = unittest.TestSuite(map(TestOrientation, test_names))
all_tests.addTest(tests)
return all_tests
......@@ -3,7 +3,6 @@ import os
import tempfile
import pytest
import unittest
import PIL.Image
......@@ -13,11 +12,11 @@ from pyocr import PyocrException
from . import tests_base as base
class TestContext(unittest.TestCase):
class TestContext(object):
"""
These tests make sure the requirements for the tests are met.
"""
def setUp(self):
def setup(self):
pass
def test_available(self):
......@@ -52,7 +51,7 @@ class TestContext(unittest.TestCase):
else:
os.environ['TESSDATA_PREFIX'] = tessdata_prefix
def tearDown(self):
def teardown(self):
pass
......@@ -70,7 +69,7 @@ class BaseLibtesseract(base.BaseTest):
)
class TestTxt(base.BaseTestText, BaseLibtesseract, unittest.TestCase):
class TestTxt(base.BaseTestText, BaseLibtesseract):
"""
These tests make sure the "usual" OCR works fine. (the one generating
a .txt file)
......@@ -117,7 +116,7 @@ class TestTxt(base.BaseTestText, BaseLibtesseract, unittest.TestCase):
)
class TestDigit(base.BaseTestDigit, BaseLibtesseract, unittest.TestCase):
class TestDigit(base.BaseTestDigit, BaseLibtesseract):
"""
These tests make sure that Tesseract digits handling works fine.
"""
......@@ -125,7 +124,7 @@ class TestDigit(base.BaseTestDigit, BaseLibtesseract, unittest.TestCase):
self._test_txt('test-digits.png', 'test-digits.txt')
class TestWordBox(base.BaseTestWordBox, BaseLibtesseract, unittest.TestCase):
class TestWordBox(base.BaseTestWordBox, BaseLibtesseract):
"""
These tests make sure that Tesseract box handling works fine.
"""
......@@ -164,7 +163,7 @@ class TestWordBox(base.BaseTestWordBox, BaseLibtesseract, unittest.TestCase):
os.remove(tmp_path)
class TestLineBox(base.BaseTestLineBox, BaseLibtesseract, unittest.TestCase):
class TestLineBox(base.BaseTestLineBox, BaseLibtesseract):
"""
These tests make sure that Tesseract box handling works fine.
"""
......@@ -203,13 +202,12 @@ class TestLineBox(base.BaseTestLineBox, BaseLibtesseract, unittest.TestCase):
os.remove(tmp_path)
class TestDigitLineBox(base.BaseTestDigitLineBox, BaseLibtesseract,
unittest.TestCase):
class TestDigitLineBox(base.BaseTestDigitLineBox, BaseLibtesseract):
def test_digits(self):
self._test_txt('test-digits.png', 'test-digits.lines')
class TestOrientation(BaseLibtesseract, unittest.TestCase):
class TestOrientation(BaseLibtesseract):
def set_builder(self):
self._builder = builders.TextBuilder()
......@@ -227,7 +225,7 @@ class TestOrientation(BaseLibtesseract, unittest.TestCase):
assert result['angle'] == 90
class TestBasicDoc(base.BaseTestLineBox, unittest.TestCase):
class TestBasicDoc(base.BaseTestLineBox):
"""
These tests make sure that Tesseract box handling works fine.
"""
......@@ -247,7 +245,7 @@ class TestBasicDoc(base.BaseTestLineBox, unittest.TestCase):
self._test_txt('basic_doc.jpg', 'basic_doc.lines')
class TestPdf(base.BaseTestPdf, unittest.TestCase):
class TestPdf(base.BaseTestPdf):
tool = libtesseract
def _path_to_img(self, image_file):
......@@ -262,63 +260,3 @@ class TestPdf(base.BaseTestPdf, unittest.TestCase):
def test_basic(self):
self._test_pdf('basic_doc.jpg')
def get_all_tests():
all_tests = unittest.TestSuite()
test_names = [
'test_available',
'test_version',
'test_langs',
'test_nolangs',
]
tests = unittest.TestSuite(map(TestContext, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
'test_european',
'test_french',
'test_japanese',
'test_multi',
'test_nolangs',
]
tests = unittest.TestSuite(map(TestTxt, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
'test_european',
'test_french',
'test_japanese',
'test_write_read',
]
tests = unittest.TestSuite(map(TestWordBox, test_names))
all_tests.addTest(tests)
tests = unittest.TestSuite(map(TestLineBox, test_names))
all_tests.addTest(tests)
test_names = [
'test_digits'
]
tests = unittest.TestSuite(map(TestDigit, test_names))
all_tests.addTest(tests)
tests = unittest.TestSuite(map(TestDigitLineBox, test_names))
all_tests.addTest(tests)
test_names = [
'test_can_detect_orientation',
'test_orientation_0',
'test_orientation_90',
]
tests = unittest.TestSuite(map(TestOrientation, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
]
tests = unittest.TestSuite(map(TestBasicDoc, test_names))
all_tests.addTest(tests)
return all_tests
......@@ -2,18 +2,16 @@ import os
import codecs
import tempfile
import unittest
from pyocr import builders
from pyocr import tesseract
from . import tests_base as base
class TestContext(unittest.TestCase):
class TestContext(object):
"""
These tests make sure the requirements for the tests are met.
"""
def setUp(self):
def setup(self):
pass
def test_available(self):
......@@ -35,7 +33,7 @@ class TestContext(unittest.TestCase):
assert "fra" in langs
assert "jpn" in langs
def tearDown(self):
def teardown(self):
pass
......@@ -53,7 +51,7 @@ class BaseTesseract(base.BaseTest):
)
class TestTxt(base.BaseTestText, BaseTesseract, unittest.TestCase):
class TestTxt(base.BaseTestText, BaseTesseract):
"""
These tests make sure the "usual" OCR works fine. (the one generating
a .txt file)
......@@ -74,7 +72,7 @@ class TestTxt(base.BaseTestText, BaseTesseract, unittest.TestCase):
self._test_txt('test-european.jpg', 'test-european.txt', 'eng+fra')
class TestCharBox(base.BaseTestBox, BaseTesseract, unittest.TestCase):
class TestCharBox(base.BaseTestBox, BaseTesseract):
"""
These tests make sure that Tesseract box handling works fine.
"""
......@@ -122,7 +120,7 @@ class TestCharBox(base.BaseTestBox, BaseTesseract, unittest.TestCase):
os.remove(tmp_path)
class TestDigit(base.BaseTestDigit, BaseTesseract, unittest.TestCase):
class TestDigit(base.BaseTestDigit, BaseTesseract):
"""
These tests make sure that Tesseract digits handling works fine.
"""
......@@ -130,7 +128,7 @@ class TestDigit(base.BaseTestDigit, BaseTesseract, unittest.TestCase):
self._test_txt('test-digits.png', 'test-digits.txt')
class TestWordBox(base.BaseTestWordBox, BaseTesseract, unittest.TestCase):
class TestWordBox(base.BaseTestWordBox, BaseTesseract):
"""
These tests make sure that Tesseract box handling works fine.
"""
......@@ -169,7 +167,7 @@ class TestWordBox(base.BaseTestWordBox, BaseTesseract, unittest.TestCase):
os.remove(tmp_path)
class TestLineBox(base.BaseTestLineBox, BaseTesseract, unittest.TestCase):
class TestLineBox(base.BaseTestLineBox, BaseTesseract):
"""
These tests make sure that Tesseract box handling works fine.
......@@ -208,17 +206,16 @@ class TestLineBox(base.BaseTestLineBox, BaseTesseract, unittest.TestCase):
finally:
os.remove(tmp_path)
def tearDown(self):
def teardown(self):
pass
class TestDigitLineBox(base.BaseTestDigitLineBox, BaseTesseract,
unittest.TestCase):
class TestDigitLineBox(base.BaseTestDigitLineBox, BaseTesseract):
def test_digits(self):
self._test_txt('test-digits.png', 'test-digits.lines')
class TestOrientation(BaseTesseract, unittest.TestCase):
class TestOrientation(BaseTesseract):
def set_builder(self):
self._builder = builders.TextBuilder()
......@@ -234,57 +231,3 @@ class TestOrientation(BaseTesseract, unittest.TestCase):
img = base.Image.open(self._path_to_img("test-90.png"))
result = tesseract.detect_orientation(img, lang='eng')
assert result['angle'] == 90
def get_all_tests():
all_tests = unittest.TestSuite()
test_names = [
'test_available',
'test_version',
'test_langs',
]
tests = unittest.TestSuite(map(TestContext, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
'test_european',
'test_french',
'test_japanese',
'test_multi',
]
tests = unittest.TestSuite(map(TestTxt, test_names))
all_tests.addTest(tests)
test_names = [
'test_basic',
'test_european',
'test_french',
'test_japanese',
'test_write_read',
]
tests = unittest.TestSuite(map(TestCharBox, test_names))
all_tests.addTest(tests)
tests = unittest.TestSuite(map(TestWordBox, test_names))
all_tests.addTest(tests)
tests = unittest.TestSuite(map(TestLineBox, test_names))
all_tests.addTest(tests)
test_names = [
'test_digits'
]
tests = unittest.TestSuite(map(TestDigit, test_names))
all_tests.addTest(tests)
tests = unittest.TestSuite(map(TestDigitLineBox, test_names))
all_tests.addTest(tests)
test_names = [
'test_can_detect_orientation',
'test_orientation_0',
'test_orientation_90',
]
tests = unittest.TestSuite(map(TestOrientation, test_names))
all_tests.addTest(tests)
return all_tests
Markdown is supported
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