-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #599 from msdemlei/fix-bug-543
Fix bug #543
- Loading branch information
Showing
5 changed files
with
277 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
""" | ||
Miscellenaneous utilities for writing tests. | ||
""" | ||
|
||
from astropy.io.votable import tree | ||
from pyvo.dal import query as dalquery | ||
|
||
|
||
try: | ||
TABLE_ELEMENT = tree.TableElement | ||
except AttributeError: | ||
TABLE_ELEMENT = tree.Table | ||
|
||
|
||
def create_votable(field_descs, records): | ||
"""returns a VOTableFile with a a single table containing records, | ||
described by field_descs. | ||
""" | ||
votable = tree.VOTableFile() | ||
resource = tree.Resource(type="results") | ||
votable.resources.append(resource) | ||
table = TABLE_ELEMENT(votable) | ||
resource.tables.append(table) | ||
table.fields.extend( | ||
tree.Field(votable, **desc) for desc in field_descs) | ||
table.create_arrays(len(records)) | ||
|
||
for index, rec in enumerate(records): | ||
table.array[index] = rec | ||
|
||
return votable | ||
|
||
|
||
def create_dalresults( | ||
field_descs, | ||
records, | ||
*, | ||
resultsClass=dalquery.DALResults): | ||
"""returns a DALResults instance for a query returning records | ||
described by field_descs. | ||
The arguments are as for create_votable. | ||
""" | ||
return resultsClass( | ||
create_votable(field_descs, records), | ||
url="http://testing.pyvo/test-url") |