[pypy-svn] r77800 - pypy/trunk/pypy/rlib/test

arigo at codespeak.net arigo at codespeak.net
Mon Oct 11 17:58:25 CEST 2010


Author: arigo
Date: Mon Oct 11 17:58:23 2010
New Revision: 77800

Modified:
   pypy/trunk/pypy/rlib/test/test_rsocket.py
Log:
Add a (failing) test that _rsocket_rffi.py is really importable on
platforms where AF_NETLINK or AF_PACKET are not defined.


Modified: pypy/trunk/pypy/rlib/test/test_rsocket.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rsocket.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_rsocket.py	Mon Oct 11 17:58:23 2010
@@ -437,3 +437,27 @@
             foo = self.serv.accept()
         py.test.raises(SocketError, raise_error)
 
+def test_cond_includes():
+    import re
+    # Test that _rsocket_rffi is importable even on platforms where
+    # AF_PACKET or AF_NETLINK is not defined.
+    for cond in ['AF_PACKET', 'AF_NETLINK']:
+        print cond
+        from pypy.rlib import _rsocket_rffi
+        srcfile = _rsocket_rffi.__file__
+        if srcfile.lower().endswith('c') or srcfile.lower().endswith('o'):
+            srcfile = srcfile[:-1]      # .pyc => .py
+        assert srcfile.lower().endswith('.py')
+        sourcelines = open(srcfile, 'rb').read().splitlines()
+        found = False
+        for i, line in enumerate(sourcelines):
+            line2 = re.sub(r"(\s*COND_HEADER\s*=)",
+                          r"\1'#undef %s\\n'+" % cond,
+                          line)
+            if line2 != line:
+                found = True
+                sourcelines[i] = line2
+        assert found
+        d = {}
+        sourcelines.append('')
+        exec '\n'.join(sourcelines) in d



More information about the Pypy-commit mailing list