Skip to content

Commit

Permalink
Merge pull request #6851 from pllim/fix-vo-difflib
Browse files Browse the repository at this point in the history
Address difflib TypeError in vo_test
  • Loading branch information
pllim committed Nov 14, 2017
2 parents 5d1b696 + 0c5233e commit f65e995
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions astropy/io/votable/tests/vo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_parse_single_table2():

@raises(IndexError)
def test_parse_single_table3():
table2 = parse_single_table(
parse_single_table(
get_pkg_data_filename('data/regression.xml'),
table_number=3, pedantic=False)

Expand Down Expand Up @@ -151,19 +151,16 @@ def _test_regression(tmpdir, _python_based=False, binary_mode=1):
get_pkg_data_filename(
'data/regression.bin.tabledata.truth.{0}.xml'.format(
votable.version)),
'rt', encoding='utf-8') as fd:
'rt', encoding='utf-8') as fd:
truth = fd.readlines()
with io.open(str(tmpdir.join("regression.bin.tabledata.xml")),
'rt', encoding='utf-8') as fd:
output = fd.readlines()

# If the lines happen to be different, print a diff
# This is convenient for debugging
for line in difflib.unified_diff(truth, output):
sys.stdout.write(
line.
encode('unicode_escape').
replace('\\n', '\n'))
sys.stdout.writelines(
difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

assert truth == output

Expand All @@ -173,7 +170,7 @@ def _test_regression(tmpdir, _python_based=False, binary_mode=1):
_astropy_version="testing",
_debug_python_based_parser=_python_based)
with gzip.GzipFile(
str(tmpdir.join("regression.bin.tabledata.xml.gz")), 'rb') as gzfd:
str(tmpdir.join("regression.bin.tabledata.xml.gz")), 'rb') as gzfd:
output = gzfd.readlines()
output = [x.decode('utf-8').rstrip() for x in output]
truth = [x.rstrip() for x in truth]
Expand Down Expand Up @@ -596,12 +593,12 @@ def test_get_info_by_id(self):

if self.votable.version != '1.1':
info = self.votable.get_info_by_id("ErrorInfo")
assert info.value == "One might expect to find some INFO here, too..."
assert info.value == "One might expect to find some INFO here, too..." # noqa

def test_repr(self):
assert '3 tables' in repr(self.votable)
assert repr(list(self.votable.iter_fields_and_params())[0]) == \
'<PARAM ID="awesome" arraysize="*" datatype="float" name="INPUT" unit="deg" value="[0.0 0.0]"/>'
'<PARAM ID="awesome" arraysize="*" datatype="float" name="INPUT" unit="deg" value="[0.0 0.0]"/>' # noqa
# Smoke test
repr(list(self.votable.iter_groups()))

Expand Down Expand Up @@ -736,7 +733,7 @@ def test_open_files():

@raises(VOTableSpecError)
def test_too_many_columns():
votable = parse(
parse(
get_pkg_data_filename('data/too_many_columns.xml.gz'),
pedantic=False)

Expand Down Expand Up @@ -776,8 +773,8 @@ def test_build_from_scratch(tmpdir):
assert_array_equal(
table.array.mask, np.array([(False, [[False, False], [False, False]]),
(False, [[False, False], [False, False]])],
dtype=[(str('filename'), str('?')),
(str('matrix'), str('?'), (2, 2))]))
dtype=[(str('filename'), str('?')),
(str('matrix'), str('?'), (2, 2))]))


def test_validate(test_path_object=False):
Expand Down Expand Up @@ -807,14 +804,14 @@ def test_validate(test_path_object=False):

with io.open(
get_pkg_data_filename('data/validation.txt'),
'rt', encoding='utf-8') as fd:
'rt', encoding='utf-8') as fd:
truth = fd.readlines()

truth = truth[1:]
output = output[1:-1]

for line in difflib.unified_diff(truth, output):
sys.stdout.write(line.replace('\\n', '\n'))
sys.stdout.writelines(
difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

assert truth == output

Expand Down Expand Up @@ -981,14 +978,14 @@ def test_no_resource_check():

with io.open(
get_pkg_data_filename('data/no_resource.txt'),
'rt', encoding='utf-8') as fd:
'rt', encoding='utf-8') as fd:
truth = fd.readlines()

truth = truth[1:]
output = output[1:-1]

for line in difflib.unified_diff(truth, output):
sys.stdout.write(line.replace('\\n', '\n'))
sys.stdout.writelines(
difflib.unified_diff(truth, output, fromfile='truth', tofile='output'))

assert truth == output

Expand Down

0 comments on commit f65e995

Please sign in to comment.