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

Bugfix for source_detection's test_outputs #665

Conversation

WilliamJamieson
Copy link
Collaborator

When I ran the unit tests locally, this test:

@pytest.mark.skipif(
os.environ.get("CI") == "true",
reason="Roman CRDS servers are not currently available outside the internal "
"network",
)
def test_outputs(tmp_path, setup_inputs):
"""Make sure `save_catalogs` and `output_cat_filetype` work correctly."""
model = setup_inputs()
# add a single source to image so a non-empty catalog is produced
add_random_gauss(model.data, [50], [50])
# run step and direct it to save catalog. default format should be asdf
sd = SourceDetectionStep()
sd.save_catalogs = True
sd.process(model)
# make sure file exists
expected_output_path = os.path.join(tmp_path, "filename_tweakreg_catalog.asdf")
assert os.path.isfile(expected_output_path)
# run again, specifying that catalog should be saved in ecsv format
sd = SourceDetectionStep()
sd.save_catalogs = True
sd.output_cat_filetype = "ecsv"
expected_output_path = os.path.join(tmp_path, "filename_tweakreg_catalog.ecsv")
assert os.path.isfile(expected_output_path)

started failing the checks for the created file.

This was caused by the step not being run in the temporary directory created for the test. This left the file behind after the test finished and the test for the output file was with respect to this directory. This PR fixes this bug by using a context manager to temporarily change python's working directory to the test's temporary directory for the duration of the test.

The reason this was not caught by the CI in #608 is because this test is not run by the GitHub CI at this time due to the lack of a public CRDS server.

Checklist

  • added entry in CHANGES.rst under the corresponding subsection
  • updated relevant tests
  • updated relevant documentation
  • updated relevant milestone(s)
  • added relevant label(s)

@codecov
Copy link

codecov bot commented Mar 27, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (dec39b6) 60.61% compared to head (3524d5b) 60.61%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #665   +/-   ##
=======================================
  Coverage   60.61%   60.61%           
=======================================
  Files          78       78           
  Lines        4113     4113           
=======================================
  Hits         2493     2493           
  Misses       1620     1620           
Flag Coverage Δ *Carryforward flag
nightly 60.55% <ø> (ø) Carriedforward from dec39b6

*This pull request uses carry forward flags. Click here to find out more.

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@cshanahan1
Copy link
Collaborator

looks good, thanks for the fix. i added the tmpdir just before i merged and forgot to re-run tests locally.

@cshanahan1
Copy link
Collaborator

just a thought - i could add an output directory arg, currently the catalog can only be output in the pwd. i originally didn't do this because i thought it would be confusing to have this in addition to the pipeline/step output_dir argument, but i think it makes sense to have this option

@zacharyburnett
Copy link
Collaborator

I can confirm the same issue on my local machine:

E       AssertionError: assert False
E        +  where False = <function isfile at 0x100b23d80>('/private/var/folders/bv/nnh6jr1553jcv2pxbt8hyw6c00053_/T/pytest-of-zburnett/pytest-4/popen-gw2/test_outputs0/filename_tweakreg_catalog.asdf')
E        +    where <function isfile at 0x100b23d80> = <module 'posixpath' (frozen)>.isfile
E        +      where <module 'posixpath' (frozen)> = os.path

romancal/source_detection/tests/test_source_detection_step.py:178: AssertionError

This PR fixes this on Python 3.11 and Python 3.9

Copy link
Collaborator

@ddavis-stsci ddavis-stsci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@PaulHuwe PaulHuwe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@WilliamJamieson WilliamJamieson merged commit 2be4de7 into spacetelescope:main Mar 28, 2023
@WilliamJamieson WilliamJamieson deleted the bugfix/source_detection_outputs branch March 28, 2023 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants