Skip to content

Commit

Permalink
RCAL-567 Update unit tests to add tmpdir for test files (spacetelesco…
Browse files Browse the repository at this point in the history
…pe#702)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and mairanteodoro committed May 30, 2023
1 parent 8290f85 commit 7e48be6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

tweakreg
--------

- Added tmpdir to the unit tests for test files [#702]

- Added logic to handle cases where an absolute catalog cannot be created. [#698]

associations
Expand Down
26 changes: 11 additions & 15 deletions romancal/associations/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,26 +378,22 @@ def parse_args(self, args=None, has_pool=False):

self.parsed = parser.parse_args(args=args)

def save(self, path=".", format="json", save_orphans=False):
"""Save the associations to disk.
def save(self):
"""Save the associations to disk."""
if self.parsed.dry_run:
return

Parameters
----------
path : str
The path to save the associations to.
format : str
The format of the associations
save_orphans : bool
If true, save the orphans to an astropy.table.Table
"""
for asn in self.associations:
(fname, serialized) = asn.dump(format=format)
try:
(fname, serialized) = asn.dump(format=self.parsed.format)
except AssociationError as exception: # noqa: F821
logger.warning("Cannot serialize association %s", asn)
logger.warning("Reason:", exc_info=exception)
continue
with open(os.path.join(self.parsed.path, fname), "w") as f:
f.write(serialized)

if save_orphans:
if self.parsed.save_orphans:
self.orphaned.write(
os.path.join(self.parsed.path, self.parsed.save_orphans),
format="ascii",
Expand Down
10 changes: 8 additions & 2 deletions romancal/tweakreg/tests/test_astrometric_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,16 @@ def _base_image(shift_1=0, shift_2=0):
("GAIADR3", 15),
],
)
def test_create_astrometric_catalog_variable_num_sources(catalog, num_sources, request):
def test_create_astrometric_catalog_variable_num_sources(
tmp_path, catalog, num_sources, request
):
"""Test fetching data from supported catalogs with variable number of sources."""
output_filename = "ref_cat.ecsv"
img = request.getfixturevalue("base_image")(shift_1=1000, shift_2=1000)
res = create_astrometric_catalog(
[img],
catalog=catalog,
output=os.path.join(tmp_path, output_filename),
num_sources=num_sources,
)

Expand Down Expand Up @@ -334,8 +338,9 @@ def test_create_astrometric_catalog_write_results_to_disk(tmp_path, base_image):
("GAIADR3", None),
],
)
def test_create_astrometric_catalog_using_epoch(catalog, epoch, request):
def test_create_astrometric_catalog_using_epoch(tmp_path, catalog, epoch, request):
"""Test fetching data from supported catalogs for a specific epoch."""
output_filename = "ref_cat.ecsv"
img = request.getfixturevalue("base_image")(shift_1=1000, shift_2=1000)

metadata_epoch = (
Expand All @@ -348,6 +353,7 @@ def test_create_astrometric_catalog_using_epoch(catalog, epoch, request):
res = create_astrometric_catalog(
[img],
catalog=catalog,
output=os.path.join(tmp_path, output_filename),
epoch=epoch,
)

Expand Down

0 comments on commit 7e48be6

Please sign in to comment.