Commit 148423fd authored by Andrey Golovizin's avatar Andrey Golovizin

Move tests outside the pybtex package

parent f4d2b8d9
......@@ -5,7 +5,7 @@ formats = gztar bztar zip
with-doctest = True
[tool:pytest]
testpaths = pybtex
testpaths = pybtex tests
addopts = --doctest-modules
[isort]
......
......@@ -21,8 +21,13 @@ from __future__ import unicode_literals
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
import pkgutil
from difflib import unified_diff
def diff(src, dst):
return '\n'.join(unified_diff(src.splitlines(), dst.splitlines()))
def read_file(filename, package='tests.data'):
return pkgutil.get_data(package, filename).decode('UTF-8')
from __future__ import unicode_literals
import pkgutil
from six.moves import zip_longest
from pybtex.bibtex import bst
from .. import read_file
test_data = (
'plain',
......@@ -14,9 +13,9 @@ test_data = (
def check_bst_parser(dataset_name):
module = __import__('pybtex.tests.bst_parser_test.{0}'.format(dataset_name), globals(), locals(), 'bst')
module = __import__('tests.bst_parser_test.{0}'.format(dataset_name), globals(), locals(), 'bst')
correct_result = module.bst
bst_data = pkgutil.get_data('pybtex.tests.data', dataset_name + '.bst').decode('latin1')
bst_data = read_file(dataset_name + '.bst')
actual_result = bst.parse_string(bst_data)
for correct_element, actual_element in zip_longest(actual_result, correct_result):
......
from __future__ import unicode_literals
import os
import pkgutil
import posixpath
from contextlib import contextmanager
from shutil import rmtree
from tempfile import mkdtemp
from pybtex import errors, io
from pybtex.tests import diff
from . import diff, read_file
@contextmanager
......@@ -23,10 +22,6 @@ def cd_tempdir():
rmtree(tempdir)
def read_file(filename, package='pybtex.tests.data'):
return pkgutil.get_data(package, filename).decode(io.get_default_encoding())
def copy_file(filename):
data = read_file(filename)
with io.open_unicode(filename, 'w') as data_file:
......@@ -74,7 +69,7 @@ def check_format_from_string(engine, filenames):
with errors.capture(): # FIXME check error messages
result = engine.format_from_string(bib_string, style=style, citations=citations)
correct_result_name = '{0}_{1}.{2}.bbl'.format(bib_name, style, engine_name)
correct_result = pkgutil.get_data('pybtex.tests.data', correct_result_name).decode(io.get_default_encoding())
correct_result = read_file(correct_result_name)
assert result == correct_result, diff(correct_result, result)
......@@ -102,7 +97,7 @@ def check_make_bibliography(engine, filenames):
with io.open_unicode(result_name) as result_file:
result = result_file.read()
correct_result_name = '{0}_{1}.{2}.bbl'.format(bib_name, bst_name, engine_name)
correct_result = pkgutil.get_data('pybtex.tests.data', correct_result_name).decode(io.get_default_encoding())
correct_result = read_file(correct_result_name)
assert result == correct_result, diff(correct_result, result)
......
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