File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed
Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1818from typing import Any
1919
2020
21- @dataclass
21+ @dataclass ( slots = True )
2222class LabThingsFeatureFlags :
2323 """Control over optional features of LabThings."""
2424
Original file line number Diff line number Diff line change 1+ """Test the feature flags mechanism.
2+
3+ Specific feature flags should be tested by the test code for the relevant feature. This
4+ test module checks that `set_temporarily` works as expected.
5+ """
6+
7+ import pytest
8+
9+ import labthings_fastapi as lt
10+
11+
12+ @pytest .mark .parametrize ("value" , [True , False ])
13+ def test_set_temporarily (value ):
14+ """Test values may be set and reset."""
15+ value_before = lt .FEATURE_FLAGS .validate_properties_on_set
16+
17+ with lt .FEATURE_FLAGS .set_temporarily (validate_properties_on_set = value ):
18+ assert lt .FEATURE_FLAGS .validate_properties_on_set == value
19+
20+ with lt .FEATURE_FLAGS .set_temporarily (validate_properties_on_set = not value ):
21+ assert lt .FEATURE_FLAGS .validate_properties_on_set != value
22+
23+ assert lt .FEATURE_FLAGS .validate_properties_on_set == value
24+
25+ assert lt .FEATURE_FLAGS .validate_properties_on_set == value_before
26+
27+
28+ def test_set_bad_setting ():
29+ """Test for errors when bad flags are used."""
30+ with pytest .raises (AttributeError ):
31+ with lt .FEATURE_FLAGS .set_temporarily (bogus_name = True ):
32+ pass
33+ with pytest .raises (AttributeError ):
34+ lt .FEATURE_FLAGS .bogus_name = True
You can’t perform that action at this time.
0 commit comments