TST: Use tmpdir fixture.

parent 5e78644a
import os
import codecs
import tempfile
import pytest
......@@ -95,28 +93,23 @@ class TestWordBox(base.BaseTestWordBox, BaseCuneiform):
def test_french(self):
self._test_txt('test-french.jpg', 'test-french.words', 'fra')
def test_write_read(self):
def test_write_read(self, tmpdir):
original_boxes = self._read_from_img(
os.path.join("tests", "input", "specific", "test.png")
)
assert len(original_boxes) > 0
(file_descriptor, tmp_path) = tempfile.mkstemp()
try:
# we must open the file with codecs.open() for utf-8 support
os.close(file_descriptor)
tmp_path = tmpdir.join('test_write_read.txt')
with codecs.open(tmp_path, 'w', encoding='utf-8') as file_desc:
self._builder.write_file(file_desc, original_boxes)
with tmp_path.open('w', encoding='utf-8') as file_desc:
self._builder.write_file(file_desc, original_boxes)
with codecs.open(tmp_path, 'r', encoding='utf-8') as file_desc:
new_boxes = self._builder.read_file(file_desc)
with tmp_path.open('r', encoding='utf-8') as file_desc:
new_boxes = self._builder.read_file(file_desc)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
finally:
os.remove(tmp_path)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
class TestOrientation(object):
......
import codecs
import os
import tempfile
import pytest
......@@ -140,27 +138,22 @@ class TestWordBox(base.BaseTestWordBox, BaseLibtesseract):
def test_japanese(self):
self._test_txt('test-japanese.jpg', 'test-japanese.words', 'jpn')
def test_write_read(self):
def test_write_read(self, tmpdir):
image_path = self._path_to_img("test.png")
original_boxes = self._read_from_img(image_path)
assert len(original_boxes) > 0
(file_descriptor, tmp_path) = tempfile.mkstemp()
try:
# we must open the file with codecs.open() for utf-8 support
os.close(file_descriptor)
tmp_path = tmpdir.join('test_write_read.txt')
with codecs.open(tmp_path, 'w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with tmp_path.open('w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with codecs.open(tmp_path, 'r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
with tmp_path.open('r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
finally:
os.remove(tmp_path)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
class TestLineBox(base.BaseTestLineBox, BaseLibtesseract):
......@@ -179,27 +172,22 @@ class TestLineBox(base.BaseTestLineBox, BaseLibtesseract):
def test_japanese(self):
self._test_txt('test-japanese.jpg', 'test-japanese.lines', 'jpn')
def test_write_read(self):
def test_write_read(self, tmpdir):
image_path = self._path_to_img("test.png")
original_boxes = self._read_from_img(image_path)
assert len(original_boxes) > 0
(file_descriptor, tmp_path) = tempfile.mkstemp()
try:
# we must open the file with codecs.open() for utf-8 support
os.close(file_descriptor)
tmp_path = tmpdir.join('test_write_read.txt')
with codecs.open(tmp_path, 'w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with tmp_path.open('w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with codecs.open(tmp_path, 'r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
with tmp_path.open('r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
finally:
os.remove(tmp_path)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
class TestDigitLineBox(base.BaseTestDigitLineBox, BaseLibtesseract):
......
import os
import codecs
import tempfile
from pyocr import builders
from pyocr import tesseract
......@@ -97,27 +95,22 @@ class TestCharBox(base.BaseTestBox, BaseTesseract):
def test_japanese(self):
self._test_txt('test-japanese.jpg', 'test-japanese.box', 'jpn')
def test_write_read(self):
def test_write_read(self, tmpdir):
image_path = self._path_to_img("test.png")
original_boxes = self._read_from_img(image_path)
assert len(original_boxes) > 0
(file_descriptor, tmp_path) = tempfile.mkstemp()
try:
# we must open the file with codecs.open() for utf-8 support
os.close(file_descriptor)
tmp_path = tmpdir.join('test_write_read.txt')
with codecs.open(tmp_path, 'w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with tmp_path.open('w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with codecs.open(tmp_path, 'r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
with tmp_path.open('r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
finally:
os.remove(tmp_path)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
class TestDigit(base.BaseTestDigit, BaseTesseract):
......@@ -144,27 +137,22 @@ class TestWordBox(base.BaseTestWordBox, BaseTesseract):
def test_japanese(self):
self._test_txt('test-japanese.jpg', 'test-japanese.words', 'jpn')
def test_write_read(self):
def test_write_read(self, tmpdir):
image_path = self._path_to_img("test.png")
original_boxes = self._read_from_img(image_path)
assert len(original_boxes) > 0
(file_descriptor, tmp_path) = tempfile.mkstemp()
try:
# we must open the file with codecs.open() for utf-8 support
os.close(file_descriptor)
tmp_path = tmpdir.join('test_write_read.txt')
with codecs.open(tmp_path, 'w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with tmp_path.open('w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with codecs.open(tmp_path, 'r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
with tmp_path.open('r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
finally:
os.remove(tmp_path)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
class TestLineBox(base.BaseTestLineBox, BaseTesseract):
......@@ -184,27 +172,22 @@ class TestLineBox(base.BaseTestLineBox, BaseTesseract):
def test_japanese(self):
self._test_txt('test-japanese.jpg', 'test-japanese.lines', 'jpn')
def test_write_read(self):
def test_write_read(self, tmpdir):
image_path = self._path_to_img("test.png")
original_boxes = self._read_from_img(image_path)
assert len(original_boxes) > 0
(file_descriptor, tmp_path) = tempfile.mkstemp()
try:
# we must open the file with codecs.open() for utf-8 support
os.close(file_descriptor)
tmp_path = tmpdir.join('test_write_read.txt')
with codecs.open(tmp_path, 'w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with tmp_path.open('w', encoding='utf-8') as fdescriptor:
self._builder.write_file(fdescriptor, original_boxes)
with codecs.open(tmp_path, 'r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
with tmp_path.open('r', encoding='utf-8') as fdescriptor:
new_boxes = self._builder.read_file(fdescriptor)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
finally:
os.remove(tmp_path)
assert len(new_boxes) == len(original_boxes)
for i in range(0, len(original_boxes)):
assert new_boxes[i] == original_boxes[i]
def teardown(self):
pass
......
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