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-34007: Fix printing of raw bytes in butler query-dimension-records. #659

Merged
merged 4 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/changes/DM-34007.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix garbled printing of raw-byte hashes in query-dimension-records.
2 changes: 2 additions & 0 deletions python/lsst/daf/butler/script/queryDimensionRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def queryDimensionRecords(repo, element, datasets, collections, where, no_check,
def conform(v):
if isinstance(v, Timespan):
v = (v.begin, v.end)
elif isinstance(v, bytes):
v = v.hex()
return v

return Table([[conform(getattr(record, key, None)) for record in records] for key in keys], names=keys)
15 changes: 15 additions & 0 deletions tests/test_cliCmdQueryDimensionRecords.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,21 @@ def testCollection(self):
expected = AstropyTable(rows, names=self.expectedColumnNames)
self.assertAstropyTablesEqual(readTable(result.output), expected)

def testSkymap(self):
butler = Butler(self.root, run="foo")
# try replacing the testRepo's butler with the one with the "foo" run.
self.testRepo.butler = butler

skymapRecord = {"name": "example_skymap", "hash": (50).to_bytes(8, byteorder="little")}
self.testRepo.butler.registry.insertDimensionData("skymap", skymapRecord)

result = self.runner.invoke(butlerCli, ["query-dimension-records", self.root, "skymap"])
self.assertEqual(result.exit_code, 0, clickResultMsg(result))

rows = array((("example_skymap", "3200000000000000", "None", "None", "None")))
expected = AstropyTable(rows, names=["name", "hash", "tract_max", "patch_nx_max", "patch_ny_max"])
self.assertAstropyTablesEqual(readTable(result.output), expected)


if __name__ == "__main__":
unittest.main()