Author: Matti Picus <[email protected]>
Branch: 
Changeset: r70329:31a0923cb46d
Date: 2014-03-29 22:50 +0300
http://bitbucket.org/pypy/pypy/changeset/31a0923cb46d/

Log:    hash _testcapi.c file contents, and add test

diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py
--- a/lib_pypy/_testcapi.py
+++ b/lib_pypy/_testcapi.py
@@ -6,8 +6,10 @@
     raise ImportError("No module named '_testcapi'")
 
 def get_hashed_dir(cfile):
+    with open(cfile,'r') as fid:
+        content = fid.read()
     # from cffi's Verifier()
-    key = '\x00'.join([sys.version[:3], cfile])
+    key = '\x00'.join([sys.version[:3], content])
     if sys.version_info >= (3,):
         key = key.encode('utf-8')
     k1 = hex(binascii.crc32(key[0::2]) & 0xffffffff)
@@ -20,7 +22,8 @@
     return output_dir 
 
 cfile = '_testcapimodule.c'
-output_dir = get_hashed_dir(cfile)
+thisdir = os.path.dirname(__file__)
+output_dir = get_hashed_dir(os.path.join(thisdir, cfile))
 
 try:
     fp, filename, description = imp.find_module('_testcapi', path=[output_dir])
diff --git a/pypy/module/test_lib_pypy/test_testcapi.py 
b/pypy/module/test_lib_pypy/test_testcapi.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/test_testcapi.py
@@ -0,0 +1,17 @@
+import py, sys
+
+if '__pypy__' not in sys.builtin_module_names:
+    py.test.skip('pypy only test')
+
+from lib_pypy import _testcapi #this should insure _testcapi is built
+
+def test_get_hashed_dir():
+    import sys
+    script = '''import _testcapi
+            assert 'get_hashed_dir' in dir(_testcapi)
+            return 0
+            '''
+    output = py.process.cmdexec('''"%s" -c "%s"''' %
+                             (sys.executable, script))
+    assert output == ''
+            
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to