Skip to content

Commit 9e0cb61

Browse files
committed
(utils/tap/xmlparser) Prefer pytest-style tests -- Refs astropy#861
1 parent 24117c9 commit 9e0cb61

1 file changed

Lines changed: 62 additions & 72 deletions

File tree

‎astroquery/utils/tap/xmlparser/tests/test_xmlparser.py‎

Lines changed: 62 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
1616
"""
1717

18-
import unittest
1918
import os
2019
from astroquery.utils.tap.xmlparser.tableSaxParser import TableSaxParser
2120
from astroquery.utils.tap.xmlparser.jobListSaxParser import JobListSaxParser
@@ -28,74 +27,65 @@ def data_path(filename):
2827
return os.path.join(data_dir, filename)
2928

3029

31-
class XmlParserTest(unittest.TestCase):
32-
33-
def test_jobs_list_parser(self):
34-
fileName = data_path('test_jobs_list.xml')
35-
file = open(fileName, 'r')
36-
parser = JobListSaxParser()
37-
jobs = parser.parseData(file)
38-
assert len(jobs) == 2, \
39-
"Expected table list size: 1, found %d" % len(jobs)
40-
self.__check_job(jobs[0], "1479386030738O", "COMPLETED", None)
41-
self.__check_job(jobs[1], "14793860307381", "ERROR", None)
42-
file.close()
43-
44-
def test_jobs_parser(self):
45-
fileName = data_path('test_jobs_async.xml')
46-
file = open(fileName, 'r')
47-
parser = JobSaxParser()
48-
jobs = parser.parseData(file)
49-
assert len(jobs) == 2, \
50-
"Expected table list size: 1, found %d" % len(jobs)
51-
self.__check_job(jobs[0], "1479386030738O", "COMPLETED", "anonymous")
52-
self.__check_job(jobs[1], "14793860307381", "ERROR", "anonymous")
53-
file.close()
54-
55-
def test_table_list_parser(self):
56-
fileName = data_path('test_tables.xml')
57-
file = open(fileName, 'r')
58-
parser = TableSaxParser()
59-
tables = parser.parseData(file)
60-
assert len(tables) == 2, \
61-
"Expected table list size: 2, found %d" % len(tables)
62-
self.__check_table(tables[0],
63-
"table1",
64-
2,
65-
['table1_col1', 'table1_col2'])
66-
self.__check_table(tables[1],
67-
"table2",
68-
3,
69-
['table2_col1', 'table2_col2', 'table2_col3'])
70-
file.close()
71-
72-
def test_job_results_parser(self):
73-
fileName = data_path('test_job_results.xml')
74-
file = open(fileName, 'rb')
75-
resultTable = utils.read_http_response(file, 'votable')
76-
assert len(resultTable.columns) == 57, \
77-
"Expected 57 columsn, found %d" % len(resultTable.columns)
78-
file.close()
79-
80-
def __check_table(self, table, baseName, numColumns, columnsData):
81-
qualifiedName = "public.%s" % baseName
82-
assert str(table.get_qualified_name()) == str(qualifiedName), \
83-
"Expected qualified table name: '%s', found '%s'" % \
84-
(qualifiedName, table.get_qualified_name())
85-
c = table.columns
86-
assert len(c) == numColumns, \
87-
"Expected table1 num columns: %d, found %d" % (numColumns, len(c))
88-
for i in range(0, numColumns):
89-
assert str(c[i].name) == str(columnsData[i]), \
90-
"Expected column name '%s', found: '%s'" % \
91-
(columnsData[i], c[i].name)
92-
93-
def __check_job(self, job, jobid, jobPhase, jobOwner):
94-
assert str(job.jobid) == str(jobid), \
95-
"Expected job id: '%s', found '%s'" % (jobid, job.jobid)
96-
p = job.get_phase()
97-
assert str(p) == str(jobPhase), \
98-
"Expected job phase: %s, found %s" % (jobPhase, p)
99-
o = job.ownerid
100-
assert str(o) == str(jobOwner), \
101-
"Expected job owner: %s, found %s" % (jobOwner, o)
30+
def test_jobs_list_parser():
31+
fileName = data_path('test_jobs_list.xml')
32+
file = open(fileName, 'r')
33+
parser = JobListSaxParser()
34+
jobs = parser.parseData(file)
35+
assert len(jobs) == 2
36+
__check_job(jobs[0], "1479386030738O", "COMPLETED", None)
37+
__check_job(jobs[1], "14793860307381", "ERROR", None)
38+
file.close()
39+
40+
41+
def test_jobs_parser():
42+
fileName = data_path('test_jobs_async.xml')
43+
file = open(fileName, 'r')
44+
parser = JobSaxParser()
45+
jobs = parser.parseData(file)
46+
assert len(jobs) == 2
47+
__check_job(jobs[0], "1479386030738O", "COMPLETED", "anonymous")
48+
__check_job(jobs[1], "14793860307381", "ERROR", "anonymous")
49+
file.close()
50+
51+
52+
def test_table_list_parser():
53+
fileName = data_path('test_tables.xml')
54+
file = open(fileName, 'r')
55+
parser = TableSaxParser()
56+
tables = parser.parseData(file)
57+
assert len(tables) == 2
58+
__check_table(tables[0],
59+
"table1",
60+
2,
61+
['table1_col1', 'table1_col2'])
62+
__check_table(tables[1],
63+
"table2",
64+
3,
65+
['table2_col1', 'table2_col2', 'table2_col3'])
66+
file.close()
67+
68+
69+
def test_job_results_parser():
70+
fileName = data_path('test_job_results.xml')
71+
file = open(fileName, 'rb')
72+
resultTable = utils.read_http_response(file, 'votable')
73+
assert len(resultTable.columns) == 57
74+
file.close()
75+
76+
77+
def __check_table(table, baseName, numColumns, columnsData):
78+
qualifiedName = "public.%s" % baseName
79+
assert str(table.get_qualified_name()) == str(qualifiedName)
80+
c = table.columns
81+
assert len(c) == numColumns
82+
for i in range(0, numColumns):
83+
assert str(c[i].name) == str(columnsData[i])
84+
85+
86+
def __check_job(job, jobid, jobPhase, jobOwner):
87+
assert str(job.jobid) == str(jobid)
88+
p = job.get_phase()
89+
assert str(p) == str(jobPhase)
90+
o = job.ownerid
91+
assert str(o) == str(jobOwner)

0 commit comments

Comments
 (0)