diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-29 02:44:13 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-29 20:31:13 +0300 |
commit | 4f46c441efef3a88498c186fdace5614bbe26cd7 (patch) | |
tree | 93075eabb138b93c3e598c7fc8dd0f8660e6bb2d /tests/basics/subclass-native1.py | |
parent | 6ead0d2fbc21795b0a8f0f69a80f3752c9b0d1de (diff) | |
download | micropython-4f46c441efef3a88498c186fdace5614bbe26cd7.tar.gz micropython-4f46c441efef3a88498c186fdace5614bbe26cd7.zip |
tests: Add basic tests for subclassing native types and using special methods.
Even of these, some features do not yet work as expected.
Diffstat (limited to 'tests/basics/subclass-native1.py')
-rw-r--r-- | tests/basics/subclass-native1.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/basics/subclass-native1.py b/tests/basics/subclass-native1.py new file mode 100644 index 0000000000..a176893425 --- /dev/null +++ b/tests/basics/subclass-native1.py @@ -0,0 +1,31 @@ +class mylist(list): + pass + +a = mylist([1, 2, 5]) +# Test setting instance attr +a.attr = "something" +# Test base type __str__ +print(a) +# Test getting instance attr +print(a.attr) +# Test base type ->subscr +print(a[-1]) +a[0] = -1 +print(a) +# Test another base type unary op +print(len(a)) + +# Test binary op of base type, with 2nd arg being raw base type +print(a + [20, 30, 40]) +# Test binary op of base type, with 2nd arg being same class as 1st arg +# TODO: Faults +#print(a + a) + +def foo(): + print("hello from foo") + +try: + class myfunc(type(foo)): + pass +except TypeError: + print("TypeError") |