Update test suite to cope with LabThings validating properties on write (https://github.com/labthings/labthings-fastapi/pull/278)
This commit is contained in:
parent
b298728fe5
commit
d673ceab7b
2 changed files with 8 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ import numpy as np
|
||||||
import pytest
|
import pytest
|
||||||
from hypothesis import given
|
from hypothesis import given
|
||||||
from hypothesis import strategies as st
|
from hypothesis import strategies as st
|
||||||
|
from pydantic import ValidationError
|
||||||
|
|
||||||
import labthings_fastapi as lt
|
import labthings_fastapi as lt
|
||||||
|
|
||||||
|
|
@ -210,7 +211,7 @@ def test_objective_getter_setter(camera):
|
||||||
camera.objective = 15
|
camera.objective = 15
|
||||||
with pytest.raises(ValueError, match=err_msg):
|
with pytest.raises(ValueError, match=err_msg):
|
||||||
camera.objective = 0
|
camera.objective = 0
|
||||||
with pytest.raises(ValueError, match=err_msg):
|
with pytest.raises(ValidationError):
|
||||||
camera.objective = "twenty"
|
camera.objective = "twenty"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from fastapi import HTTPException
|
from fastapi import HTTPException
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel, ValidationError
|
||||||
|
|
||||||
from labthings_fastapi.exceptions import InvocationCancelledError
|
from labthings_fastapi.exceptions import InvocationCancelledError
|
||||||
from labthings_fastapi.testing import create_thing_without_server
|
from labthings_fastapi.testing import create_thing_without_server
|
||||||
|
|
@ -206,8 +206,11 @@ def test_setting_workflows(caplog, mocker):
|
||||||
with caplog.at_level(logging.WARNING), smart_scan_thing:
|
with caplog.at_level(logging.WARNING), smart_scan_thing:
|
||||||
assert smart_scan_thing._workflow_name == "foo"
|
assert smart_scan_thing._workflow_name == "foo"
|
||||||
assert smart_scan_thing._workflow is workflows["foo"]
|
assert smart_scan_thing._workflow is workflows["foo"]
|
||||||
# Can't set None, warns doesn't change
|
# Can't set None, raises a ValidationError
|
||||||
smart_scan_thing.workflow_name = None
|
with pytest.raises(ValidationError):
|
||||||
|
smart_scan_thing.workflow_name = None
|
||||||
|
# Empty string still won't change, but just warns
|
||||||
|
smart_scan_thing.workflow_name = ""
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert smart_scan_thing._workflow_name == "foo"
|
assert smart_scan_thing._workflow_name == "foo"
|
||||||
assert smart_scan_thing._workflow is workflows["foo"]
|
assert smart_scan_thing._workflow is workflows["foo"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue