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

DM-36984: Fix astropy table test code #754

Merged
merged 2 commits into from
Nov 14, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions python/lsst/daf/butler/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

__all__ = ()

import io
import os
import shutil
import tempfile
Expand All @@ -32,7 +31,6 @@

import astropy
from astropy.table import Table as AstropyTable
from astropy.utils.diff import report_diff_values

from .. import Butler, Config, StorageClassFactory
from ..registry import CollectionType
Expand Down Expand Up @@ -128,7 +126,6 @@ def assertAstropyTablesEqual(self, tables, expectedTables, filterColumns=False,
tables = [tables]
if isinstance(expectedTables, AstropyTable):
expectedTables = [expectedTables]
diff = io.StringIO()
self.assertEqual(len(tables), len(expectedTables))
for table, expected in zip(tables, expectedTables):
# Assert that we are testing what we think we are testing:
Expand All @@ -142,8 +139,17 @@ def assertAstropyTablesEqual(self, tables, expectedTables, filterColumns=False,
table.sort(table.colnames)
expected = expected.copy()
expected.sort(expected.colnames)
# Assert that they match:
self.assertTrue(report_diff_values(table, expected, fileobj=diff), msg="\n" + diff.getvalue())
# Assert that they match.
# Recommendation from Astropy Slack is to format the table into
# lines for comparison. We do not compare column data types.
table1 = table.pformat_all()
expected1 = expected.pformat_all()
timj marked this conversation as resolved.
Show resolved Hide resolved
original_max = self.maxDiff
self.maxDiff = None # This is required to get the full diff.
try:
self.assertEqual(table1, expected1)
finally:
self.maxDiff = original_max


def readTable(textTable):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cliCmdQueryDimensionRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class QueryDimensionRecordsTest(unittest.TestCase, ButlerTestHelper):
"physical_filter",
"name",
"day_obs",
"seq_num",
"exposure_time",
"target_name",
"observation_reason",
"science_program",
"azimuth",
"zenith_angle",
"region",
f"timespan{timespan_columns}",
Expand Down Expand Up @@ -96,6 +98,8 @@ def testBasic(self):
"None",
"None",
"None",
"None",
"None",
"None .. None",
),
(
Expand All @@ -110,6 +114,8 @@ def testBasic(self):
"None",
"None",
"None",
"None",
"None",
"None .. None",
),
)
Expand Down Expand Up @@ -143,6 +149,8 @@ def testWhere(self):
"None",
"None",
"None",
"None",
"None",
"None .. None",
),
)
Expand Down Expand Up @@ -196,6 +204,8 @@ def testCollection(self):
"None",
"None",
"None",
"None",
"None",
"None .. None",
),
(
Expand All @@ -210,6 +220,8 @@ def testCollection(self):
"None",
"None",
"None",
"None",
"None",
"None .. None",
),
)
Expand Down Expand Up @@ -245,6 +257,8 @@ def testCollection(self):
"None",
"None",
"None",
"None",
"None",
"None .. None",
),
)
Expand Down