@@ -751,6 +751,18 @@ def test_device_type_conformance(self):
751
751
asserts .assert_equal (str (xml_callable ), 'CD, testy' , msg )
752
752
asserts .assert_equal (xml_callable (0 , [], []), ConformanceDecision .OPTIONAL )
753
753
754
+ def check_good_choice (self , xml : str , conformance_str : str ) -> Conformance :
755
+ et = ElementTree .fromstring (xml )
756
+ xml_callable = parse_callable_from_xml (et , self .params )
757
+ asserts .assert_equal (str (xml_callable ), conformance_str , 'Bad choice conformance string' )
758
+ return xml_callable
759
+
760
+ def check_decision (self , more_expected : bool , conformance : Conformance , feature_map : uint , attr_list : list [uint ], cmd_list : list [uint ]):
761
+ decision = conformance (feature_map , attr_list , cmd_list )
762
+ asserts .assert_true (decision .choice , 'Expected choice conformance on decision, but did not get one' )
763
+ asserts .assert_equal (decision .choice .marker , 'a' , 'Unexpected conformance string returned' )
764
+ asserts .assert_equal (decision .choice .more , more_expected , "Unexpected more on choice" )
765
+
754
766
def test_choice_conformance (self ):
755
767
# Choice conformances can appear on:
756
768
# - base optional O.a
@@ -776,67 +788,55 @@ def test_choice_conformance(self):
776
788
777
789
choices = [('a+' , 'choice="a" more="true"' , True ), ('a' , 'choice="a"' , False )]
778
790
for suffix , xml_attrs , more in choices :
779
- def check_good_choice (xml : str , conformance_str : str ) -> Conformance :
780
- msg = 'Bad choice conformance string'
781
- et = ElementTree .fromstring (xml )
782
- xml_callable = parse_callable_from_xml (et , self .params )
783
- asserts .assert_equal (str (xml_callable ), conformance_str , msg )
784
- return xml_callable
785
-
786
- def check_decision (conformance : Conformance , feature_map : uint , attr_list : list [uint ], cmd_list : list [uint ]):
787
- decision = conformance (feature_map , attr_list , cmd_list )
788
- asserts .assert_true (decision .get_choice (), 'Expected choice conformance on decision, but did not get one' )
789
- asserts .assert_equal (decision .get_choice ().choice , 'a' , 'Unexpected conformance string returned' )
790
- asserts .assert_equal (decision .get_choice ().more , more , "Unexpected more on choice" )
791
791
792
792
AB = self .feature_names_to_bits ['AB' ]
793
793
attr1 = [self .attribute_names_to_values ['attr1' ]]
794
794
cmd1 = [self .command_names_to_values ['cmd1' ]]
795
795
796
796
msg_not_applicable = "Expected NOT_APPLICABLE conformance"
797
797
xml = f'<optionalConform { xml_attrs } />'
798
- conformance = check_good_choice (xml , f'O.{ suffix } ' )
799
- check_decision (conformance , 0 , [], [])
798
+ conformance = self . check_good_choice (xml , f'O.{ suffix } ' )
799
+ self . check_decision (more , conformance , 0 , [], [])
800
800
801
801
xml = (f'<optionalConform { xml_attrs } >'
802
802
'<feature name="AB" />'
803
803
'</optionalConform>' )
804
- conformance = check_good_choice (xml , f'[AB].{ suffix } ' )
804
+ conformance = self . check_good_choice (xml , f'[AB].{ suffix } ' )
805
805
asserts .assert_equal (conformance (0 , [], []), ConformanceDecision .NOT_APPLICABLE , msg_not_applicable )
806
- check_decision (conformance , AB , [], [])
806
+ self . check_decision (more , conformance , AB , [], [])
807
807
808
808
xml = (f'<optionalConform { xml_attrs } >'
809
809
'<attribute name="attr1" />'
810
810
'</optionalConform>' )
811
- conformance = check_good_choice (xml , f'[attr1].{ suffix } ' )
811
+ conformance = self . check_good_choice (xml , f'[attr1].{ suffix } ' )
812
812
asserts .assert_equal (conformance (0 , [], []), ConformanceDecision .NOT_APPLICABLE , msg_not_applicable )
813
- check_decision (conformance , 0 , attr1 , [])
813
+ self . check_decision (more , conformance , 0 , attr1 , [])
814
814
815
815
xml = (f'<optionalConform { xml_attrs } >'
816
816
'<command name="cmd1" />'
817
817
'</optionalConform>' )
818
- conformance = check_good_choice (xml , f'[cmd1].{ suffix } ' )
818
+ conformance = self . check_good_choice (xml , f'[cmd1].{ suffix } ' )
819
819
asserts .assert_equal (conformance (0 , [], []), ConformanceDecision .NOT_APPLICABLE , msg_not_applicable )
820
- check_decision (conformance , 0 , [], cmd1 )
820
+ self . check_decision (more , conformance , 0 , [], cmd1 )
821
821
822
822
xml = (f'<optionalConform { xml_attrs } >'
823
823
'<orTerm>'
824
824
'<feature name="AB" />'
825
825
'<feature name="CD" />'
826
826
'</orTerm>'
827
827
'</optionalConform>' )
828
- conformance = check_good_choice (xml , f'[AB | CD].{ suffix } ' )
828
+ conformance = self . check_good_choice (xml , f'[AB | CD].{ suffix } ' )
829
829
asserts .assert_equal (conformance (0 , [], []), ConformanceDecision .NOT_APPLICABLE , msg_not_applicable )
830
- check_decision (conformance , AB , [], [])
830
+ self . check_decision (more , conformance , AB , [], [])
831
831
832
832
xml = (f'<optionalConform { xml_attrs } >'
833
833
'<notTerm>'
834
834
'<attribute name="attr1" />'
835
835
'</notTerm>'
836
836
'</optionalConform>' )
837
- conformance = check_good_choice (xml , f'[!attr1].{ suffix } ' )
837
+ conformance = self . check_good_choice (xml , f'[!attr1].{ suffix } ' )
838
838
asserts .assert_equal (conformance (0 , attr1 , []), ConformanceDecision .NOT_APPLICABLE , msg_not_applicable )
839
- check_decision (conformance , 0 , [], [])
839
+ self . check_decision (more , conformance , 0 , [], [])
840
840
841
841
xml = ('<otherwiseConform>'
842
842
'<attribute name="attr1" />'
@@ -845,15 +845,15 @@ def check_decision(conformance: Conformance, feature_map: uint, attr_list: list[
845
845
'</optionalConform>'
846
846
f'<optionalConform { xml_attrs } />'
847
847
'</otherwiseConform>' )
848
- conformance = check_good_choice (xml , f'attr1, [AB], O.{ suffix } ' )
848
+ conformance = self . check_good_choice (xml , f'attr1, [AB], O.{ suffix } ' )
849
849
# with no features or attributes, this should end up as O.a, so there should be a choice
850
- check_decision (conformance , 0 , [], [])
850
+ self . check_decision (more , conformance , 0 , [], [])
851
851
# when we have this attribute, we should not have a choice
852
852
asserts .assert_equal (conformance (0 , attr1 , []), ConformanceDecision .MANDATORY , 'Unexpected conformance' )
853
- asserts .assert_equal (conformance (0 , attr1 , []).get_choice () , None , 'Unexpected choice in conformance' )
853
+ asserts .assert_equal (conformance (0 , attr1 , []).choice , None , 'Unexpected choice in conformance' )
854
854
# when we have only this feature, we should not have a choice
855
855
asserts .assert_equal (conformance (AB , [], []), ConformanceDecision .OPTIONAL , 'Unexpected conformance' )
856
- asserts .assert_equal (conformance (AB , [], []).get_choice () , None , 'Unexpected choice in conformance' )
856
+ asserts .assert_equal (conformance (AB , [], []).choice , None , 'Unexpected choice in conformance' )
857
857
858
858
# - multiple in otherwise [AB].a, [CD].b
859
859
xml = ('<otherwiseConform>'
@@ -865,23 +865,23 @@ def check_decision(conformance: Conformance, feature_map: uint, attr_list: list[
865
865
'<feature name="CD" />'
866
866
'</optionalConform>'
867
867
'</otherwiseConform>' )
868
- conformance = check_good_choice (xml , f'attr1, [AB].{ suffix } , [CD].b' )
868
+ conformance = self . check_good_choice (xml , f'attr1, [AB].{ suffix } , [CD].b' )
869
869
asserts .assert_equal (conformance (0 , [], []), ConformanceDecision .NOT_APPLICABLE , msg_not_applicable )
870
870
# when we have this attribute, we should not have a choice
871
871
asserts .assert_equal (conformance (0 , attr1 , []), ConformanceDecision .MANDATORY , 'Unexpected conformance' )
872
- asserts .assert_equal (conformance (0 , attr1 , []).get_choice () , None , 'Unexpected choice in conformance' )
872
+ asserts .assert_equal (conformance (0 , attr1 , []).choice , None , 'Unexpected choice in conformance' )
873
873
# When it's just AB, we should have a choice
874
- check_decision (conformance , AB , [], [])
874
+ self . check_decision (more , conformance , AB , [], [])
875
875
# When we have both the attribute and AB, we should not have a choice
876
876
asserts .assert_equal (conformance (0 , attr1 , []), ConformanceDecision .MANDATORY , 'Unexpected conformance' )
877
- asserts .assert_equal (conformance (0 , attr1 , []).get_choice () , None , 'Unexpected choice in conformance' )
877
+ asserts .assert_equal (conformance (0 , attr1 , []).choice , None , 'Unexpected choice in conformance' )
878
878
# When we have AB and CD, we should be using the AB choice
879
879
CD = self .feature_names_to_bits ['CD' ]
880
880
ABCD = AB | CD
881
- check_decision (conformance , ABCD , [], [])
881
+ self . check_decision (more , conformance , ABCD , [], [])
882
882
# When we just have CD, we still have a choice, but the string should be b
883
883
asserts .assert_equal (conformance (CD , [], []), ConformanceDecision .OPTIONAL , 'Unexpected conformance' )
884
- asserts .assert_equal (conformance (CD , [], []).get_choice () , Choice ('b' , False ), 'Unexpected choice in conformance' )
884
+ asserts .assert_equal (conformance (CD , [], []).choice , Choice ('b' , False ), 'Unexpected choice in conformance' )
885
885
886
886
# Ones that should throw exceptions
887
887
0 commit comments