diff options
| author | Damien George | 2016-10-17 11:43:47 +1100 |
|---|---|---|
| committer | Damien George | 2016-10-17 11:43:47 +1100 |
| commit | e9404e5f5f058db954ac0a92cb5acfcef6f6724a (patch) | |
| tree | 6d5ced599e860604aea660de5fb5be1199d29963 /tests/basics | |
| parent | 453c2e8f55132d92933f2de0308166730576ecc4 (diff) | |
tests: Improve coverage of array, range, dict, slice, exc, unicode.
Diffstat (limited to 'tests/basics')
| -rw-r--r-- | tests/basics/array1.py | 4 | ||||
| -rw-r--r-- | tests/basics/builtin_range.py | 6 | ||||
| -rw-r--r-- | tests/basics/dict1.py | 24 | ||||
| -rw-r--r-- | tests/basics/dict_views.py | 15 | ||||
| -rw-r--r-- | tests/basics/int_constfolding.py | 5 | ||||
| -rw-r--r-- | tests/basics/slice_attrs.py | 9 |
6 files changed, 63 insertions, 0 deletions
diff --git a/tests/basics/array1.py b/tests/basics/array1.py index e5ea6683c..c45b883c9 100644 --- a/tests/basics/array1.py +++ b/tests/basics/array1.py @@ -21,6 +21,10 @@ print(array.array('i')) print(bool(array.array('i'))) print(bool(array.array('i', [1]))) +# containment, with incorrect type +print('12' in array.array('B', b'12')) +print([] in array.array('B', b'12')) + # bad typecode try: array.array('X') diff --git a/tests/basics/builtin_range.py b/tests/basics/builtin_range.py index 9110cf12c..59fc0344a 100644 --- a/tests/basics/builtin_range.py +++ b/tests/basics/builtin_range.py @@ -50,3 +50,9 @@ try: range(1)[0] = 1 except TypeError: print("TypeError") + +# bad attr (can't store) +try: + range(4).start = 0 +except AttributeError: + print('AttributeError') diff --git a/tests/basics/dict1.py b/tests/basics/dict1.py index c70ca588a..21d5af272 100644 --- a/tests/basics/dict1.py +++ b/tests/basics/dict1.py @@ -16,3 +16,27 @@ while x < 100: d[x] = x x += 1 print(d[50]) + +# equality operator on dicts of different size +print({} == {1:1}) + +# equality operator on dicts of same size but with different keys +print({1:1} == {2:1}) + +# value not found +try: + {}[0] +except KeyError: + print('KeyError') + +# unsupported unary op +try: + +{} +except TypeError: + print('TypeError') + +# unsupported binary op +try: + {} + {} +except TypeError: + print('TypeError') diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py index fbf63fa0a..7ebcc1f56 100644 --- a/tests/basics/dict_views.py +++ b/tests/basics/dict_views.py @@ -3,4 +3,19 @@ for m in d.items, d.values, d.keys: print(m()) print(list(m())) +# print a view with more than one item +print({1:1, 2:1}.values()) + +# unsupported binary op on a dict values view +try: + {1:1}.values() + 1 +except TypeError: + print('TypeError') + +# unsupported binary op on a dict keys view +try: + {1:1}.keys() + 1 +except TypeError: + print('TypeError') + # set operations still to come diff --git a/tests/basics/int_constfolding.py b/tests/basics/int_constfolding.py index c01f964da..aa38fa6b8 100644 --- a/tests/basics/int_constfolding.py +++ b/tests/basics/int_constfolding.py @@ -38,3 +38,8 @@ print(-123 // 7, -123 % 7) print(123 // -7, 123 % -7) print(-123 // -7, -123 % -7) +# zero big-num on rhs +print(1 + ((1 << 65) - (1 << 65))) + +# negative big-num on rhs +print(1 + (-(1 << 65))) diff --git a/tests/basics/slice_attrs.py b/tests/basics/slice_attrs.py index 76368a78c..67456ff8e 100644 --- a/tests/basics/slice_attrs.py +++ b/tests/basics/slice_attrs.py @@ -14,3 +14,12 @@ except: A()[1:2:3] + +# test storing to attr (shouldn't be allowed) +class B: + def __getitem__(self, idx): + try: + idx.start = 0 + except AttributeError: + print('AttributeError') +B()[:] |
