~launchpad-committers/storm/lp

« back to all changes in this revision

Viewing changes to storm/tests/expr.py

  • Committer: Colin Watson
  • Date: 2023-07-06 10:51:34 UTC
  • mfrom: (386.34.138 storm)
  • Revision ID: cjwatson@canonical.com-20230706105134-rzpb4opv8nfpg56r
Merge Storm 0.26 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
        self.assertEqual(like_expr.expr2, u"abc!!!!!_!%%")
200
200
        self.assertEqual(like_expr.escape, u"!")
201
201
 
 
202
    def test_startswith_case(self):
 
203
        expr = Func1()
 
204
        like_expr = expr.startswith(u"abc!!_%")
 
205
        self.assertIsNone(like_expr.case_sensitive)
 
206
        like_expr = expr.startswith(u"abc!!_%", case_sensitive=True)
 
207
        self.assertIs(True, like_expr.case_sensitive)
 
208
        like_expr = expr.startswith(u"abc!!_%", case_sensitive=False)
 
209
        self.assertIs(False, like_expr.case_sensitive)
 
210
 
202
211
    def test_endswith(self):
203
212
        expr = Func1()
204
213
        self.assertRaises(ExprError, expr.startswith, b"not a unicode string")
209
218
        self.assertEqual(like_expr.expr2, u"%abc!!!!!_!%")
210
219
        self.assertEqual(like_expr.escape, u"!")
211
220
 
 
221
    def test_endswith_case(self):
 
222
        expr = Func1()
 
223
        like_expr = expr.endswith(u"abc!!_%")
 
224
        self.assertIsNone(like_expr.case_sensitive)
 
225
        like_expr = expr.endswith(u"abc!!_%", case_sensitive=True)
 
226
        self.assertIs(True, like_expr.case_sensitive)
 
227
        like_expr = expr.endswith(u"abc!!_%", case_sensitive=False)
 
228
        self.assertIs(False, like_expr.case_sensitive)
 
229
 
212
230
    def test_contains_string(self):
213
231
        expr = Func1()
214
232
        self.assertRaises(
220
238
        self.assertEqual(like_expr.expr2, u"%abc!!!!!_!%%")
221
239
        self.assertEqual(like_expr.escape, u"!")
222
240
 
 
241
    def test_contains_string_case(self):
 
242
        expr = Func1()
 
243
        like_expr = expr.contains_string(u"abc!!_%")
 
244
        self.assertIsNone(like_expr.case_sensitive)
 
245
        like_expr = expr.contains_string(u"abc!!_%", case_sensitive=True)
 
246
        self.assertIs(True, like_expr.case_sensitive)
 
247
        like_expr = expr.contains_string(u"abc!!_%", case_sensitive=False)
 
248
        self.assertIs(False, like_expr.case_sensitive)
 
249
 
 
250
    def test_is(self):
 
251
        expr = Is(elem1, elem2)
 
252
        self.assertEqual(expr.expr1, elem1)
 
253
        self.assertEqual(expr.expr2, elem2)
 
254
 
 
255
    def test_is_not(self):
 
256
        expr = IsNot(elem1, elem2)
 
257
        self.assertEqual(expr.expr1, elem1)
 
258
        self.assertEqual(expr.expr2, elem2)
 
259
 
223
260
    def test_eq(self):
224
261
        expr = Eq(elem1, elem2)
225
262
        self.assertEqual(expr.expr1, elem1)
1074
1111
        self.assertEqual(statement, "?")
1075
1112
        self.assertVariablesEqual(state.parameters, [Variable("value")])
1076
1113
 
 
1114
    def test_is_null(self):
 
1115
        expr = Is(Func1(), None)
 
1116
        state = State()
 
1117
        statement = compile(expr, state)
 
1118
        self.assertEqual(statement, "func1() IS NULL")
 
1119
        self.assertEqual(state.parameters, [])
 
1120
 
 
1121
    def test_is_true(self):
 
1122
        expr = Is(Func1(), True)
 
1123
        state = State()
 
1124
        statement = compile(expr, state)
 
1125
        self.assertEqual(statement, "func1() IS TRUE")
 
1126
        self.assertEqual(state.parameters, [])
 
1127
 
 
1128
    def test_is_false(self):
 
1129
        expr = Is(Func1(), False)
 
1130
        state = State()
 
1131
        statement = compile(expr, state)
 
1132
        self.assertEqual(statement, "func1() IS FALSE")
 
1133
        self.assertEqual(state.parameters, [])
 
1134
 
 
1135
    def test_is_invalid(self):
 
1136
        expr = Is(Func1(), "x")
 
1137
        self.assertRaises(CompileError, compile, expr)
 
1138
 
 
1139
    def test_is_not_null(self):
 
1140
        expr = IsNot(Func1(), None)
 
1141
        state = State()
 
1142
        statement = compile(expr, state)
 
1143
        self.assertEqual(statement, "func1() IS NOT NULL")
 
1144
        self.assertEqual(state.parameters, [])
 
1145
 
 
1146
    def test_is_not_true(self):
 
1147
        expr = IsNot(Func1(), True)
 
1148
        state = State()
 
1149
        statement = compile(expr, state)
 
1150
        self.assertEqual(statement, "func1() IS NOT TRUE")
 
1151
        self.assertEqual(state.parameters, [])
 
1152
 
 
1153
    def test_is_not_false(self):
 
1154
        expr = IsNot(Func1(), False)
 
1155
        state = State()
 
1156
        statement = compile(expr, state)
 
1157
        self.assertEqual(statement, "func1() IS NOT FALSE")
 
1158
        self.assertEqual(state.parameters, [])
 
1159
 
 
1160
    def test_is_not_invalid(self):
 
1161
        expr = IsNot(Func1(), "x")
 
1162
        self.assertRaises(CompileError, compile, expr)
 
1163
 
1077
1164
    def test_eq(self):
1078
1165
        expr = Eq(Func1(), Func2())
1079
1166
        state = State()
2246
2333
        self.assertEqual(py_expr, "_0")
2247
2334
        self.assertEqual(state.parameters, ["value"])
2248
2335
 
 
2336
    def test_is_null(self):
 
2337
        expr = Is(Variable(True), None)
 
2338
        state = State()
 
2339
        statement = compile_python(expr, state)
 
2340
        self.assertEqual(statement, "_0 is None")
 
2341
        self.assertEqual(state.parameters, [True])
 
2342
 
 
2343
    def test_is_true(self):
 
2344
        expr = Is(Variable(True), True)
 
2345
        state = State()
 
2346
        statement = compile_python(expr, state)
 
2347
        self.assertEqual(statement, "_0 is _1")
 
2348
        self.assertEqual(state.parameters, [True, True])
 
2349
 
 
2350
    def test_is_false(self):
 
2351
        expr = Is(Variable(True), False)
 
2352
        state = State()
 
2353
        statement = compile_python(expr, state)
 
2354
        self.assertEqual(statement, "_0 is _1")
 
2355
        self.assertEqual(state.parameters, [True, False])
 
2356
 
 
2357
    def test_is_not_null(self):
 
2358
        expr = IsNot(Variable(True), None)
 
2359
        state = State()
 
2360
        statement = compile_python(expr, state)
 
2361
        self.assertEqual(statement, "_0 is not None")
 
2362
        self.assertEqual(state.parameters, [True])
 
2363
 
 
2364
    def test_is_not_true(self):
 
2365
        expr = IsNot(Variable(True), True)
 
2366
        state = State()
 
2367
        statement = compile_python(expr, state)
 
2368
        self.assertEqual(statement, "_0 is not _1")
 
2369
        self.assertEqual(state.parameters, [True, True])
 
2370
 
 
2371
    def test_is_not_false(self):
 
2372
        expr = IsNot(Variable(True), False)
 
2373
        state = State()
 
2374
        statement = compile_python(expr, state)
 
2375
        self.assertEqual(statement, "_0 is not _1")
 
2376
        self.assertEqual(state.parameters, [True, False])
 
2377
 
2249
2378
    def test_eq(self):
2250
2379
        expr = Eq(Variable(1), Variable(2))
2251
2380
        state = State()