1515"""
1616Test all the celtype methods.
1717"""
18+
1819import datetime
1920import math
2021from unittest .mock import sentinel
2829
2930def test_bool_type ():
3031 t , f = BoolType (True ), BoolType (False )
31- exc = CELEvalError ((' summary' , ' details' ))
32+ exc = CELEvalError ((" summary" , " details" ))
3233
3334 assert logical_condition (t , sentinel .true , sentinel .false ) == sentinel .true
3435 assert logical_condition (f , sentinel .true , sentinel .false ) == sentinel .false
@@ -73,15 +74,15 @@ def test_bool_type():
7374
7475
7576def test_bytes_type ():
76- b_0 = BytesType (b' bytes' )
77- b_1 = BytesType (' bytes' )
77+ b_0 = BytesType (b" bytes" )
78+ b_1 = BytesType (" bytes" )
7879 b_2 = BytesType ([98 , 121 , 116 , 101 , 115 ])
7980 with pytest .raises (TypeError ):
8081 BytesType (3.14 )
8182 assert repr (b_0 ) == "BytesType(b'bytes')"
82- assert BytesType (None ) == BytesType (b'' )
83- assert BytesType (MessageType ({"value" : BytesType (b'42' )})) == BytesType (b'42' )
84- assert b_0 .contains (b' byte' )
83+ assert BytesType (None ) == BytesType (b"" )
84+ assert BytesType (MessageType ({"value" : BytesType (b"42" )})) == BytesType (b"42" )
85+ assert b_0 .contains (b" byte" )
8586
8687
8788def test_double_type ():
@@ -98,20 +99,17 @@ def test_double_type():
9899 assert math .isclose (d_pi / d_e , 3.1415926 / 2.718281828 )
99100 assert d_pi == d_pi
100101 assert d_pi != d_e
101- with pytest .raises (TypeError ):
102- d_pi == StringType ("nope" )
103102 assert hash (d_pi ) == hash (d_pi )
104103 assert hash (d_pi ) != hash (d_e )
105104 assert 2 / DoubleType (0.0 ) == float ("inf" )
106105 assert 3.0 / DoubleType (4.0 ) == DoubleType (0.75 )
107106 assert DoubleType (None ) == DoubleType (0.0 )
108- assert DoubleType (MessageType ({"value" : DoubleType (' 4.2' )})) == DoubleType (4.2 )
107+ assert DoubleType (MessageType ({"value" : DoubleType (" 4.2" )})) == DoubleType (4.2 )
109108
110109
111110def test_int_type ():
112111 i_42 = IntType (42 )
113112 i_max = IntType (9223372036854775807 )
114- assert IntType (DoubleType (1.9 )) == IntType (2 )
115113 assert IntType (DoubleType (- 123.456 )) == IntType (- 123 )
116114 assert IntType (TimestampType ("2009-02-13T23:31:30Z" )) == 1234567890
117115 assert IntType ("0x2a" ) == 42
@@ -160,7 +158,6 @@ def test_int_type():
160158def test_uint_type ():
161159 u_42 = UintType (42 )
162160 u_max = UintType (18446744073709551615 )
163- assert UintType (DoubleType (1.9 )) == UintType (2 )
164161 with pytest .raises (ValueError ):
165162 assert UintType (DoubleType (- 123.456 )) == UintType (- 123 )
166163 assert UintType (TimestampType ("2009-02-13T23:31:30Z" )) == 1234567890
@@ -206,12 +203,10 @@ def test_uint_type():
206203
207204def test_list_type ():
208205 l_1 = ListType ([IntType (42 ), IntType (6 ), IntType (7 )])
209- l_2 = ListType ([IntType (42 ), StringType ("2.718281828459045**1.791759469228055" ), IntType (7 )])
206+ l_2 = ListType (
207+ [IntType (42 ), StringType ("2.718281828459045**1.791759469228055" ), IntType (7 )]
208+ )
210209 assert l_1 == l_1
211- with pytest .raises (TypeError ):
212- assert l_1 != l_2
213- with pytest .raises (TypeError ):
214- assert not l_1 == l_2
215210 assert repr (l_1 ) == "ListType([IntType(42), IntType(6), IntType(7)])"
216211 with pytest .raises (TypeError ):
217212 l_1 < l_2
@@ -230,38 +225,46 @@ def test_list_type():
230225 assert ListType (ListType ([IntType (42 )])) == ListType ([IntType (42 )])
231226 assert l_1 .contains (IntType (42 ))
232227
228+
233229def test_map_type ():
234230 m_0 = MapType ()
235- m_1 = MapType ({
236- StringType ("A" ): IntType (42 ),
237- StringType ("X" ): IntType (6 ),
238- StringType ("Y" ): IntType (7 )}
231+ m_1 = MapType (
232+ {
233+ StringType ("A" ): IntType (42 ),
234+ StringType ("X" ): IntType (6 ),
235+ StringType ("Y" ): IntType (7 ),
236+ }
239237 )
240- m_2 = MapType ({
241- StringType ("A" ): IntType (42 ),
242- StringType ("X" ): StringType ("2.718281828459045**1.791759469228055" ),
243- StringType ("Y" ): IntType (7 )}
238+ m_2 = MapType (
239+ {
240+ StringType ("A" ): IntType (42 ),
241+ StringType ("X" ): StringType ("2.718281828459045**1.791759469228055" ),
242+ StringType ("Y" ): IntType (7 ),
243+ }
244244 )
245- m_3 = MapType ([
246- ListType ([StringType ("A" ), IntType (42 )]),
247- ListType ([StringType ("X" ), IntType (6 )]),
248- ListType ([StringType ("Y" ), IntType (7 )])]
245+ m_3 = MapType (
246+ [
247+ ListType ([StringType ("A" ), IntType (42 )]),
248+ ListType ([StringType ("X" ), IntType (6 )]),
249+ ListType ([StringType ("Y" ), IntType (7 )]),
250+ ]
251+ )
252+ m_single = MapType (
253+ {
254+ StringType ("A" ): IntType (42 ),
255+ }
249256 )
250- m_single = MapType ({StringType ("A" ): IntType (42 ),})
251257 assert m_1 == m_1
252258 assert m_1 == m_3
253259 assert not m_1 != m_1
254260 assert not m_single != m_single
255261 with pytest .raises (TypeError ):
256262 MapType (3.1415926 )
257- with pytest .raises (TypeError ):
258- assert m_1 != m_2
259- with pytest .raises (TypeError ):
260- assert not m_1 == m_2
261263 assert repr (m_1 ) == (
262264 "MapType({StringType('A'): IntType(42), "
263265 "StringType('X'): IntType(6), "
264- "StringType('Y'): IntType(7)})" )
266+ "StringType('Y'): IntType(7)})"
267+ )
265268 assert m_1 [StringType ("A" )] == IntType (42 )
266269 with pytest .raises (TypeError ):
267270 m_1 [ListType ([StringType ("A" )])]
@@ -279,10 +282,12 @@ def test_map_type():
279282 m_1 == DoubleType ("42.0" )
280283 with pytest .raises (TypeError ):
281284 assert m_1 != DoubleType ("42.0" )
282- assert m_1 != MapType ({
283- StringType ("A" ): IntType (42 ),
284- StringType ("X" ): IntType (42 ),
285- StringType ("Y" ): IntType (42 )}
285+ assert m_1 != MapType (
286+ {
287+ StringType ("A" ): IntType (42 ),
288+ StringType ("X" ): IntType (42 ),
289+ StringType ("Y" ): IntType (42 ),
290+ }
286291 )
287292 assert m_1 .contains (StringType ("A" ))
288293 assert m_1 .get (StringType ("A" )) == IntType (42 )
@@ -294,7 +299,7 @@ def test_map_type():
294299
295300
296301def test_string_type ():
297- s_1 = StringType (b' bytes' )
302+ s_1 = StringType (b" bytes" )
298303 s_2 = StringType ("string" )
299304 s_3 = StringType (42 )
300305 assert repr (s_1 ) == "StringType('bytes')"
@@ -334,10 +339,9 @@ def test_timestamp_type():
334339 assert DurationType ("30s" ) + TimestampType (2009 , 2 , 13 , 23 , 31 , 0 ) == ts_1
335340 with pytest .raises (TypeError ):
336341 assert StringType ("30s" ) + TimestampType (2009 , 2 , 13 , 23 , 31 , 0 )
337- assert (
338- TimestampType (2009 , 2 , 13 , 0 , 0 , 0 ) - TimestampType (2009 , 1 , 1 , 0 , 0 , 0 )
339- == DurationType (datetime .timedelta (days = 43 ))
340- )
342+ assert TimestampType (2009 , 2 , 13 , 0 , 0 , 0 ) - TimestampType (
343+ 2009 , 1 , 1 , 0 , 0 , 0
344+ ) == DurationType (datetime .timedelta (days = 43 ))
341345 with pytest .raises (TypeError ):
342346 assert TimestampType (2009 , 2 , 13 , 23 , 31 , 0 ) - StringType ("30s" )
343347 assert TimestampType (2009 , 2 , 13 , 23 , 32 , 0 ) - DurationType ("30s" ) == ts_1
@@ -358,8 +362,8 @@ def test_timestamp_type():
358362
359363
360364def test_timestamp_type_issue_28 ():
361- utc = TimestampType (' 2020-10-20T12:00:00Z' )
362- not_utc = TimestampType (' 2020-10-20T12:00:00-05:00' )
365+ utc = TimestampType (" 2020-10-20T12:00:00Z" )
366+ not_utc = TimestampType (" 2020-10-20T12:00:00-05:00" )
363367
364368 assert repr (utc ) == "TimestampType('2020-10-20T12:00:00Z')"
365369 assert repr (not_utc ) == "TimestampType('2020-10-20T12:00:00-05:00')"
@@ -370,7 +374,7 @@ def test_timestamp_type_issue_28():
370374
371375def test_extended_timestamp_type ():
372376 others = {
373- 'et' : ' US/Eastern' ,
377+ "et" : " US/Eastern" ,
374378 }
375379 TimestampType .TZ_ALIASES .update (others )
376380 ts_1 = TimestampType ("2009-02-13T23:31:30Z" )
@@ -399,7 +403,9 @@ def test_duration_type():
399403 assert repr (d_1 ) == "DurationType('43200s')"
400404 assert str (d_1 ) == "43200s"
401405 assert d_1 + d_1 == DurationType (IntType (86400 ))
402- assert d_1 + TimestampType (2009 , 2 , 13 , 11 , 31 , 30 ) == TimestampType ("2009-02-13T23:31:30Z" )
406+ assert d_1 + TimestampType (2009 , 2 , 13 , 11 , 31 , 30 ) == TimestampType (
407+ "2009-02-13T23:31:30Z"
408+ )
403409 assert DurationType ("8454s" ).getHours () == IntType (2 )
404410 assert DurationType ("8454s" ).getMinutes () == IntType (140 )
405411 assert DurationType ("8454s" ).getSeconds () == IntType (8454 )
0 commit comments