-
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
269 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
import os | ||
|
||
from jupyterlab_server.config import get_page_config | ||
|
||
|
||
def test_get_page_config(tmp_path): | ||
labext_path = [os.path.join(tmp_path, "ext")] | ||
settings_path = os.path.join(tmp_path, "settings") | ||
os.mkdir(settings_path) | ||
|
||
with open(os.path.join(settings_path, "page_config.json"), "w") as fid: | ||
data = dict(deferredExtensions=["foo"]) | ||
json.dump(data, fid) | ||
|
||
static_dir = os.path.join(tmp_path, "static") | ||
os.mkdir(static_dir) | ||
with open(os.path.join(static_dir, "package.json"), "w") as fid: | ||
data = dict(jupyterlab=dict(extensionMetadata=dict(foo=dict(disabledExtensions=["bar"])))) | ||
json.dump(data, fid) | ||
|
||
config = get_page_config(labext_path, settings_path) | ||
assert config == { | ||
"deferredExtensions": ["foo"], | ||
"federated_extensions": [], | ||
"disabledExtensions": ["bar"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
import json | ||
|
||
import requests_mock | ||
|
||
from jupyterlab_server.listings_handler import ListingsHandler, fetch_listings | ||
from jupyterlab_server.test_utils import validate_request | ||
|
||
|
||
async def test_get_listing(jp_fetch, labserverapp): | ||
url = r"lab/api/listings/@jupyterlab/extensionmanager-extension/listings.json" | ||
r = await jp_fetch(*url.split("/")) | ||
validate_request(r) | ||
|
||
|
||
def test_fetch_listings(): | ||
ListingsHandler.allowed_extensions_uris = ["http://foo"] | ||
ListingsHandler.blocked_extensions_uris = ["http://bar"] | ||
with requests_mock.Mocker() as m: | ||
data = dict(blocked_extensions=[]) | ||
m.get("http://bar", text=json.dumps(data)) | ||
data = dict(allowed_extensions=[]) | ||
m.get("http://foo", text=json.dumps(data)) | ||
fetch_listings(None) | ||
ListingsHandler.allowed_extensions_uris = [] | ||
ListingsHandler.blocked_extensions_uris = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import os | ||
import sys | ||
import warnings | ||
|
||
import pytest | ||
|
||
from jupyterlab_server.process import Process, WatchHelper, which | ||
from jupyterlab_server.process_app import ProcessApp | ||
|
||
|
||
def test_which(): | ||
assert which("python") | ||
|
||
|
||
async def test_process(): | ||
p = Process([sys.executable, "--version"]) | ||
p.get_log().info("test") | ||
assert p.wait() == 0 | ||
|
||
p = Process([sys.executable, "--version"]) | ||
p.get_log().info("test") | ||
assert await p.wait_async() == 0 | ||
assert p.terminate() == 0 | ||
|
||
|
||
@pytest.mark.skipif(os.name == "nt", reason="Fails on Windows") | ||
async def test_watch_helper(): | ||
helper = WatchHelper([sys.executable, "-i"], ">>>") | ||
helper.terminate() | ||
helper.wait() | ||
|
||
|
||
def test_process_app(): | ||
class TestApp(ProcessApp): | ||
name = "tests" | ||
|
||
app = TestApp() | ||
app.initialize_server([]) | ||
try: | ||
app.initialize() | ||
with pytest.raises(SystemExit): | ||
app.start() | ||
# Kandle exception on older versions of server. | ||
except Exception as e: | ||
# Convert to warning so the test will pass on min version test. | ||
warnings.warn(str(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,33 @@ | ||
from unittest.mock import Mock | ||
|
||
from tornado.httpserver import HTTPRequest | ||
from tornado.web import Application | ||
|
||
from jupyterlab_server.test_utils import validate_request | ||
from jupyterlab_server.themes_handler import ThemesHandler | ||
|
||
|
||
async def test_get_theme(jp_fetch, labserverapp): | ||
r = await jp_fetch("lab", "api", "themes", "@jupyterlab", "foo", "index.css") | ||
validate_request(r) | ||
|
||
|
||
def test_themes_handler(tmp_path): | ||
app = Application() | ||
request = HTTPRequest(connection=Mock()) | ||
data_path = f"{tmp_path}/test.txt" | ||
with open(data_path, "w") as fid: | ||
fid.write("hi") | ||
handler = ThemesHandler(app, request, path=str(tmp_path)) | ||
handler.absolute_path = data_path | ||
handler.get_content_size() | ||
handler.get_content("test.txt") | ||
|
||
css_path = f"{tmp_path}/test.css" | ||
with open(css_path, "w") as fid: | ||
fid.write("url('./foo.css')") | ||
handler.absolute_path = css_path | ||
handler.path = "/" | ||
handler.themes_url = "foo" | ||
content = handler.get_content(css_path) | ||
assert content == b"url('foo/./foo.css')" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import sys | ||
|
||
from jupyterlab_server.translation_utils import ( | ||
TranslationBundle, | ||
_main, | ||
get_installed_packages_locale, | ||
get_language_packs, | ||
translator, | ||
) | ||
|
||
|
||
def test_transutils_main(): | ||
sys.argv = ["", "get_language_packs"] | ||
_main() | ||
sys.argv = [""] | ||
|
||
|
||
def test_get_installed_packages_locale(jp_environ): | ||
get_installed_packages_locale("es_co") | ||
|
||
|
||
def test_get_language_packs(jp_environ): | ||
get_language_packs("es_co") | ||
|
||
|
||
def test_translation_bundle(): | ||
bundle = TranslationBundle("foo", "bar") | ||
bundle.update_locale("fizz") | ||
bundle.gettext("hi") | ||
bundle.ngettext("hi", "his", 1) | ||
bundle.npgettext("foo", "bar", "bars", 2) | ||
bundle.pgettext("foo", "bar") | ||
|
||
|
||
def test_translator(): | ||
t = translator() | ||
t.load("foo") | ||
t.normalize_domain("bar") | ||
t.set_locale("fizz") | ||
t.translate_schema({}) |
Oops, something went wrong.