Exemplo n.º 1
0
def test_dummy_invalid_import(caplog, temp_builds_dir, fixtures_settings,
                              reset_syspath):
    """
    Import invalid (bad import) module from sample dummy package
    """
    basedir = os.path.join(fixtures_settings.fixtures_path, "dummy_package")
    module_name = "invalid_import"

    setup_project(basedir, "dummy_value", set_envvar=False)

    with pytest.raises(ImportError):
        import_settings_module(module_name, basedir=basedir)

    assert caplog.record_tuples == [
        (
            "optimus",
            logging.INFO,
            "Register project base directory: {}".format(basedir),
        ),
        ("optimus", logging.INFO, 'Loading "{}" module'.format(module_name)),
        (
            "optimus",
            logging.CRITICAL,
            "Unable to load settings module, it probably have errors: {}".
            format(module_name),
        ),
    ]

    # Cleanup sys.path for next tests
    reset_syspath(basedir)
Exemplo n.º 2
0
def test_dummy_unfinded(caplog, temp_builds_dir, fixtures_settings,
                        reset_syspath):
    """
    Unfindable module from sample dummy package
    """
    basedir = os.path.join(fixtures_settings.fixtures_path, "dummy_package")
    module_name = "idontexist"

    setup_project(basedir, "dummy_value", set_envvar=False)

    with pytest.raises(SystemExit):
        import_settings_module(module_name, basedir=basedir)

    assert caplog.record_tuples == [
        (
            "optimus",
            logging.INFO,
            "Register project base directory: {}".format(basedir),
        ),
        ("optimus", logging.INFO, 'Loading "{}" module'.format(module_name)),
        (
            "optimus",
            logging.CRITICAL,
            "Unable to find settings module: {}".format(module_name),
        ),
    ]

    # Cleanup sys.path for next tests
    reset_syspath(basedir)
Exemplo n.º 3
0
def build_command(context, basedir, settings_name):
    """
    Build project pages
    """
    # Set project before to be able to load its modules
    setup_project(basedir, settings_name)

    # Load current project settings and page map
    settings = import_settings_module(settings_name, basedir=basedir)
    # In test environment, force the module reload to avoid previous test cache to be
    # used (since the module have the same path).
    if context.obj["test_env"]:
        settings = importlib.reload(settings)

    settings = load_settings(settings)

    views = import_pages_module(settings.PAGES_MAP, basedir=basedir)
    if context.obj["test_env"]:
        views = importlib.reload(views)

    # Debug output
    display_settings(
        settings,
        ("DEBUG", "PROJECT_DIR", "SOURCES_DIR", "TEMPLATES_DIR",
         "LOCALES_DIR"),
    )

    builder_interface(settings, views)
Exemplo n.º 4
0
def test_dummy_invalid_import(caplog, temp_builds_dir, fixtures_settings):
    """
    Import invalid (bad import) module from sample dummy package
    """
    basedir = os.path.join(fixtures_settings.fixtures_path, 'dummy_package')
    module_name = 'invalid_import'

    with pytest.raises(ImportError):
        mod = import_settings_module(module_name, basedir=basedir)

    assert caplog.record_tuples == [
        (
            'optimus',
            logging.INFO,
            'Loading "{}" module'.format(module_name)
        ),
        (
            'optimus',
            logging.INFO,
            'Module searched in: {}'.format(basedir)
        ),
        (
            'optimus',
            logging.CRITICAL,
            'Unable to load settings module, it probably have errors: {}'.format(module_name)
        ),
    ]
Exemplo n.º 5
0
def test_dummy_unfinded(caplog, temp_builds_dir, fixtures_settings):
    """
    Unfindable module from sample dummy package
    """
    basedir = os.path.join(fixtures_settings.fixtures_path, 'dummy_package')
    module_name = 'idontexist'

    with pytest.raises(SystemExit):
        mod = import_settings_module(module_name, basedir=basedir)

    assert caplog.record_tuples == [
        (
            'optimus',
            logging.INFO,
            'Loading "{}" module'.format(module_name)
        ),
        (
            'optimus',
            logging.INFO,
            'Module searched in: {}'.format(basedir)
        ),
        (
            'optimus',
            logging.CRITICAL,
            'Unable to find settings module: {}'.format(module_name)
        ),
    ]
Exemplo n.º 6
0
def watch_command(context, basedir, settings_name):
    """
    Watch for changes in project sources to automatically build project
    ressources
    """
    logger = logging.getLogger("optimus")

    # Set project before to be able to load its modules
    setup_project(basedir, settings_name)

    # Load current project settings and page map
    settings = import_settings_module(settings_name, basedir=basedir)
    # In test environment, force the module reload to avoid previous test cache to be
    # used (since the module have the same path).
    if context.obj["test_env"]:
        settings = importlib.reload(settings)

    settings = load_settings(settings)

    views = import_pages_module(settings.PAGES_MAP, basedir=basedir)
    if context.obj["test_env"]:
        views = importlib.reload(views)

    # Debug output
    display_settings(
        settings,
        ("DEBUG", "PROJECT_DIR", "SOURCES_DIR", "TEMPLATES_DIR", "LOCALES_DIR"),
    )

    logger.debug("Trigger pages build to start")
    build_env = builder_interface(settings, views)

    # Init and configure observer with events
    observer = watcher_interface(settings, views, build_env)

    logger.warning("Starting to watch sources, use CTRL+C to stop it")
    # Do not start observer during tests since we cannot manage interruption and
    # watcher threads
    if not context.obj["test_env"]:
        observer.start()
        try:
            while True:
                time.sleep(1)
        except KeyboardInterrupt:
            logger.warning("Stopping watcher..")
            observer.stop()
        observer.join()
Exemplo n.º 7
0
def runserver_command(context, basedir, settings_name, index, hostname):
    """
    Launch a simple HTTP server rooted on the project build directory

    Default behavior is to bind server on IP address '127.0.0.1' and port
    '80'. You may give another host to bind to as argument 'HOSTNAME'.

    'HOSTNAME' can be either a simple address like '0.0.0.0' or an address and
    port like '0.0.0.0:8001'. If no custom port is given, '80' is used as
    default.
    """
    logger = logging.getLogger("optimus")

    # Set project before to be able to load its modules
    setup_project(basedir, settings_name)

    # Load current project settings and page map
    settings = import_settings_module(settings_name, basedir=basedir)
    # In test environment, force the module reload to avoid previous test cache to be
    # used (since the module have the same path).
    if context.obj["test_env"]:
        settings = importlib.reload(settings)

    settings = load_settings(settings)

    # Debug output
    display_settings(
        settings,
        ("DEBUG", "PROJECT_DIR", "SOURCES_DIR", "TEMPLATES_DIR",
         "LOCALES_DIR"),
    )

    try:
        server_env = server_interface(settings, hostname, index=index)
    except ServerConfigurationError as e:
        logger.error(e)
        raise click.Abort()

    # Don't start cherrypy server during tests
    if not context.obj["test_env"]:
        server_env["cherrypy"].quickstart(
            None,
            server_env["mount_on"],
            config=server_env["app_conf"],
        )
Exemplo n.º 8
0
def po_command(context, init, update, compile_opt, basedir, settings_name):
    """
    Manage project translation catalogs for all registred languages
    """
    # Set project before to be able to load its modules
    setup_project(basedir, settings_name)

    # Load current project settings and page map
    settings = import_settings_module(settings_name, basedir=basedir)
    # In test environment, force the module reload to avoid previous test cache to be
    # used (since the module have the same path).
    if context.obj["test_env"]:
        settings = importlib.reload(settings)

    settings = load_settings(settings)

    # Debug output
    display_settings(
        settings,
        ("DEBUG", "PROJECT_DIR", "SOURCES_DIR", "TEMPLATES_DIR",
         "LOCALES_DIR"),
    )

    po_interface(settings, init=init, update=update, compile_opt=compile_opt)