Skip to content

Commit

Permalink
Merge pull request #754 from lsst/tickets/DM-36984
Browse files Browse the repository at this point in the history
DM-36984: Fix astropy table test code
  • Loading branch information
timj committed Nov 14, 2022
2 parents 08d9810 + bea5bbf commit 0e87300
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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()
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

0 comments on commit 0e87300

Please sign in to comment.