예제 #1
0
def test_non_existing_module_raises_error_only_once():
    """Test that a non-existing module raises the ImportError only once"""
    non_existing = optional.optional_import("non_existing_module")
    try:
        non_existing.should_raise_error
    except ImportError:
        pass
    assert isinstance(non_existing.should_not_raise_error_anymore,
                      optional.SimpleMock)
예제 #2
0
파일: setup.py 프로젝트: priyatharsan/where
# Midgard imports
from midgard.config import config as mg_config
from midgard.dev import console

# Where imports
from where import pipelines
from where.lib import config
from where.lib import files
from where.lib import log
from where.lib.timer import timer
from where.lib import util

# Optional import of editor and seaborn, add dummy methods in case they are not installed
from midgard.dev import optional

editor = optional.optional_import("editor")


@timer(f"Finish {util.get_program_name()} in")
@util.no_traceback
def main():
    """Parse command line options and set up an Where analysis

    Do simple parsing of command line arguments. Set up config-files and show the configuration.
    """
    util.check_help_and_version(doc_module=__name__)

    # Start logging
    log.init()

    # Read command line options
예제 #3
0
"""

# Standard library imports
import shutil
import textwrap
from typing import Any, Optional

# Midgard imports
from midgard.dev import optional

# Use colorama for coloring in the console, graceful fallback to no color if colorama is not installed
_empty_string = optional.EmptyStringMock("_empty_string")
color = optional.optional_import("colorama",
                                 attrs=dict(init=lambda **_: None,
                                            Back=_empty_string,
                                            Fore=_empty_string,
                                            Style=_empty_string))
color.init(autoreset=True)


def lines() -> int:
    """The height of the console

    Returns:
        The heigth of the console in characters.
    """
    return shutil.get_terminal_size().lines


def columns() -> int:
예제 #4
0
def test_non_existing_module_with_attrs():
    """Test that a non-existing module still returns given attributes"""
    attrs = {"one": 1, "pi": 3.14, "numbers": [1, 2, 3]}
    non_existing = optional.optional_import("non_existing_module", attrs=attrs)
    for attr, value in attrs.items():
        assert getattr(non_existing, attr) is value
예제 #5
0
def test_non_existing_module_raises_error():
    """Test that a non-existing module raises an ImportError when used"""
    non_existing = optional.optional_import("non_existing_module")
    with pytest.raises(ImportError):
        non_existing.should_raise_error
예제 #6
0
def test_optional_import_of_non_existing_module():
    """Test that optional import of non-existing module returns a SimpleMock"""
    non_existing = optional.optional_import("non_existing_module")
    assert isinstance(non_existing, optional.SimpleMock)
예제 #7
0
def test_optional_import_of_existing_module():
    """Test that optional import of existing module returns module"""
    optional_sys = optional.optional_import("sys")
    assert optional_sys is sys.modules["sys"]
예제 #8
0
asdf

"""
# Standard library imports
import itertools

# WHERE imports
from where.lib import files
from where.lib import log
from where.lib import plugins
from where.reports import report

# Optional library imports
from midgard.dev import optional

kernelspec = optional.optional_import("jupyter_client.kernelspec")
nbformat = optional.optional_import("nbformat")
nbbase = optional.optional_import("nbformat.v4.nbbase")

CELL_PARSER = {
    "title": lambda txt: "# " + txt,
    "header": lambda txt: "## " + txt,
    "text": lambda txt: txt,
    "model": lambda txt: "### Model: " + txt.replace("_", " ").title(),
}


@plugins.register
def write_notebook(rundate, tech):
    kernelspec = _get_kernelspec("python3")
    cells = list(get_cells())