Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle description of None when describing a TAP service's tables #197

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

- Add default for UWS version. [#199]

- Handle description of None when describing a TAP service's tables. [#197]

1.0 (2019-09-20)
================
Expand Down
10 changes: 10 additions & 0 deletions pyvo/io/vosi/tests/data/tables/no_table_description.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<?xml-stylesheet href='/static/xsl/vosi.xsl' type='text/xsl'?>
<vtm:tableset xmlns:vs="http://www.ivoa.net/xml/VODataService/v1.1" xmlns:vtm="http://www.ivoa.net/xml/VOSITables/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ivoa.net/xml/VODataService/v1.1 http://vo.ari.uni-heidelberg.de/docs/schemata/VODataService-v1.1.xsd http://www.ivoa.net/xml/VOSITables/v1.0 http://vo.ari.uni-heidelberg.de/docs/schemata/VOSITables-v1.0.xsd">
<schema>
<name>test</name>
<table>
<name>description</name>
</table>
</schema>
</vtm:tableset>
11 changes: 11 additions & 0 deletions pyvo/io/vosi/tests/data/tables/single_table_description.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<?xml-stylesheet href='/static/xsl/vosi.xsl' type='text/xsl'?>
<vtm:tableset xmlns:vs="http://www.ivoa.net/xml/VODataService/v1.1" xmlns:vtm="http://www.ivoa.net/xml/VOSITables/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ivoa.net/xml/VODataService/v1.1 http://vo.ari.uni-heidelberg.de/docs/schemata/VODataService-v1.1.xsd http://www.ivoa.net/xml/VOSITables/v1.0 http://vo.ari.uni-heidelberg.de/docs/schemata/VOSITables-v1.0.xsd">
<schema>
<name>test</name>
<table>
<name>description</name>
<description>A test table with a single description</description>
</table>
</schema>
</vtm:tableset>
31 changes: 31 additions & 0 deletions pyvo/io/vosi/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
Tests for pyvo.io.vosi
"""
import contextlib
import io
import pytest

import pyvo.io.vosi as vosi
Expand Down Expand Up @@ -368,3 +370,32 @@ def test_wrong_arraysize(self):
vosi.parse_tables(
get_pkg_data_filename(
"data/tables/wrong_arraysize.xml"))

def test_no_table_description(self):
"""Test handling of describing tables with no description
"""
tableset = vosi.parse_tables(
get_pkg_data_filename(
"data/tables/no_table_description.xml"))
nodesc_table = tableset.get_first_table()
assert nodesc_table.description is None

with io.StringIO() as buf, contextlib.redirect_stdout(buf):
nodesc_table.describe()
output = buf.getvalue()
assert 'No description' in output

def test_single_table_description(self):
"""Test describing a table with a single description
"""
tableset = vosi.parse_tables(
get_pkg_data_filename(
"data/tables/single_table_description.xml"))
onedesc_table = tableset.get_first_table()
describe_string = 'A test table with a single description'
assert describe_string in onedesc_table.description

with io.StringIO() as buf, contextlib.redirect_stdout(buf):
onedesc_table.describe()
output = buf.getvalue()
assert describe_string in output
5 changes: 4 additions & 1 deletion pyvo/io/vosi/vodataservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ def __repr__(self):

def describe(self):
print(self.name)
print(indent(self.description))
if self.description is not None:
print(indent(self.description))
else:
print('No description')

print()

Expand Down