Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
73914beb
Commit
73914beb
authored
Feb 20, 2018
by
Myles Hollowed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test coverage for build / usage / teardown
parent
010b34e8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
1 deletion
+78
-1
docs/examples/tutorial/rectangle_cpp/example_usage.py
docs/examples/tutorial/rectangle_cpp/example_usage.py
+0
-0
docs/examples/tutorial/rectangle_cpp/rect.pyx
docs/examples/tutorial/rectangle_cpp/rect.pyx
+25
-1
docs/examples/tutorial/rectangle_cpp/test.py
docs/examples/tutorial/rectangle_cpp/test.py
+53
-0
No files found.
docs/examples/tutorial/rectangle_cpp/
test_import
.py
→
docs/examples/tutorial/rectangle_cpp/
example_usage
.py
View file @
73914beb
File moved
docs/examples/tutorial/rectangle_cpp/rect.pyx
View file @
73914beb
...
...
@@ -36,11 +36,35 @@ cdef class PyRectangle:
@
property
def
x0
(
self
):
return
self
.
c_rect
.
x0
@
x0
.
setter
def
x0
(
self
,
x0
):
self
.
c_rect
.
x0
=
x0
# Attribute access
@
property
def
x1
(
self
):
return
self
.
c_rect
.
x1
@
x1
.
setter
def
x1
(
self
,
x1
):
self
.
c_rect
.
x1
=
x1
# Attribute access
@
property
def
y0
(
self
):
return
self
.
c_rect
.
y0
@
y0
.
setter
def
y0
(
self
,
y0
):
self
.
c_rect
.
y0
=
y0
# Attribute access
@
property
def
y1
(
self
):
return
self
.
c_rect
.
y1
@
y1
.
setter
def
y1
(
self
,
y1
):
self
.
c_rect
.
y1
=
y1
def
main
():
rec_ptr
=
new
Rectangle
(
1
,
2
,
3
,
4
)
# Instantiate a Rectangle object on the heap
...
...
docs/examples/tutorial/rectangle_cpp/test.py
0 → 100644
View file @
73914beb
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import
sys
import
unittest
import
os
class
TestRectangleCppExtension
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
directory_at_runtime
=
os
.
listdir
()
os
.
system
(
"python setup.py build_ext --inplace"
)
import
rect
self
.
x0
,
self
.
y0
,
self
.
x1
,
self
.
y1
=
1
,
2
,
3
,
4
self
.
rect_obj
=
rect
.
PyRectangle
(
self
.
x0
,
self
.
y0
,
self
.
x1
,
self
.
y1
)
def
test_get_area
(
self
):
width
=
self
.
x1
-
self
.
x0
height
=
self
.
y1
-
self
.
y0
area
=
width
*
height
self
.
assertEqual
(
self
.
rect_obj
.
get_area
(),
area
)
def
test_get_size
(
self
):
true_width
=
self
.
x1
-
self
.
x0
true_height
=
self
.
y1
-
self
.
y0
width
,
height
=
self
.
rect_obj
.
get_size
()
self
.
assertEqual
(
true_width
,
width
)
self
.
assertEqual
(
true_height
,
height
)
def
test_move
(
self
):
x0
,
x1
=
self
.
rect_obj
.
x0
,
self
.
rect_obj
.
x1
y0
,
y1
=
self
.
rect_obj
.
y0
,
self
.
rect_obj
.
y1
dx
,
dy
=
10
,
5
self
.
rect_obj
.
move
(
dx
,
dy
)
self
.
assertEqual
(
(
x0
+
dx
,
x1
+
dx
,
y0
+
dy
,
y1
+
dy
),
(
self
.
rect_obj
.
x0
,
self
.
rect_obj
.
x1
,
self
.
rect_obj
.
y0
,
self
.
rect_obj
.
y1
))
def
tearDown
(
self
):
files_to_remove
=
[
f
for
f
in
os
.
listdir
()
if
f
not
in
self
.
directory_at_runtime
]
for
f
in
files_to_remove
:
if
os
.
path
.
isfile
(
f
):
os
.
remove
(
f
)
elif
os
.
path
.
isdir
(
f
):
os
.
system
(
"rm -rf {}"
.
format
(
f
))
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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