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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Gwenaël Samain
cython
Commits
00ef9ff2
Commit
00ef9ff2
authored
May 03, 2018
by
Robert Bradshaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for CyCache.
parent
175870ed
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
0 deletions
+70
-0
Cython/Build/Tests/TestCyCache.py
Cython/Build/Tests/TestCyCache.py
+65
-0
Cython/Utils.py
Cython/Utils.py
+5
-0
No files found.
Cython/Build/Tests/TestCyCache.py
0 → 100644
View file @
00ef9ff2
import
glob
import
gzip
import
os
import
tempfile
import
Cython.Build.Dependencies
import
Cython.Utils
#from Cython.Build.Dependencies import cythonize
from
Cython.TestUtils
import
CythonTest
class
TestInline
(
CythonTest
):
def
setUp
(
self
):
CythonTest
.
setUp
(
self
)
self
.
temp_dir
=
tempfile
.
mkdtemp
(
prefix
=
'cycache-test'
,
dir
=
'TEST_TMP'
if
os
.
path
.
isdir
(
'TEST_TMP'
)
else
None
)
self
.
src_dir
=
tempfile
.
mkdtemp
(
prefix
=
'src'
,
dir
=
self
.
temp_dir
)
self
.
cache_dir
=
tempfile
.
mkdtemp
(
prefix
=
'cache'
,
dir
=
self
.
temp_dir
)
def
cache_files
(
self
,
file_glob
):
return
glob
.
glob
(
os
.
path
.
join
(
self
.
cache_dir
,
file_glob
))
def
fresh_cythonize
(
self
,
*
args
,
**
kwargs
):
Cython
.
Utils
.
clear_function_caches
()
Cython
.
Build
.
Dependencies
.
_dep_tree
=
None
# discard method caches
Cython
.
Build
.
Dependencies
.
cythonize
(
*
args
,
**
kwargs
)
def
test_cycache_switch
(
self
):
content1
=
'value = 1
\
n
'
content2
=
'value = 2
\
n
'
a_pyx
=
os
.
path
.
join
(
self
.
src_dir
,
'a.pyx'
)
a_c
=
a_pyx
[:
-
4
]
+
'.c'
open
(
a_pyx
,
'w'
).
write
(
content1
)
self
.
fresh_cythonize
(
a_pyx
,
cache
=
self
.
cache_dir
)
self
.
fresh_cythonize
(
a_pyx
,
cache
=
self
.
cache_dir
)
self
.
assertEqual
(
1
,
len
(
self
.
cache_files
(
'a.c*'
)))
a_contents1
=
open
(
a_c
).
read
()
open
(
a_pyx
,
'w'
).
write
(
content2
)
self
.
fresh_cythonize
(
a_pyx
,
cache
=
self
.
cache_dir
)
a_contents2
=
open
(
a_c
).
read
()
self
.
assertNotEqual
(
a_contents1
,
a_contents2
)
self
.
assertEqual
(
2
,
len
(
self
.
cache_files
(
'a.c*'
)))
open
(
a_pyx
,
'w'
).
write
(
content1
)
self
.
fresh_cythonize
(
a_pyx
,
cache
=
self
.
cache_dir
)
self
.
assertEqual
(
2
,
len
(
self
.
cache_files
(
'a.c*'
)))
a_contents
=
open
(
a_c
).
read
()
self
.
assertEqual
(
a_contents
,
a_contents1
)
def
test_cycache_uses_cache
(
self
):
a_pyx
=
os
.
path
.
join
(
self
.
src_dir
,
'a.pyx'
)
a_c
=
a_pyx
[:
-
4
]
+
'.c'
open
(
a_pyx
,
'w'
).
write
(
"pass"
)
self
.
fresh_cythonize
(
a_pyx
,
cache
=
self
.
cache_dir
)
a_cache
=
os
.
path
.
join
(
self
.
cache_dir
,
os
.
listdir
(
self
.
cache_dir
)[
0
])
gzip
.
GzipFile
(
a_cache
,
'wb'
).
write
(
'fake stuff'
)
os
.
unlink
(
a_c
)
self
.
fresh_cythonize
(
a_pyx
,
cache
=
self
.
cache_dir
)
a_contents
=
open
(
a_c
).
read
()
self
.
assertEqual
(
a_contents
,
'fake stuff'
)
Cython/Utils.py
View file @
00ef9ff2
...
...
@@ -20,9 +20,14 @@ from contextlib import contextmanager
modification_time
=
os
.
path
.
getmtime
_function_caches
=
[]
def
clear_function_caches
():
for
cache
in
_function_caches
:
cache
.
clear
()
def
cached_function
(
f
):
cache
=
{}
_function_caches
.
append
(
cache
)
uncomputed
=
object
()
def
wrapper
(
*
args
):
res
=
cache
.
get
(
args
,
uncomputed
)
...
...
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