Commits

mattip committed b488d6e

only warn if 'import numpy' called before 'import numpypy', try to test but 2nd test fails obscurely after 'import numpy' called in 1st test

Comments (0)

Files changed (3)

 
 
 
-TODO list by matti
+TODO list by mattip
 ===================
 
 - test array.nonzero()

lib_pypy/numpy.py

 import warnings
-
-warnings.warn(
-    "The 'numpy' module of PyPy is in-development and not complete. "
-    "To avoid this warning, write 'import numpypy as numpy'. ")
+import sys
+if 'numpypy' not in sys.modules:
+    warnings.warn(
+        "The 'numpy' module of PyPy is in-development and not complete. "
+        "To avoid this warning, write 'import numpypy as numpy'. ",
+        UserWarning) # XXX is this the best warning type?
 
 from numpypy import *
 

pypy/module/test_lib_pypy/numpypy/test_numpy.py

+from pypy.conftest import option
+import py, sys
 from pypy.module.micronumpy.test.test_base import BaseNumpyAppTest
 
-class AppTestNumpy(BaseNumpyAppTest):
+class AppTestNumpyImport1(object):
     spaceconfig = dict(usemodules=['micronumpy'])
 
-    def test_imports(self):
-        try:
-            import numpy   # fails if 'numpypy' was not imported so far
-        except ImportError:
-            pass
-        import numpypy
-        import numpy     # works after 'numpypy' has been imported
+    @classmethod
+    def setup_class(cls):
+        if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
+            py.test.skip("pypy only test")
 
+    def test_imports_no_warning(self):
+        from warnings import catch_warnings
+        with catch_warnings(record=True) as w:
+            import numpypy
+            import numpy
+            assert len(w) == 0
+            import numpy
+            assert len(w) == 0
+
+class AppTestNumpyImport2(object):
+    spaceconfig = dict(usemodules=['micronumpy'])
+
+    @classmethod
+    def setup_class(cls):
+        if option.runappdirect and '__pypy__' not in sys.builtin_module_names:
+            py.test.skip("pypy only test")
+
+    def test_imports_with_warning(self):
+        import sys
+        from warnings import catch_warnings
+        # XXX why are numpypy and numpy modules already imported?
+        print sys.modules.keys()
+
+        with catch_warnings(record=True) as w:
+            import numpy
+            msg = w[0].message
+            assert msg.message.startswith(
+                "The 'numpy' module of PyPy is in-development")
+            import numpy
+            assert len(w) == 1
+
+class AppTestNumpy(BaseNumpyAppTest):
     def test_min_max_after_import(self):
         import __builtin__
         from __builtin__ import *
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.