Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
4f46c441
Commit
4f46c441
authored
Apr 29, 2014
by
Paul Sokolovsky
Browse files
tests: Add basic tests for subclassing native types and using special methods.
Even of these, some features do not yet work as expected.
parent
6ead0d2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/basics/subclass-native1.py
0 → 100644
View file @
4f46c441
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"
)
tests/basics/subclass-native2.py
0 → 100644
View file @
4f46c441
class
Base1
:
def
__init__
(
self
,
*
args
):
print
(
"Base1.__init__"
,
args
)
class
Clist1
(
Base1
,
list
):
pass
class
Ctuple1
(
Base1
,
tuple
):
pass
a
=
Clist1
()
print
(
len
(
a
))
a
=
Clist1
([
1
,
2
,
3
])
print
(
len
(
a
))
a
=
Ctuple1
()
print
(
len
(
a
))
a
=
Ctuple1
([
1
,
2
,
3
])
# TODO: Faults
#print(len(a))
print
(
"---"
)
class
Clist2
(
list
,
Base1
):
pass
class
Ctuple2
(
tuple
,
Base1
):
pass
a
=
Clist2
()
print
(
len
(
a
))
a
=
Clist2
([
1
,
2
,
3
])
print
(
len
(
a
))
#a = Ctuple2()
#print(len(a))
#a = Ctuple2([1, 2, 3])
#print(len(a))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment