Skip to content

Commit

Permalink
Remove unnecessary code duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoBektesevic committed May 17, 2021
1 parent 401be08 commit d2ad6d9
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions python/astro_metadata_translator/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,25 +151,19 @@ def assertObservationInfoFromYaml(self, file, dir=None, check_wcs=True, # noqa:
"""
header = read_test_file(file, dir=dir)

try:
self.assertObservationInfo(header, filename=file, check_wcs=check_wcs,
wcs_params=wcs_params, **kwargs)
except AssertionError as e:
raise AssertionError("ObservationInfo derived from an dict-like "
"type is inconsistent.") from e

astropy_header = Header()
for key, val in header.items():
values = val if isinstance(val, list) else [val]
for v in values:
astropy_header[key] = v

try:
self.assertObservationInfo(astropy_header, filename=file, check_wcs=check_wcs,
wcs_params=wcs_params, **kwargs)
except AssertionError as e:
raise AssertionError("ObservationInfo derived from an Astropy "
"Header is inconsistent.") from e
astropy_header.append((key, v))

for hdr in (header, astropy_header):
try:
self.assertObservationInfo(header, filename=file, check_wcs=check_wcs,
wcs_params=wcs_params, **kwargs)
except AssertionError as e:
raise AssertionError("ObservationInfo derived from {type(hdr)} "
"type is inconsistent.") from e

def assertObservationInfo(self, header, filename=None, check_wcs=True, # noqa: N802
wcs_params=None, **kwargs):
Expand Down

0 comments on commit d2ad6d9

Please sign in to comment.