Ejemplo n.º 1
0
def init() -> ExitCodes:
    """init ixian

    Finds the ixian config module for the projects and initializes itself
    using the `setup` function found inside ixian.py.

    :return:
    """
    init_logging()

    try:
        ixian_module = import_ixian()
    except FileNotFoundError as e:
        logger.error(str(e))
        return ExitCodes.ERROR_NO_IXIAN_PY

    try:
        module_init = ixian_module.init
    except AttributeError:
        logger.error("init() was not found within ixian.py")
        return ExitCodes.ERROR_NO_INIT

    # init module and return all globals.
    logger.debug("Ixian v0.0.1")
    load_module("ixian.modules.core")
    module_init()

    return ExitCodes.SUCCESS
Ejemplo n.º 2
0
def mock_environment(temp_builder):
    """
    Initialize ixian with a tests environment
    """
    CONFIG.PROJECT_NAME = "unittests"
    CONFIG.LOGGING_CONFIG = {
        "version": 1,
        "formatters": {
            "stdout": {
                "class": "logging.Formatter",
                "format": "%(message)s",
            },  # noqa:E231
        },
        "handlers": {
            "stdout": {
                "class": "logging.StreamHandler",
                "formatter": "stdout",
                "level": "DEBUG",
            }  # noqa:E231
        },
        "root": {
            "level": "DEBUG",
            "handlers": ["stdout"]
        },
    }
    load_module("ixian.modules.core")
    yield
    # Clear reference to runner else subsequent loads won't properly setup the tasks
    # TODO: this needs to be cleaned up when task loading is simplified
    for runner in TASKS.values():
        if runner.task:
            type(runner.task).__task__ = None
    TASKS.clear()
    MODULES.clear()
Ejemplo n.º 3
0
    def test_load_module_no_tasks(self, mock_environment):
        """Module tasks are not required"""
        from ixian.tests.mocks.modules.empty_tasks_module import OPTIONS
        from ixian.tests.mocks.modules.empty_tasks_module.config import TestConfig

        load_module("ixian.tests.mocks.modules.empty_tasks_module")
        assert "EMPTY_TASKS_MODULE" in MODULES
        assert MODULES["EMPTY_TASKS_MODULE"] == OPTIONS
        assert type(CONFIG.EMPTY_TASKS_MODULE) == TestConfig
Ejemplo n.º 4
0
    def test_load_module_no_config(self):
        """Config option is not required"""
        from ixian.tests.mocks.modules.no_config import OPTIONS
        from ixian.tests.mocks.modules.no_config.tasks import TestTask

        load_module("ixian.tests.mocks.modules.no_config")
        assert resolve_task("test_task") is TestTask.__task__
        assert "NO_CONFIG" in MODULES
        assert MODULES["NO_CONFIG"] == OPTIONS
Ejemplo n.º 5
0
    def test_load_module(self):
        """Successfully load a module"""
        from ixian.tests.mocks.modules.functional import OPTIONS
        from ixian.tests.mocks.modules.functional.tasks import TestTask
        from ixian.tests.mocks.modules.functional.config import TestConfig

        load_module("ixian.tests.mocks.modules.functional")
        assert resolve_task("test_task") is TestTask.__task__
        assert "FUNCTIONAL" in MODULES
        assert MODULES["FUNCTIONAL"] == OPTIONS
        assert type(CONFIG.FUNCTIONAL) == TestConfig
Ejemplo n.º 6
0
 def test_task_module_does_not_exist(self):
     """Module tasks path should exist"""
     with pytest.raises(ModuleNotFoundError):
         load_module("ixian.tests.mocks.modules.task_path_does_not_exist")
Ejemplo n.º 7
0
 def test_load_module_config_path_does_not_exist(self):
     """Config path should exist"""
     with pytest.raises(ModuleNotFoundError):
         load_module("ixian.tests.mocks.modules.config_path_does_not_exist")
Ejemplo n.º 8
0
 def test_load_module_config_path_bad_format(self):
     """Config path should be a valid classpath"""
     with pytest.raises(InvalidClassPath):
         load_module("ixian.tests.mocks.modules.config_path_invalid")
Ejemplo n.º 9
0
 def test_load_module_no_options(self):
     """Module options are required"""
     with pytest.raises(ModuleLoadError, match=".*: missing OPTIONS"):
         load_module("ixian.tests.mocks.modules.no_options")
Ejemplo n.º 10
0
 def test_load_module_invalid_path(self):
     """If module path is bad it can't be loaded"""
     with pytest.raises(ModuleNotFoundError):
         load_module("ixian.tests.mocks.modules.does.not.exist")
     with pytest.raises(ModuleNotFoundError):
         load_module("ixian.tests.mocks.modules.invalid-module-name")
Ejemplo n.º 11
0
 def test_load_module_no_name(self):
     """Module name is required"""
     with pytest.raises(ModuleLoadError,
                        match=".*: OPTIONS is missing 'name'"):
         load_module("ixian.tests.mocks.modules.no_name")
Ejemplo n.º 12
0
 def test_task_load_error(self):
     """An error loading a modules task is fatal"""
     with pytest.raises(Exception, match="Intentional Exception"):
         load_module("ixian.tests.mocks.modules.task_load_error")
Ejemplo n.º 13
0
def init():
    """Initialize with test config"""
    CONFIG.PROJECT_NAME = "unittests"
    load_module("ixian.modules.core")
    load_module("ixian.tests.mocks.modules.functional")