FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonnet/tests/test_repr.py at just · pythonnet/pythonnet · GitHub
pythonnet
pythonnet
Repository navigation
Code
Issues
147
(147)
Pull requests
11
(11)
Discussions
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonnet
/
tests
/
test_repr.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
68 lines (55 loc) · 2.17 KB
Breadcrumbs
pythonnet
/
tests
/
test_repr.py
Copy path
File metadata and controls
68 lines (55 loc) · 2.17 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
"""Test __repr__ output"""
import
System
import
pytest
from
Python
.
Test
import
ReprTest
def
test_basic
():
"""Test Point class which implements both ToString and __repr__ without inheritance"""
ob
=
ReprTest
.
Point
(
1
,
2
)
# point implements ToString() and __repr__()
assert
ob
.
__repr__
()
==
"Point(1,2)"
assert
str
(
ob
)
==
"Python.Test.ReprTest+Point: X=1, Y=2"
def
test_system_string
():
"""Test system string"""
ob
=
System
.
String
(
"hello"
)
assert
str
(
ob
)
==
"hello"
assert
"<System.String object at "
in
ob
.
__repr__
()
def
test_str_only
():
"""Test class implementing ToString() but not __repr__()"""
ob
=
ReprTest
.
Bar
()
assert
str
(
ob
)
==
"I implement ToString() but not __repr__()!"
assert
"<Python.Test.Bar object at "
in
ob
.
__repr__
()
def
test_hierarchy1
():
"""Test inheritance hierarchy with base & middle class implementing ToString"""
ob1
=
ReprTest
.
BazBase
()
assert
str
(
ob1
)
==
"Base class implementing ToString()!"
assert
"<Python.Test.BazBase object at "
in
ob1
.
__repr__
()
ob2
=
ReprTest
.
BazMiddle
()
assert
str
(
ob2
)
==
"Middle class implementing ToString()!"
assert
"<Python.Test.BazMiddle object at "
in
ob2
.
__repr__
()
ob3
=
ReprTest
.
Baz
()
assert
str
(
ob3
)
==
"Middle class implementing ToString()!"
assert
"<Python.Test.Baz object at "
in
ob3
.
__repr__
()
def
bad_tostring
():
"""Test ToString that can't be used by str()"""
ob
=
ReprTest
.
Quux
()
assert
str
(
ob
)
==
"Python.Test.ReprTest+Quux"
assert
"<Python.Test.Quux object at "
in
ob
.
__repr__
()
def
bad_repr
():
"""Test incorrect implementation of repr"""
ob1
=
ReprTest
.
QuuzBase
()
assert
str
(
ob1
)
==
"Python.Test.ReprTest+QuuzBase"
assert
"<Python.Test.QuuzBase object at "
in
ob
.
__repr__
()
ob2
=
ReprTest
.
Quuz
()
assert
str
(
ob2
)
==
"Python.Test.ReprTest+Quuz"
assert
"<Python.Test.Quuz object at "
in
ob
.
__repr__
()
ob3
=
ReprTest
.
Corge
()
with
pytest
.
raises
(
Exception
):
str
(
ob3
)
with
pytest
.
raises
(
Exception
):
ob3
.
__repr__
()
ob4
=
ReprTest
.
Grault
()
with
pytest
.
raises
(
Exception
):
str
(
ob4
)
with
pytest
.
raises
(
Exception
):
ob4
.
__repr__
()
Back
|
FazBrowse Home
|
New Git URL