diff --git a/CHANGES.rst b/CHANGES.rst index 54eb7cd44..a956cf8af 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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) ================ diff --git a/pyvo/io/vosi/tests/data/tables/no_table_description.xml b/pyvo/io/vosi/tests/data/tables/no_table_description.xml new file mode 100644 index 000000000..b8d49127d --- /dev/null +++ b/pyvo/io/vosi/tests/data/tables/no_table_description.xml @@ -0,0 +1,10 @@ + + + + + test + + description +
+
+
diff --git a/pyvo/io/vosi/tests/data/tables/single_table_description.xml b/pyvo/io/vosi/tests/data/tables/single_table_description.xml new file mode 100644 index 000000000..027ad6a5f --- /dev/null +++ b/pyvo/io/vosi/tests/data/tables/single_table_description.xml @@ -0,0 +1,11 @@ + + + + + test + + description + A test table with a single description +
+
+
diff --git a/pyvo/io/vosi/tests/test_tables.py b/pyvo/io/vosi/tests/test_tables.py index 811e2ede9..e9bb6edd9 100644 --- a/pyvo/io/vosi/tests/test_tables.py +++ b/pyvo/io/vosi/tests/test_tables.py @@ -3,6 +3,8 @@ """ Tests for pyvo.io.vosi """ +import contextlib +import io import pytest import pyvo.io.vosi as vosi @@ -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 diff --git a/pyvo/io/vosi/vodataservice.py b/pyvo/io/vosi/vodataservice.py index d9666c8b0..28b3bf50e 100644 --- a/pyvo/io/vosi/vodataservice.py +++ b/pyvo/io/vosi/vodataservice.py @@ -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()