Skip to content

Give sensible image when webcam responds with error#1462

Merged
DominicOram merged 10 commits intomainfrom
1002-Webcam_Corrupt_Image
Sep 16, 2025
Merged

Give sensible image when webcam responds with error#1462
DominicOram merged 10 commits intomainfrom
1002-Webcam_Corrupt_Image

Conversation

@adaudon
Copy link
Contributor

@adaudon adaudon commented Aug 19, 2025

Fixes DiamondLightSource/mx-bluesky#1002

Instructions to reviewer on how to test:

  1. Run tests on Dodal

Checks for reviewer

  • Would the PR title make sense to a scientist on a set of release notes
  • If a new device has been added does it follow the standards
  • If changing the API for a pre-existing device, ensure that any beamlines using this device have updated their Bluesky plans accordingly
  • Have the connection tests for the relevant beamline(s) been run via dodal connect ${BEAMLINE}

@adaudon adaudon requested a review from a team as a code owner August 19, 2025 10:37
@codecov
Copy link

codecov bot commented Aug 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.73%. Comparing base (1d370c2) to head (612bded).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1462   +/-   ##
=======================================
  Coverage   98.73%   98.73%           
=======================================
  Files         237      237           
  Lines        8683     8684    +1     
=======================================
+ Hits         8573     8574    +1     
  Misses        110      110           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Thanks! I really like the use of in-built library functions for this. A comment in code, additionally:

Must: I think this might be always creating a placeholder image. If I run the following:

async def test_webcam_system_test(RE):
    async with init_devices(mock=True):
        webcam = Webcam(
            url=URL("http://i03-webcam1/axis-cgi/jpg/image.cgi"),
        )

    import pathlib

    this_folder = pathlib.Path(__file__).parent.resolve()

    await webcam.filename.set("test")
    await webcam.directory.set(str(this_folder))
    await webcam.trigger()

on main I get a webcam image, if I run on this branch I get a placeholder. I think this might be because Image.open expects a file path and we have data but I'm not sure. Can you add that test into the repository but skipped with a comment similar to test_grid_overlay. Once you have the test it should hopefully be obvious from the exception on verify why it is failing.

@adaudon adaudon requested a review from DominicOram September 15, 2025 09:26
Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Thanks! Some minor nitpicks which I have quickly addressed myself


@pytest.mark.skip(reason="System test that hits a real webcam, not suitable for CI")
async def test_webcam_system_test(RE):
async with init_devices(mock=True):
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It's not really mock device if it's being set up against a real stream

mock_file.write.assert_called_once_with(test_placeholder_data)


@pytest.mark.skip(reason="System test that hits a real webcam, not suitable for CI")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think we can use @pytest.mark.system_test here so it will get run by our internal system tests but not in GH CI

Copy link
Contributor

Choose a reason for hiding this comment

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

No we can't, we're in dodal not mx-bluesky

url=URL("http://i03-webcam1/axis-cgi/jpg/image.cgi"),
)

import pathlib
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: By convention imports are all at the top of the file unless there is a specific reason for them not to be

@patch("dodal.devices.webcam.create_placeholder_image", autospec=True)
@patch("dodal.devices.webcam.ClientSession.get", autospec=True)
@patch("dodal.devices.webcam.Image.open")
async def test_given_response_read_passes_but_image_is_invalid(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit This is a bit of a confusing name

@DominicOram DominicOram changed the title 1002 webcam corrupt image Give sensible image when webcam responds with error Sep 16, 2025
@DominicOram DominicOram merged commit e5a6a1b into main Sep 16, 2025
11 checks passed
@DominicOram DominicOram deleted the 1002-Webcam_Corrupt_Image branch September 16, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Webcam error giving corrupt image

2 participants