summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/basics/class_store_class.py47
-rw-r--r--tests/basics/int1.py1
-rw-r--r--tests/basics/list_slice_assign.py9
-rw-r--r--tests/basics/string_partition.py11
-rw-r--r--tests/basics/string_strip.py10
-rw-r--r--tests/basics/subclass_native_cmp.py9
6 files changed, 87 insertions, 0 deletions
diff --git a/tests/basics/class_store_class.py b/tests/basics/class_store_class.py
new file mode 100644
index 0000000000..60f65220d9
--- /dev/null
+++ b/tests/basics/class_store_class.py
@@ -0,0 +1,47 @@
+# Inspired by urlparse.py from CPython 3.3 stdlib
+# There was a bug in MicroPython that under some conditions class stored
+# in instance attribute later was returned "bound" as if it was a method,
+# which caused class constructor to receive extra argument.
+try:
+ from collections import namedtuple
+except ImportError:
+ from _collections import namedtuple
+
+_DefragResultBase = namedtuple('DefragResult', 'foo bar')
+
+class _ResultMixinStr(object):
+ def encode(self):
+ return self._encoded_counterpart(*(x.encode() for x in self))
+
+class _ResultMixinBytes(object):
+ def decode(self):
+ return self._decoded_counterpart(*(x.decode() for x in self))
+
+class DefragResult(_DefragResultBase, _ResultMixinStr):
+ pass
+
+class DefragResultBytes(_DefragResultBase, _ResultMixinBytes):
+ pass
+
+
+DefragResult._encoded_counterpart = DefragResultBytes
+DefragResultBytes._decoded_counterpart = DefragResult
+
+# Due to differences in type and native subclass printing,
+# the best thing we can do here is to just test that no exceptions
+# happen
+
+#print(DefragResult, DefragResult._encoded_counterpart)
+#print(DefragResultBytes, DefragResultBytes._decoded_counterpart)
+
+o1 = DefragResult("a", "b")
+#print(o1, type(o1))
+o2 = DefragResultBytes("a", "b")
+#print(o2, type(o2))
+
+#print(o1._encoded_counterpart)
+_o1 = o1.encode()
+print(_o1[0], _o1[1])
+#print(_o1, type(_o1))
+
+print("All's ok")
diff --git a/tests/basics/int1.py b/tests/basics/int1.py
index 2daef9bf0e..e8a0a04683 100644
--- a/tests/basics/int1.py
+++ b/tests/basics/int1.py
@@ -46,6 +46,7 @@ print(int('0B100', 2))
print(int('0100', 2))
print(int(' \t 0o12', 8))
print(int('0o12 \t ', 8))
+print(int(b"12", 10))
def test(value, base):
diff --git a/tests/basics/list_slice_assign.py b/tests/basics/list_slice_assign.py
index f880520461..baa9a00810 100644
--- a/tests/basics/list_slice_assign.py
+++ b/tests/basics/list_slice_assign.py
@@ -11,6 +11,9 @@ print(l)
l = list(x)
l[1:3] = []
print(l)
+l = list(x)
+del l[1:3]
+print(l)
l = list(x)
l[:3] = [10, 20]
@@ -18,6 +21,9 @@ print(l)
l = list(x)
l[:3] = []
print(l)
+l = list(x)
+del l[:3]
+print(l)
l = list(x)
l[:-3] = [10, 20]
@@ -25,3 +31,6 @@ print(l)
l = list(x)
l[:-3] = []
print(l)
+l = list(x)
+del l[:-3]
+print(l)
diff --git a/tests/basics/string_partition.py b/tests/basics/string_partition.py
index ad70d02509..fe0070a658 100644
--- a/tests/basics/string_partition.py
+++ b/tests/basics/string_partition.py
@@ -27,3 +27,14 @@ except ValueError:
print("Raised ValueError")
else:
print("Did not raise ValueError")
+
+# Bytes
+print(b"abba".partition(b'b'))
+try:
+ print(b"abba".partition('b'))
+except TypeError:
+ print("Raised TypeError")
+try:
+ print("abba".partition(b'b'))
+except TypeError:
+ print("Raised TypeError")
diff --git a/tests/basics/string_strip.py b/tests/basics/string_strip.py
index 8e03eff93a..4684c2a248 100644
--- a/tests/basics/string_strip.py
+++ b/tests/basics/string_strip.py
@@ -10,3 +10,13 @@ print('www.example.com'.lstrip('cmowz.'))
print(' spacious '.rstrip())
print('mississippi'.rstrip('ipz'))
+
+print(b'mississippi'.rstrip(b'ipz'))
+try:
+ print(b'mississippi'.rstrip('ipz'))
+except TypeError:
+ print("TypeError")
+try:
+ print('mississippi'.rstrip(b'ipz'))
+except TypeError:
+ print("TypeError")
diff --git a/tests/basics/subclass_native_cmp.py b/tests/basics/subclass_native_cmp.py
new file mode 100644
index 0000000000..1a095bfa1a
--- /dev/null
+++ b/tests/basics/subclass_native_cmp.py
@@ -0,0 +1,9 @@
+# Test calling non-special method inherited from native type
+
+class mytuple(tuple):
+ pass
+
+t = mytuple((1, 2, 3))
+print(t)
+print(t == (1, 2, 3))
+print((1, 2, 3) == t)