def test_build(self): install_extension(pjoin(here, 'mockextension')) build() entry = pjoin(_get_build_dir(), 'index.out.js') with open(entry) as fid: data = fid.read() assert '@jupyterlab/python-tests' in data
def install_labextension(): print("Trying to install pyforest labextension...") try: from jupyterlab import commands except ImportError: print( "Could not install pyforest Jupyter Lab extension because Jupyter Lab is not available" ) return from pathlib import Path dir = Path(__file__).parent should_build = commands.install_extension(str(dir)) print("Successfully installed pyforest Jupyter Lab labextension") if should_build: print("") print("Starting JupyterLab build") commands.build() print("Successfully built JupyterLab") print("") print("Please reload your Jupyter Lab browser window")
def test_should_build(self): assert not should_build()[0] install_extension(self.source_dir) assert should_build()[0] build() assert not should_build()[0] uninstall_extension('@jupyterlab/python-tests') assert should_build()[0]
def install_cmd(_args, _rest): """install command""" files = pkg_resources.resource_listdir(RESOURCE_NAME, 'labextension') versions = [version_tuple(PACKAGE_RE.sub(r'\1', x)) for x in files] latest = max(versions) latest_file = PACKAGE_NAME.format('.'.join(map(str, latest))) resource_file = pkg_resources.resource_filename( RESOURCE_NAME, 'labextension/' + latest_file) print('Installing labextension') install_extension(resource_file) build()
def test_build_custom_minimal_core_config(self): default_config = CoreConfig() core_config = CoreConfig() core_config.clear_packages() logger = logging.getLogger('jupyterlab_test_logger') logger.setLevel('DEBUG') app_dir = self.tempdir() options = AppOptions( app_dir=app_dir, core_config=core_config, logger=logger, use_sys_dir=False, ) extensions = ( '@jupyterlab/application-extension', '@jupyterlab/apputils-extension', ) singletons = ( "@jupyterlab/application", "@jupyterlab/apputils", "@jupyterlab/coreutils", "@jupyterlab/services", ) for name in extensions: semver = default_config.extensions[name] core_config.add(name, semver, extension=True) for name in singletons: semver = default_config.singletons[name] core_config.add(name, semver) assert install_extension(self.mock_extension, app_options=options) is True build(app_options=options) # check static directory. entry = pjoin(app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data pkg = pjoin(app_dir, 'static', 'package.json') with open(pkg) as fid: data = json.load(fid) assert sorted(data['jupyterlab']['extensions'].keys()) == [ '@jupyterlab/application-extension', '@jupyterlab/apputils-extension', '@jupyterlab/mock-extension', ] assert data['jupyterlab']['mimeExtensions'] == {} for pkg in data['jupyterlab']['singletonPackages']: if pkg.startswith('@jupyterlab/'): assert pkg in singletons
def test_build(self): install_extension(self.source_dir) build() # check staging directory. entry = pjoin(self.app_dir, 'staging', 'build', 'index.out.js') with open(entry) as fid: data = fid.read() assert '@jupyterlab/python-tests' in data # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert '@jupyterlab/python-tests' in data
def test_build(self): assert install_extension(self.mock_extension) is True build() # check staging directory. entry = pjoin(self.app_dir, "staging", "build", "index.out.js") with open(entry) as fid: data = fid.read() assert self.pkg_names["extension"] in data # check static directory. entry = pjoin(self.app_dir, "static", "index.out.js") with open(entry) as fid: data = fid.read() assert self.pkg_names["extension"] in data
def test_build(self): install_extension(self.mock_extension) build() # check staging directory. entry = pjoin(self.app_dir, 'staging', 'build', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data
def test_build(self): assert install_extension(self.mock_extension) is True build() # check staging directory. entry = pjoin(self.app_dir, 'staging', 'build', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data
def test_build_custom(self): install_extension(self.source_dir) build(name='foo', version='1.0') # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert '@jupyterlab/python-tests' in data pkg = pjoin(self.app_dir, 'static', 'package.json') with open(pkg) as fid: data = json.load(fid) assert data['jupyterlab']['name'] == 'foo' assert data['jupyterlab']['version'] == '1.0'
def test_build_custom(self): install_extension(self.mock_extension) build(name='foo', version='1.0') # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data pkg = pjoin(self.app_dir, 'static', 'package.json') with open(pkg) as fid: data = json.load(fid) assert data['jupyterlab']['name'] == 'foo' assert data['jupyterlab']['version'] == '1.0'
def test_uninstall_core_extension(self): uninstall_extension('@jupyterlab/console-extension') app_dir = self.app_dir build(app_dir) with open(pjoin(app_dir, 'staging', 'package.json')) as fid: data = json.load(fid) extensions = data['jupyterlab']['extensions'] assert '@jupyterlab/console-extension' not in extensions install_extension('@jupyterlab/console-extension') build(app_dir) with open(pjoin(app_dir, 'staging', 'package.json')) as fid: data = json.load(fid) extensions = data['jupyterlab']['extensions'] assert '@jupyterlab/console-extension' in extensions
def test_build_custom(self): assert install_extension(self.mock_extension) is True build(name='foo', version='1.0', public_url='bar') # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data pkg = pjoin(self.app_dir, 'static', 'package.json') with open(pkg) as fid: data = json.load(fid) assert data['jupyterlab']['name'] == 'foo' assert data['jupyterlab']['version'] == '1.0' assert data['jupyterlab']['publicUrl'] == 'bar'
def test_build_splice_packages(self): app_options = AppOptions(splice_source=True) assert install_extension(self.mock_extension) is True build(app_options=app_options) assert '-spliced' in get_app_version(app_options) # check staging directory. entry = pjoin(self.app_dir, 'staging', 'build', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data # check static directory. entry = pjoin(self.app_dir, 'static', 'index.out.js') with open(entry) as fid: data = fid.read() assert self.pkg_names['extension'] in data
def test_build_custom(self): assert install_extension(self.mock_extension) is True build(name="foo", version="1.0", static_url="bar") # check static directory. entry = pjoin(self.app_dir, "static", "index.out.js") with open(entry) as fid: data = fid.read() assert self.pkg_names["extension"] in data pkg = pjoin(self.app_dir, "static", "package.json") with open(pkg) as fid: data = json.load(fid) assert data["jupyterlab"]["name"] == "foo" assert data["jupyterlab"]["version"] == "1.0" assert data["jupyterlab"]["staticUrl"] == "bar"
def test_uninstall_core_extension(self): assert uninstall_extension('@jupyterlab/console-extension') is True app_dir = self.app_dir build(app_dir) with open(pjoin(app_dir, 'staging', 'package.json')) as fid: data = json.load(fid) extensions = data['jupyterlab']['extensions'] assert '@jupyterlab/console-extension' not in extensions assert not check_extension('@jupyterlab/console-extension') assert install_extension('@jupyterlab/console-extension') is True build(app_dir) with open(pjoin(app_dir, 'staging', 'package.json')) as fid: data = json.load(fid) extensions = data['jupyterlab']['extensions'] assert '@jupyterlab/console-extension' in extensions assert check_extension('@jupyterlab/console-extension')
def test_uninstall_core_extension(self): assert uninstall_extension("@jupyterlab/console-extension") is True app_dir = self.app_dir build() with open(pjoin(app_dir, "staging", "package.json")) as fid: data = json.load(fid) extensions = data["jupyterlab"]["extensions"] assert "@jupyterlab/console-extension" not in extensions assert not check_extension("@jupyterlab/console-extension") assert install_extension("@jupyterlab/console-extension") is True build() with open(pjoin(app_dir, "staging", "package.json")) as fid: data = json.load(fid) extensions = data["jupyterlab"]["extensions"] assert "@jupyterlab/console-extension" in extensions assert check_extension("@jupyterlab/console-extension")
def test_build_check(self): # Do the initial build. assert build_check()[0] link_package(self.mock_extension) link_package(self.mock_package) build() assert not build_check()[0] # Check installed extensions. install_extension(self.mock_mimeextension) assert build_check()[0] uninstall_extension('@jupyterlab/mime-extension-test') assert not build_check()[0] # Check linked extensions. pkg_path = pjoin(self.mock_extension, 'package.json') with open(pkg_path) as fid: data = json.load(fid) with open(pkg_path, 'rb') as fid: orig = fid.read() data['foo'] = 'bar' with open(pkg_path, 'w') as fid: json.dump(data, fid) assert build_check()[0] assert build_check()[0] with open(pkg_path, 'wb') as fid: fid.write(orig) assert not build_check()[0] # Check linked packages. pkg_path = pjoin(self.mock_package, 'package.json') with open(pkg_path) as fid: data = json.load(fid) with open(pkg_path, 'rb') as fid: orig = fid.read() data['foo'] = 'bar' with open(pkg_path, 'w') as fid: json.dump(data, fid) assert build_check()[0] assert build_check()[0] with open(pkg_path, 'wb') as fid: fid.write(orig) assert not build_check()[0]
def test_build_check(self): # Do the initial build. assert build_check() install_extension(self.mock_extension) link_package(self.mock_package) build() assert not build_check() # Check installed extensions. install_extension(self.mock_mimeextension) assert build_check() uninstall_extension(self.pkg_names['mimeextension']) assert not build_check() # Check local extensions. pkg_path = pjoin(self.mock_extension, 'package.json') with open(pkg_path) as fid: data = json.load(fid) with open(pkg_path, 'rb') as fid: orig = fid.read() data['foo'] = 'bar' with open(pkg_path, 'w') as fid: json.dump(data, fid) assert build_check() assert build_check() with open(pkg_path, 'wb') as fid: fid.write(orig) assert not build_check() # Check linked packages. pkg_path = pjoin(self.mock_package, 'index.js') with open(pkg_path, 'rb') as fid: orig = fid.read() with open(pkg_path, 'wb') as fid: fid.write(orig + b'\nconsole.log("hello");') assert build_check() assert build_check() with open(pkg_path, 'wb') as fid: fid.write(orig) assert not build_check()
def test_build_check(self): # Do the initial build. assert build_check() assert install_extension(self.mock_extension) is True assert link_package(self.mock_package) is True build() assert not build_check() # Check installed extensions. assert install_extension(self.mock_mimeextension) is True assert build_check() assert uninstall_extension(self.pkg_names["mimeextension"]) is True assert not build_check() # Check local extensions. pkg_path = pjoin(self.mock_extension, "package.json") with open(pkg_path) as fid: data = json.load(fid) with open(pkg_path, "rb") as fid: orig = fid.read() data["foo"] = "bar" with open(pkg_path, "w") as fid: json.dump(data, fid) assert build_check() assert build_check() with open(pkg_path, "wb") as fid: fid.write(orig) assert not build_check() # Check linked packages. pkg_path = pjoin(self.mock_package, "index.js") with open(pkg_path, "rb") as fid: orig = fid.read() with open(pkg_path, "wb") as fid: fid.write(orig + b'\nconsole.log("hello");') assert build_check() assert build_check() with open(pkg_path, "wb") as fid: fid.write(orig) assert not build_check()
def test_build_check(self): # Do the initial build. assert build_check() assert install_extension(self.mock_extension) is True assert link_package(self.mock_package) is True build() assert not build_check() # Check installed extensions. assert install_extension(self.mock_mimeextension) is True assert build_check() assert uninstall_extension(self.pkg_names['mimeextension']) is True assert not build_check() # Check local extensions. pkg_path = pjoin(self.mock_extension, 'package.json') with open(pkg_path) as fid: data = json.load(fid) with open(pkg_path, 'rb') as fid: orig = fid.read() data['foo'] = 'bar' with open(pkg_path, 'w') as fid: json.dump(data, fid) assert build_check() assert build_check() with open(pkg_path, 'wb') as fid: fid.write(orig) assert not build_check() # Check linked packages. pkg_path = pjoin(self.mock_package, 'index.js') with open(pkg_path, 'rb') as fid: orig = fid.read() with open(pkg_path, 'wb') as fid: fid.write(orig + b'\nconsole.log("hello");') assert build_check() assert build_check() with open(pkg_path, 'wb') as fid: fid.write(orig) assert not build_check()
def setup_class(cls): super(SettingsAPITest, cls).setup_class() build()