def test_nbinit_imports(): """Test custom imports.""" ns_dict = {} init_notebook( namespace=ns_dict, extra_imports=["pathlib", "datetime, time", "datetime, timedelta, tdelta"], def_imports="nb", verbose=True, ) print(ns_dict.keys()) check.is_in("pathlib", ns_dict) check.is_in("time", ns_dict) check.is_in("tdelta", ns_dict) check.is_in("np", ns_dict) check.equal(timedelta, ns_dict["tdelta"]) check.equal(datetime.time, ns_dict["time"])
def test_nbinit_no_params(): """Test init_notebook defaults.""" ns_dict = {} init_notebook(namespace=ns_dict, def_imports="nb") check.is_in("pd", ns_dict) check.is_in("get_ipython", ns_dict) check.is_in("Path", ns_dict) check.is_in("np", ns_dict) # Note - msticpy imports throw when exec'd from unit test # e.g. check.is_in("QueryProvider", ns_dict) fails check.is_in("WIDGET_DEFAULTS", ns_dict) check.equal(ns_dict["pd"].__name__, "pandas") check.equal(ns_dict["np"].__name__, "numpy") check.equal(pd.get_option("display.max_columns"), 50)
def test_install_pkgs(): """Test installing and importing a package.""" test_pkg = "pip-install-test" # Uninstall package if it is already there subprocess.run(["pip", "uninstall", "-y", test_pkg], check=True) # nosec ns_dict = {} init_notebook( namespace=ns_dict, additional_packages=[test_pkg], extra_imports=["pip_install_test"], def_imports="nb", ) for name, obj in ns_dict.items(): print(name, type(obj)) check.is_in("pip_install_test", ns_dict) subprocess.run(["pip", "uninstall", "-y", test_pkg], check=True) # nosec