Skip to content

Commit 1a9919b

Browse files
Fix some conformance tests
Mostly picking off some easy ones.
1 parent 443a79f commit 1a9919b

File tree

2 files changed

+17
-146
lines changed

2 files changed

+17
-146
lines changed

src/celpy/celtypes.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
import logging
191191
import re
192192
from functools import reduce, wraps
193-
from math import fsum
193+
from math import fsum, trunc
194194
from typing import (
195195
Any,
196196
Callable,
@@ -210,9 +210,8 @@
210210
)
211211

212212
import pendulum
213-
from pendulum import timezone
214213
import pendulum.tz.exceptions
215-
214+
from pendulum import timezone
216215

217216
logger = logging.getLogger(f"celpy.{__name__}")
218217

@@ -398,6 +397,12 @@ def __new__(cls: Type["BoolType"], source: Any) -> "BoolType":
398397
return source
399398
elif isinstance(source, MessageType):
400399
return super().__new__(cls, cast(int, source.get(StringType("value"))))
400+
elif isinstance(source, (str, StringType)):
401+
if source in ("False", "f", "FALSE", "false"):
402+
return super().__new__(cls, 0)
403+
if source in ("True", "t", "TRUE", "true"):
404+
return super().__new__(cls, 1)
405+
return super().__new__(cls, source)
401406
else:
402407
return super().__new__(cls, source)
403408

@@ -495,11 +500,9 @@ def __rtruediv__(self, other: Any) -> "DoubleType":
495500
else:
496501
return DoubleType(super().__rtruediv__(other))
497502

498-
@type_matched
499503
def __eq__(self, other: Any) -> bool:
500504
return super().__eq__(other)
501505

502-
@type_matched
503506
def __ne__(self, other: Any) -> bool:
504507
return super().__ne__(other)
505508

@@ -562,7 +565,7 @@ def __new__(
562565
# Used by protobuf.
563566
return super().__new__(cls, cast(int, source.get(StringType("value"))))
564567
elif isinstance(source, (float, DoubleType)):
565-
convert = int64(round)
568+
convert = int64(trunc)
566569
elif isinstance(source, TimestampType):
567570
convert = int64(lambda src: src.timestamp())
568571
elif isinstance(source, (str, StringType)) and source[:2] in {"0x", "0X"}:
@@ -642,27 +645,21 @@ def __rmod__(self, other: Any) -> "IntType":
642645
go_mod = left_sign * (abs(other) % abs(self))
643646
return IntType(go_mod)
644647

645-
@type_matched
646648
def __eq__(self, other: Any) -> bool:
647649
return super().__eq__(other)
648650

649-
@type_matched
650651
def __ne__(self, other: Any) -> bool:
651652
return super().__ne__(other)
652653

653-
@type_matched
654654
def __lt__(self, other: Any) -> bool:
655655
return super().__lt__(other)
656656

657-
@type_matched
658657
def __le__(self, other: Any) -> bool:
659658
return super().__le__(other)
660659

661-
@type_matched
662660
def __gt__(self, other: Any) -> bool:
663661
return super().__gt__(other)
664662

665-
@type_matched
666663
def __ge__(self, other: Any) -> bool:
667664
return super().__ge__(other)
668665

@@ -729,7 +726,7 @@ def __new__(
729726
if isinstance(source, UintType):
730727
return source
731728
elif isinstance(source, (float, DoubleType)):
732-
convert = uint64(round)
729+
convert = uint64(trunc)
733730
elif isinstance(source, TimestampType):
734731
convert = uint64(lambda src: src.timestamp())
735732
elif isinstance(source, (str, StringType)) and source[:2] in {"0x", "0X"}:
@@ -799,11 +796,9 @@ def __rtruediv__(self, other: Any) -> "UintType":
799796
def __rmod__(self, other: Any) -> "UintType":
800797
return UintType(super().__rmod__(cast(IntType, other)))
801798

802-
@type_matched
803799
def __eq__(self, other: Any) -> bool:
804800
return super().__eq__(other)
805801

806-
@type_matched
807802
def __ne__(self, other: Any) -> bool:
808803
return super().__ne__(other)
809804

@@ -841,6 +836,8 @@ def __ge__(self, other: Any) -> NoReturn:
841836
raise TypeError("no such overload")
842837

843838
def __eq__(self, other: Any) -> bool:
839+
if other is None:
840+
return False
844841
if not isinstance(other, (list, ListType)):
845842
raise TypeError(f"no such overload: ListType == {type(other)}")
846843

@@ -928,6 +925,8 @@ def __getitem__(self, key: Any) -> Any:
928925
return super().__getitem__(key)
929926

930927
def __eq__(self, other: Any) -> bool:
928+
if other is None:
929+
return False
931930
if not isinstance(other, (Mapping, MapType)):
932931
raise TypeError(f"no such overload: MapType == {type(other)}")
933932

@@ -990,7 +989,9 @@ def get(self, key: Any, default: Optional[Any] = None) -> Value:
990989
@staticmethod
991990
def valid_key_type(key: Any) -> bool:
992991
"""Valid CEL key types. Plus native str for tokens in the source when evaluating ``e.f``"""
993-
return isinstance(key, (IntType, UintType, BoolType, StringType, str))
992+
return isinstance(
993+
key, (IntType, UintType, BoolType, StringType, str, DoubleType)
994+
)
994995

995996
def contains(self, item: Value) -> BoolType:
996997
return BoolType(item in self)

tools/wip.toml

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -49,47 +49,8 @@ ternary = "@wip"
4949
timestamp = "@wip"
5050

5151
[comparisons.eq_literal]
52-
eq_double_int = "@wip"
53-
eq_double_uint = "@wip"
54-
eq_dyn_double_int = "@wip"
55-
eq_dyn_double_uint = "@wip"
56-
eq_dyn_int_double = "@wip"
57-
eq_dyn_int_uint = "@wip"
5852
eq_dyn_json_null = "@wip"
59-
eq_dyn_uint_double = "@wip"
60-
eq_dyn_uint_int = "@wip"
61-
eq_int_double = "@wip"
62-
eq_int_uint = "@wip"
63-
eq_list_elem_mixed_types = "@wip"
64-
eq_list_mixed_type_numbers = "@wip"
65-
eq_map_mixed_type_numbers = "@wip"
66-
eq_map_value_mixed_types = "@wip"
67-
eq_mixed_types = "@wip"
68-
eq_uint_double = "@wip"
69-
eq_uint_int = "@wip"
70-
not_eq_double_int = "@wip"
7153
not_eq_double_nan = "@wip"
72-
not_eq_double_uint = "@wip"
73-
not_eq_dyn_double_int = "@wip"
74-
not_eq_dyn_double_null = "@wip"
75-
not_eq_dyn_double_uint = "@wip"
76-
not_eq_dyn_int_double = "@wip"
77-
not_eq_dyn_int_null = "@wip"
78-
not_eq_dyn_int_uint = "@wip"
79-
not_eq_dyn_list_null = "@wip"
80-
not_eq_dyn_map_null = "@wip"
81-
not_eq_dyn_timestamp_null = "@wip"
82-
not_eq_dyn_uint_double = "@wip"
83-
not_eq_dyn_uint_int = "@wip"
84-
not_eq_int_double = "@wip"
85-
not_eq_int_double_nan = "@wip"
86-
not_eq_int_uint = "@wip"
87-
not_eq_list_elem_null = "@wip"
88-
not_eq_list_mixed_type_numbers = "@wip"
89-
not_eq_map_null = "@wip"
90-
not_eq_uint_double = "@wip"
91-
not_eq_uint_double_nan = "@wip"
92-
not_eq_uint_int = "@wip"
9354

9455
[comparisons.eq_wrapper]
9556
eq_bool = "@wip"
@@ -146,125 +107,51 @@ eq_uint64_proto2_null = "@wip"
146107
eq_uint64_proto3_null = "@wip"
147108

148109
[comparisons.gt_literal]
149-
gt_dyn_int_double = "@wip"
150110
gt_dyn_int_small_lossy_double_greater = "@wip"
151-
gt_dyn_int_uint = "@wip"
152111
not_gt_dyn_big_double_int = "@wip"
153112
not_gt_dyn_int_big_double = "@wip"
154113
not_gt_dyn_int_big_uint = "@wip"
155-
not_gt_dyn_int_double = "@wip"
156114
not_gt_dyn_int_small_lossy_double = "@wip"
157-
not_gt_dyn_int_uint = "@wip"
158115
not_gt_dyn_small_double_int = "@wip"
159-
not_gt_dyn_small_int_uint = "@wip"
160116

161117
[comparisons.gte_literal]
162118
gte_dyn_int_big_lossy_double = "@wip"
163-
gte_dyn_int_double = "@wip"
164119
gte_dyn_int_small_lossy_double_equal = "@wip"
165120
gte_dyn_int_small_lossy_double_greater = "@wip"
166-
gte_dyn_int_uint = "@wip"
167121
gte_dyn_small_double_int = "@wip"
168122
not_gte_dyn_int_big_double = "@wip"
169123
not_gte_dyn_int_big_uint = "@wip"
170-
not_gte_dyn_int_double = "@wip"
171-
not_gte_dyn_int_uint = "@wip"
172-
not_gte_dyn_small_int_uint = "@wip"
173-
174-
[comparisons.in_list_literal]
175-
elem_in_mixed_type_list_cross_type = "@wip"
176-
177-
[comparisons.in_map_literal]
178-
key_in_mixed_key_type_map_cross_type = "@wip"
179124

180125
[comparisons.lt_literal]
181-
lt_dyn_int_big_lossy_double = "@wip"
182-
lt_dyn_int_big_uint = "@wip"
183-
lt_dyn_int_double = "@wip"
184-
lt_dyn_int_uint = "@wip"
185-
lt_dyn_small_int_uint = "@wip"
186126
not_lt_dyn_int_big_lossy_double = "@wip"
187-
not_lt_dyn_int_double = "@wip"
188-
not_lt_dyn_int_small_double = "@wip"
189127
not_lt_dyn_int_small_lossy_double = "@wip"
190-
not_lt_dyn_int_uint = "@wip"
191128
not_lt_dyn_small_double_int = "@wip"
192129

193130
[comparisons.lte_literal]
194131
lte_dyn_big_double_int = "@wip"
195-
lte_dyn_int_big_double = "@wip"
196-
lte_dyn_int_big_uint = "@wip"
197-
lte_dyn_int_double = "@wip"
198132
lte_dyn_int_small_lossy_double = "@wip"
199-
lte_dyn_int_uint = "@wip"
200133
lte_dyn_small_double_int = "@wip"
201-
lte_dyn_small_int_uint = "@wip"
202-
not_lte_dyn_int_double = "@wip"
203134
not_lte_dyn_int_small_lossy_double_less = "@wip"
204-
not_lte_dyn_int_uint = "@wip"
205135

206136
[comparisons.ne_literal]
207-
ne_double_int = "@wip"
208137
ne_double_nan = "@wip"
209-
ne_double_uint = "@wip"
210-
ne_int_double = "@wip"
211-
ne_int_uint = "@wip"
212-
ne_mixed_types = "@wip"
213-
ne_proto2_any_unpack = "@wip"
214138
ne_proto2_any_unpack_bytewise_fallback = "@wip"
215-
ne_proto3_any_unpack = "@wip"
216139
ne_proto3_any_unpack_bytewise_fallback = "@wip"
217140
ne_proto_different_types = "@wip"
218-
ne_uint_double = "@wip"
219-
not_ne_double_int = "@wip"
220141
not_ne_double_nan = "@wip"
221-
not_ne_double_uint = "@wip"
222-
not_ne_int_double = "@wip"
223-
not_ne_int_double_nan = "@wip"
224-
not_ne_int_uint = "@wip"
225-
not_ne_uint_double = "@wip"
226-
not_ne_uint_double_nan = "@wip"
227-
228-
[conversions.bool]
229-
string_f = "@wip"
230-
string_false_lowercase = "@wip"
231-
string_false_pascalcase = "@wip"
232-
string_false_uppercase = "@wip"
233-
string_t = "@wip"
234-
string_true_lowercase = "@wip"
235-
string_true_pascalcase = "@wip"
236-
string_true_uppercase = "@wip"
237142

238143
[conversions.identity]
239144
timestamp = "@wip"
240145

241146
[conversions.int]
242-
double_half_neg = "@wip"
243-
double_half_pos = "@wip"
244147
double_int_min_range = "@wip"
245-
double_truncate = "@wip"
246-
double_truncate_neg = "@wip"
247-
248-
[conversions.uint]
249-
double_half = "@wip"
250-
double_truncate = "@wip"
251148

252149
[dynamic.any]
253150
literal = "@wip"
254151

255-
[dynamic.bool]
256-
literal = "@wip"
257-
literal_empty = "@wip"
258-
259-
[dynamic.bytes]
260-
literal = "@wip"
261-
literal_unicode = "@wip"
262-
263152
[dynamic.double]
264153
field_read_proto2_unset = "@wip"
265154
field_read_proto3_unset = "@wip"
266-
literal = "@wip"
267-
literal_zero = "@wip"
268155

269156
[dynamic.float]
270157
field_assign_proto2_range = "@wip"
@@ -406,15 +293,6 @@ comparison_false = "@wip"
406293
comparison_true = "@wip"
407294
convert_symbol_to_int = "@wip"
408295

409-
[fields.in]
410-
mixed_numbers_and_keys_absent = "@wip"
411-
mixed_numbers_and_keys_present = "@wip"
412-
413-
[fields.map_fields]
414-
map_key_mixed_numbers_double_key = "@wip"
415-
map_key_mixed_numbers_int_key = "@wip"
416-
map_key_mixed_numbers_uint_key = "@wip"
417-
418296
[fields.quoted_map_fields]
419297
field_access_dash = "@wip"
420298
field_access_dot = "@wip"
@@ -423,14 +301,6 @@ has_field_dash = "@wip"
423301
has_field_dot = "@wip"
424302
has_field_slash = "@wip"
425303

426-
[lists.in]
427-
double_in_ints = "@wip"
428-
double_in_uints = "@wip"
429-
int_in_doubles = "@wip"
430-
int_in_uints = "@wip"
431-
uint_in_doubles = "@wip"
432-
uint_in_ints = "@wip"
433-
434304
[lists.index]
435305
zero_based_double = "@wip"
436306

0 commit comments

Comments
 (0)