@@ -30,13 +30,15 @@ def __init__(self, string, variables, build_only_mode, findal_unknown_value):
3030 @staticmethod
3131 def evaluate (string , variables , build_only_mode , final_unknown_value = True ):
3232 """
33- string: Expression to evaluate
33+ string: Expression to evaluate
3434 variables: variables that evaluate to true
3535 build_only_mode: if true enables unknown values
3636 findal_unknown_value: findal boolean result if evaluation results in `unknown`
3737 """
3838 try :
39- parser = E2EExpr (string , set (variables ), build_only_mode , final_unknown_value )
39+ parser = E2EExpr (
40+ string , set (variables ), build_only_mode , final_unknown_value
41+ )
4042 return parser .parseAll ()
4143 except ValueError as e :
4244 raise ValueError (str (e ) + ("\n in expression: %r" % string ))
@@ -96,31 +98,121 @@ def test_basic(self):
9698 # Non build-only expressions should work the same
9799 self .assertTrue (E2EExpr .evaluate ("linux" , {"linux" , "rt_feature" }, False ))
98100 self .assertTrue (E2EExpr .evaluate ("rt_feature" , {"linux" , "rt_feature" }, False ))
99- self .assertFalse (E2EExpr .evaluate ( "another_aspect && rt_feature" , {"linux" , "rt_feature" }, False ))
101+ self .assertFalse (
102+ E2EExpr .evaluate (
103+ "another_aspect && rt_feature" , {"linux" , "rt_feature" }, False
104+ )
105+ )
100106 # build-only expressions with no unknowns should work the same
101- self .assertTrue (E2EExpr .evaluate ("linux" , {"linux" }, True , final_unknown_value = False ))
102- self .assertFalse (E2EExpr .evaluate ( "linux && windows" , {"linux" }, True , final_unknown_value = True ))
103- self .assertTrue (E2EExpr .evaluate ( "!(windows || zstd)" , {"linux" }, True , final_unknown_value = False ))
107+ self .assertTrue (
108+ E2EExpr .evaluate ("linux" , {"linux" }, True , final_unknown_value = False )
109+ )
110+ self .assertFalse (
111+ E2EExpr .evaluate (
112+ "linux && windows" , {"linux" }, True , final_unknown_value = True
113+ )
114+ )
115+ self .assertTrue (
116+ E2EExpr .evaluate (
117+ "!(windows || zstd)" , {"linux" }, True , final_unknown_value = False
118+ )
119+ )
104120 # build-only expressions where unknown affects the resulting value
105- self .assertTrue (E2EExpr .evaluate ("rt_feature" , {}, True , final_unknown_value = True ))
106- self .assertFalse (E2EExpr .evaluate ("rt_feature" , {}, True , final_unknown_value = False ))
107- self .assertTrue (E2EExpr .evaluate ("rt_feature" , {"rt_feature" }, True , final_unknown_value = True ))
108- self .assertFalse (E2EExpr .evaluate ("rt_feature" , {"rt_feature" }, True , final_unknown_value = False ))
109- self .assertFalse (E2EExpr .evaluate ("!rt_feature" , {}, True , final_unknown_value = False ))
110- self .assertFalse (E2EExpr .evaluate ("!!rt_feature" , {}, True , final_unknown_value = False ))
111- self .assertTrue (E2EExpr .evaluate ("windows || rt_feature" , {"linux" }, True , final_unknown_value = True ))
112- self .assertFalse (E2EExpr .evaluate ("windows || rt_feature" , {"linux" }, True , final_unknown_value = False ))
113- self .assertTrue (E2EExpr .evaluate ("linux && rt_feature" , {"linux" }, True , final_unknown_value = True ))
114- self .assertFalse (E2EExpr .evaluate ("linux && rt_feature" , {"linux" }, True , final_unknown_value = False ))
115- self .assertTrue (E2EExpr .evaluate ( "linux && !(windows || rt_feature)" , {"linux" }, True , final_unknown_value = True ))
116- self .assertFalse (E2EExpr .evaluate ( "linux && !(windows || rt_feature)" , {"linux" }, True , final_unknown_value = False ))
121+ self .assertTrue (
122+ E2EExpr .evaluate ("rt_feature" , {}, True , final_unknown_value = True )
123+ )
124+ self .assertFalse (
125+ E2EExpr .evaluate ("rt_feature" , {}, True , final_unknown_value = False )
126+ )
127+ self .assertTrue (
128+ E2EExpr .evaluate (
129+ "rt_feature" , {"rt_feature" }, True , final_unknown_value = True
130+ )
131+ )
132+ self .assertFalse (
133+ E2EExpr .evaluate (
134+ "rt_feature" , {"rt_feature" }, True , final_unknown_value = False
135+ )
136+ )
137+ self .assertFalse (
138+ E2EExpr .evaluate ("!rt_feature" , {}, True , final_unknown_value = False )
139+ )
140+ self .assertFalse (
141+ E2EExpr .evaluate ("!!rt_feature" , {}, True , final_unknown_value = False )
142+ )
143+ self .assertTrue (
144+ E2EExpr .evaluate (
145+ "windows || rt_feature" , {"linux" }, True , final_unknown_value = True
146+ )
147+ )
148+ self .assertFalse (
149+ E2EExpr .evaluate (
150+ "windows || rt_feature" , {"linux" }, True , final_unknown_value = False
151+ )
152+ )
153+ self .assertTrue (
154+ E2EExpr .evaluate (
155+ "linux && rt_feature" , {"linux" }, True , final_unknown_value = True
156+ )
157+ )
158+ self .assertFalse (
159+ E2EExpr .evaluate (
160+ "linux && rt_feature" , {"linux" }, True , final_unknown_value = False
161+ )
162+ )
163+ self .assertTrue (
164+ E2EExpr .evaluate (
165+ "linux && !(windows || rt_feature)" ,
166+ {"linux" },
167+ True ,
168+ final_unknown_value = True ,
169+ )
170+ )
171+ self .assertFalse (
172+ E2EExpr .evaluate (
173+ "linux && !(windows || rt_feature)" ,
174+ {"linux" },
175+ True ,
176+ final_unknown_value = False ,
177+ )
178+ )
117179 # build-only expressions where unknown does not affect the resulting value
118- self .assertTrue (E2EExpr .evaluate ("linux || rt_feature" , {"linux" }, True , final_unknown_value = True ))
119- self .assertTrue (E2EExpr .evaluate ("linux || rt_feature" , {"linux" }, True , final_unknown_value = False ))
120- self .assertFalse (E2EExpr .evaluate ("windows && rt_feature" , {"linux" }, True , final_unknown_value = True ))
121- self .assertFalse (E2EExpr .evaluate ("windows && rt_feature" , {"linux" }, True , final_unknown_value = False ))
122- self .assertFalse (E2EExpr .evaluate ( "linux && (windows && rt_feature)" , {"linux" }, True , final_unknown_value = True ))
123- self .assertFalse (E2EExpr .evaluate ( "linux && (windows && rt_feature)" , {"linux" }, True , final_unknown_value = False ))
180+ self .assertTrue (
181+ E2EExpr .evaluate (
182+ "linux || rt_feature" , {"linux" }, True , final_unknown_value = True
183+ )
184+ )
185+ self .assertTrue (
186+ E2EExpr .evaluate (
187+ "linux || rt_feature" , {"linux" }, True , final_unknown_value = False
188+ )
189+ )
190+ self .assertFalse (
191+ E2EExpr .evaluate (
192+ "windows && rt_feature" , {"linux" }, True , final_unknown_value = True
193+ )
194+ )
195+ self .assertFalse (
196+ E2EExpr .evaluate (
197+ "windows && rt_feature" , {"linux" }, True , final_unknown_value = False
198+ )
199+ )
200+ self .assertFalse (
201+ E2EExpr .evaluate (
202+ "linux && (windows && rt_feature)" ,
203+ {"linux" },
204+ True ,
205+ final_unknown_value = True ,
206+ )
207+ )
208+ self .assertFalse (
209+ E2EExpr .evaluate (
210+ "linux && (windows && rt_feature)" ,
211+ {"linux" },
212+ True ,
213+ final_unknown_value = False ,
214+ )
215+ )
124216
125217
126218if __name__ == "__main__" :
0 commit comments