瀏覽代碼

pytest green

Eric Charles 5 年之前
父節點
當前提交
4fde4a33ef
共有 5 個文件被更改,包括 53 次插入69 次删除
  1. 31 9
      jupyterlab/pytest_plugin.py
  2. 9 48
      jupyterlab/tests/test_build_api.py
  3. 9 10
      jupyterlab/tests/test_jupyterlab.py
  4. 3 1
      scripts/ci_script.sh
  5. 1 1
      setup.cfg

+ 31 - 9
jupyterlab/pytest_plugin.py

@@ -1,12 +1,17 @@
 import pytest, shutil, os
 
-from jupyterlab import LabApp
-from jupyterlab_server import LabConfig
+import urllib.parse
+
+from tornado.escape import url_escape
 
 from traitlets import Unicode
 
+from jupyterlab import LabApp
+from jupyterlab_server import LabConfig
 from jupyterlab_server.tests.utils import here
 from jupyterlab_server.app import LabServerApp
+from jupyter_server.utils import url_path_join
+
 
 def mkdir(tmp_path, *parts):
     path = tmp_path.joinpath(*parts)
@@ -20,9 +25,9 @@ schemas_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, 'schemas'))
 workspaces_dir = pytest.fixture(lambda tmp_path: mkdir(tmp_path, 'workspaces'))
 
 @pytest.fixture
-def make_lab_extension_app(root_dir, template_dir, app_settings_dir, user_settings_dir, schemas_dir, workspaces_dir):
-    def _make_lab_extension_app(**kwargs):
-        class TestLabServerApp(LabApp):
+def make_lab_app(root_dir, template_dir, app_settings_dir, user_settings_dir, schemas_dir, workspaces_dir):
+    def _make_lab_app(**kwargs):
+        class TestLabApp(LabApp):
             base_url = '/lab'
             default_url = Unicode('/',
                                 help='The default URL to redirect to from `/`')
@@ -36,7 +41,7 @@ def make_lab_extension_app(root_dir, template_dir, app_settings_dir, user_settin
                 schemas_dir = str(schemas_dir),
                 workspaces_dir = str(workspaces_dir),
             )
-        app = TestLabServerApp()
+        app = TestLabApp()
         return app
 
     # Create the index files.
@@ -73,11 +78,28 @@ def make_lab_extension_app(root_dir, template_dir, app_settings_dir, user_settin
 </html>
 """)
 
-    return _make_lab_extension_app
+    return _make_lab_app
 
 
 @pytest.fixture
-def labserverapp(serverapp, make_lab_extension_app):
-    app = make_lab_extension_app()
+def labapp(serverapp, make_lab_app):
+    app = make_lab_app()
     app.initialize(serverapp)
     return app
+
+
+@pytest.fixture
+def fetch_long(http_server_client, auth_header, base_url):
+    """fetch fixture that handles auth, base_url, and path"""
+    def client_fetch(*parts, headers={}, params={}, **kwargs):
+        # Handle URL strings
+        path_url = url_escape(url_path_join(base_url, *parts), plus=False)
+        params_url = urllib.parse.urlencode(params)
+        url = path_url + "?" + params_url
+        # Add auth keys to header
+        headers.update(auth_header)
+        # Make request.
+        return http_server_client.fetch(
+            url, headers=headers, request_timeout=50, **kwargs
+        )
+    return client_fetch

+ 9 - 48
jupyterlab/tests/test_build_api.py

@@ -2,17 +2,18 @@
 from tempfile import TemporaryDirectory
 import threading
 
+import asyncio
 import pytest
 import json
 import tornado
 
-import urllib.parse
-
-from tornado.escape import url_escape
-
 from jupyterlab.labapp import LabApp
 from jupyterlab_server.tests.utils import expected_http_error
-from jupyter_server.utils import url_path_join
+
+
+@pytest.fixture
+def build_api_tester(serverapp, labapp, fetch_long):
+    return BuildAPITester(labapp, fetch_long)
 
 
 class BuildAPITester():
@@ -39,35 +40,6 @@ class BuildAPITester():
         return await self._req('DELETE', '')
 
 
-@pytest.fixture
-def labapp(serverapp, make_lab_extension_app):
-    app = make_lab_extension_app()
-    app.initialize(serverapp)
-    return app
-
-
-@pytest.fixture
-def build_api_tester(serverapp, labapp, fetch_long):
-    return BuildAPITester(labapp, fetch_long)
-
-
-@pytest.fixture
-def fetch_long(http_server_client, auth_header, base_url):
-    """fetch fixture that handles auth, base_url, and path"""
-    def client_fetch(*parts, headers={}, params={}, **kwargs):
-        # Handle URL strings
-        path_url = url_escape(url_path_join(base_url, *parts), plus=False)
-        params_url = urllib.parse.urlencode(params)
-        url = path_url + "?" + params_url
-        # Add auth keys to header
-        headers.update(auth_header)
-        # Make request.
-        return http_server_client.fetch(
-            url, headers=headers, request_timeout=30, **kwargs
-        )
-    return client_fetch
-
-
 @pytest.mark.slow
 class TestBuildAPI:
 
@@ -109,16 +81,9 @@ class TestBuildAPI:
             res = r.body.decode()
         assert expected_http_error(e, 500)
 
-        async def build_thread():
-            with pytest.raises(tornado.httpclient.HTTPClientError) as e:
-                r = await build_api_tester.build()
-                res = r.body.decode()
-            assert expected_http_error(e, 500)
+        loop = asyncio.get_running_loop()
+        asyncio.ensure_future(build_api_tester.build(), loop=loop)
 
-        t1 = threading.Thread(target=build_thread)
-        t1.start()
-        """
-        TODO(@echarles) FIX ME
         while 1:
             r = await build_api_tester.getStatus()
             res = r.body.decode()
@@ -127,8 +92,4 @@ class TestBuildAPI:
                 break
 
         r = await build_api_tester.clear()
-        res = r.body.decode()
-        resp = json.loads(res)
-        assert resp.code == 204
-        """
-    
+        assert r.code == 204

+ 9 - 10
jupyterlab/tests/test_jupyterlab.py

@@ -520,16 +520,6 @@ class TestExtension(AppHandlerTest):
         for pkg in data['jupyterlab']['singletonPackages']:
             if pkg.startswith('@jupyterlab/'):
                 assert pkg in singletons
-    """
-    # TODO(@echarles) Fix and reenable this test.
-    def test_load_extension(self):
-        app = NotebookApp()
-        stderr = sys.stderr
-        sys.stderr = self.devnull
-        app.initialize(argv=[])
-        sys.stderr = stderr
-        load_jupyter_server_extension(app)
-    """
 
     def test_disable_extension(self):
         options = AppOptions(app_dir=self.tempdir())
@@ -788,3 +778,12 @@ class TestExtension(AppHandlerTest):
         with p1, p2:
             assert update_extension(None, all_=True) is True
         assert sorted(updated) == [self.pkg_names['extension'], self.pkg_names['mimeextension']]
+
+
+def test_load_extension(serverapp, make_lab_app):
+    app = make_lab_app()
+    stderr = sys.stderr
+#    sys.stderr = self.devnull
+    app.initialize(serverapp)
+    sys.stderr = stderr
+    load_jupyter_server_extension(app)

+ 3 - 1
scripts/ci_script.sh

@@ -13,7 +13,9 @@ fi
 
 if [[ $GROUP == python ]]; then
     # Run the python tests
-    py.test -v --junitxml=junit.xml
+#    py.test -v --junitxml=junit.xml
+#    Move the flags to setup.cfg
+    py.test
 fi
 
 

+ 1 - 1
setup.cfg

@@ -7,5 +7,5 @@ universal=1
 [tool:pytest]
 testpaths=jupyterlab/tests
 norecursedirs=node_modules .git _build
-addopts = --pdbcls=IPython.terminal.debugger:Pdb
+addopts = --pdbcls=IPython.terminal.debugger:Pdb -v --junitxml=junit.xml
 ignore=tests examples