diff options
author | Damien George <damien.p.george@gmail.com> | 2017-08-09 21:25:48 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-08-09 21:25:48 +1000 |
commit | 3d25d9c7d96f9a54ad510391901af8f5bd82b306 (patch) | |
tree | 0f3ce56bee2fe8ffebc6ef7ca4fa0bebf1e0d610 /tests | |
parent | eb2784e8a2dc17b0f551b68d2b41eece3e5348a7 (diff) | |
download | micropython-3d25d9c7d96f9a54ad510391901af8f5bd82b306.tar.gz micropython-3d25d9c7d96f9a54ad510391901af8f5bd82b306.zip |
py/objstr: Raise an exception for wrong type on RHS of str binary op.
The main case to catch is invalid types for the containment operator, of
the form str.__contains__(non-str).
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basics/containment.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/basics/containment.py b/tests/basics/containment.py index bae3661131..4c94a9bae4 100644 --- a/tests/basics/containment.py +++ b/tests/basics/containment.py @@ -16,6 +16,17 @@ for needle in [haystack[:i+1] for i in range(len(haystack))]: print(haystack, "in", needle, "::", haystack in needle) print(haystack, "not in", needle, "::", haystack not in needle) +# containment of bytes/ints in bytes +print(b'' in b'123') +print(b'0' in b'123', b'1' in b'123') +print(48 in b'123', 49 in b'123') + +# containment of int in str is an error +try: + 1 in '123' +except TypeError: + print('TypeError') + # until here, the tests would work without the 'second attempt' iteration thing. for i in 1, 2: |