Exemple #1
0
def test_001_basic(settings, custom_project_settings):
    """conf.json_backend.SettingsBackendJson: Load basic JSON settings file
       fail because of wrong paths"""
    backend = SettingsBackendJson(basedir=settings.fixtures_path)

    with pytest.raises(SettingsInvalidError):
        settings_object = backend.load()
Exemple #2
0
def test_001_basic(settings, custom_project_settings):
    """conf.json_backend.SettingsBackendJson: Load basic JSON settings file
       fail because of wrong paths"""
    backend = SettingsBackendJson(basedir=settings.fixtures_path)

    with pytest.raises(SettingsInvalidError):
        settings_object = backend.load()
Exemple #3
0
def test_002_empty_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: no path given and
       with a basedir"""
    backend = SettingsBackendJson(basedir="/home/bart/www")

    result = backend.parse_filepath()

    assert result == ("/home/bart/www", "settings.json")
Exemple #4
0
def test_001_empty_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: no path given and
       with empty basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath()

    assert result == ('.', "settings.json")
Exemple #5
0
def test_005_relative_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: relative filepath and empty
       basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="foo/settings_custom.json")

    assert result == (
        'foo',
        "settings_custom.json",
    )
Exemple #6
0
def test_004_filename_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: filename and filled
       basedir"""
    backend = SettingsBackendJson(basedir="/home/bart/www")

    result = backend.parse_filepath(filepath="settings_custom.json")

    assert result == (
        '/home/bart/www',
        "settings_custom.json",
    )
Exemple #7
0
def test_003_filename_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: filename and empty
       basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="settings_custom.json")

    assert result == (
        '.',
        "settings_custom.json",
    )
Exemple #8
0
def test_011_normalize_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: filename and empty basedir,
       normalize can't do anything"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="../settings_custom.json")

    assert result == (
        '..',
        "settings_custom.json",
    )
Exemple #9
0
def test_006_relative_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: relative filepath and filled
       basedir"""
    backend = SettingsBackendJson(basedir="/home/bart/www")

    result = backend.parse_filepath(filepath="foo/settings_custom.json")

    assert result == (
        "/home/bart/www/foo",
        "settings_custom.json",
    )
Exemple #10
0
def test_001_empty_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: no path given and
       with empty basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath()

    assert result == (
        '.',
        "settings.json"
    )
Exemple #11
0
def test_006_relative_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: relative filepath and filled
       basedir"""
    backend = SettingsBackendJson(basedir="/home/bart/www")

    result = backend.parse_filepath(filepath="foo/settings_custom.json")

    assert result == (
        "/home/bart/www/foo",
        "settings_custom.json",
    )
Exemple #12
0
def test_004_filename_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: filename and filled
       basedir"""
    backend = SettingsBackendJson(basedir="/home/bart/www")

    result = backend.parse_filepath(filepath="settings_custom.json")

    assert result == (
        '/home/bart/www',
        "settings_custom.json",
    )
Exemple #13
0
def test_005_relative_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: relative filepath and empty
       basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="foo/settings_custom.json")

    assert result == (
        'foo',
        "settings_custom.json",
    )
Exemple #14
0
def test_002_empty_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: no path given and
       with a basedir"""
    backend = SettingsBackendJson(basedir="/home/bart/www")

    result = backend.parse_filepath()

    assert result == (
        "/home/bart/www",
        "settings.json"
    )
Exemple #15
0
def test_003_filename_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: filename and empty
       basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="settings_custom.json")

    assert result == (
        '.',
        "settings_custom.json",
    )
Exemple #16
0
def test_008_absolute_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: absolute filepath and filled
       basedir to ensure basedir is ignored with absolute filepath"""
    backend = SettingsBackendJson(basedir="/home/no/pasaran")

    result = backend.parse_filepath(filepath="/home/bart/www/settings_custom.json")

    assert result == (
        "/home/bart/www",
        "settings_custom.json",
    )
Exemple #17
0
def test_011_normalize_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: filename and empty basedir,
       normalize can't do anything"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="../settings_custom.json")

    assert result == (
        '..',
        "settings_custom.json",
    )
Exemple #18
0
def test_007_absolute_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: absolute filepath and empty
       basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(filepath="/home/bart/www/settings_custom.json")

    assert result == (
        "/home/bart/www",
        "settings_custom.json",
    )
Exemple #19
0
def test_007_absolute_nobasedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: absolute filepath and empty
       basedir"""
    backend = SettingsBackendJson()

    result = backend.parse_filepath(
        filepath="/home/bart/www/settings_custom.json")

    assert result == (
        "/home/bart/www",
        "settings_custom.json",
    )
Exemple #20
0
def test_008_absolute_basedir(settings, sample_project_settings):
    """conf.SettingsBackendJson.parse_filepath: absolute filepath and filled
       basedir to ensure basedir is ignored with absolute filepath"""
    backend = SettingsBackendJson(basedir="/home/no/pasaran")

    result = backend.parse_filepath(
        filepath="/home/bart/www/settings_custom.json")

    assert result == (
        "/home/bart/www",
        "settings_custom.json",
    )
Exemple #21
0
def compile_command(context, config):
    """
    Compile SASS project sources to CSS
    """
    logger = context.obj['logger']
    logger.info("Building project")

    # Load settings file
    try:
        backend = SettingsBackendJson(basedir=os.getcwd())
        settings = backend.load(filepath=config)
    except SettingsBackendError as e:
        logger.critical(e.message)
        raise click.Abort()

    logger.debug("Project sources directory: {}".format(
                settings.SOURCES_PATH))
    logger.debug("Project destination directory: {}".format(
                settings.TARGET_PATH))
    logger.debug("Exclude patterns: {}".format(
                settings.EXCLUDES))

    # Find all sources with their destination path
    try:
        compilable_files = ScssFinder().mirror_sources(
            settings.SOURCES_PATH,
            targetdir=settings.TARGET_PATH,
            excludes=settings.EXCLUDES
        )
    except BoussoleBaseException as e:
        logger.error(e.message)
        raise click.Abort()

    # Build all compilable stylesheets
    compiler = SassCompileHelper()
    errors = 0
    for src, dst in compilable_files:
        logger.debug("Compile: {}".format(src))

        output_opts = {}
        success, message = compiler.safe_compile(settings, src, dst)

        if success:
            logger.info("Output: {}".format(message), **output_opts)
        else:
            errors += 1
            logger.error(message)

    # Ensure correct exit code if error has occured
    if errors:
        raise click.Abort()
Exemple #22
0
def test_003_custom(settings, custom_project_settings):
    """conf.json_backend.SettingsBackendJson: Load custom JSON settings file"""
    backend = SettingsBackendJson(basedir=settings.fixtures_path)

    settings_object = backend.load(filepath="settings_custom.json")

    assert settings_object._settings == custom_project_settings

    assert settings_object.TARGET_PATH == custom_project_settings['TARGET_PATH']
    assert settings_object.SOURCES_PATH == custom_project_settings['SOURCES_PATH']
    assert settings_object.LIBRARY_PATHS == custom_project_settings['LIBRARY_PATHS']
    assert settings_object.OUTPUT_STYLES == custom_project_settings['OUTPUT_STYLES']

    # Wrong settings that does not exist and should have been removed
    assert getattr(settings_object, 'FOO', None) == None
    assert getattr(settings_object, 'BAR', None) == None
Exemple #23
0
def test_003_custom(settings, custom_project_settings):
    """conf.json_backend.SettingsBackendJson: Load custom JSON settings file"""
    backend = SettingsBackendJson(basedir=settings.fixtures_path)

    settings_object = backend.load(filepath="settings_custom.json")

    assert settings_object._settings == custom_project_settings

    assert settings_object.TARGET_PATH == custom_project_settings[
        'TARGET_PATH']
    assert settings_object.SOURCES_PATH == custom_project_settings[
        'SOURCES_PATH']
    assert settings_object.LIBRARY_PATHS == custom_project_settings[
        'LIBRARY_PATHS']
    assert settings_object.OUTPUT_STYLES == custom_project_settings[
        'OUTPUT_STYLES']

    # Wrong settings that does not exist and should have been removed
    assert getattr(settings_object, 'FOO', None) == None
    assert getattr(settings_object, 'BAR', None) == None
Exemple #24
0
def test_error_001(settings, sample_project_settings):
    """conf.json_backend.SettingsBackendJson: JSON content parsing error"""
    backend = SettingsBackendJson(basedir=settings.fixtures_path)

    path, filename = backend.parse_filepath(filepath="settings.txt")
    filepath = backend.check_filepath(path, filename)

    content = backend.open(filepath)

    with pytest.raises(SettingsBackendError):
        backend.parse(filepath, content)
Exemple #25
0
def test_ok_001(settings, sample_project_settings):
    """conf.json_backend.SettingsBackendJson: JSON content parsing"""
    backend = SettingsBackendJson(basedir=settings.fixtures_path)

    path, filename = backend.parse_filepath()
    filepath = backend.check_filepath(path, filename)

    content = backend.open(filepath)

    assert backend.parse(filepath, content) == sample_project_settings
Exemple #26
0
def watch_command(context, config):
    """
    Watch for change on your SASS project sources then compile them to CSS.

    Watched events are:

    \b
    * Create: when a new source file is created;
    * Change: when a source is changed;
    * Delete: when a source is deleted;
    * Move: When a source file is moved;

    Almost all errors occurring during compile won't break watcher, so you can
    resolve them and watcher will try again to compile once an a new event
    occurs.

    You can stop watcher using key combo "CTRL+C" (or CMD+C on MacOSX).
    """
    logger = context.obj['logger']
    logger.info("Watching project")

    # Load settings file
    try:
        backend = SettingsBackendJson(basedir=os.getcwd())
        settings = backend.load(filepath=config)
    except SettingsBackendError as e:
        logger.critical(e.message)
        raise click.Abort()

    logger.debug("Project sources directory: {}".format(settings.SOURCES_PATH))
    logger.debug("Project destination directory: {}".format(
        settings.TARGET_PATH))
    logger.debug("Exclude patterns: {}".format(settings.EXCLUDES))

    # Watcher settings
    watcher_templates_patterns = {
        'patterns': ['*.scss'],
        'ignore_patterns': ['*.part'],
        'ignore_directories': False,
        'case_sensitive': True,
    }

    # Init inspector instance shared through all handlers
    inspector = ScssInspector()

    # Registering event handlers to observer
    observer = Observer()
    project_handler = WatchdogProjectEventHandler(settings, logger, inspector,
                                                  **watcher_templates_patterns)

    lib_handler = WatchdogLibraryEventHandler(settings, logger, inspector,
                                              **watcher_templates_patterns)

    # Observe source directory
    observer.schedule(project_handler, settings.SOURCES_PATH, recursive=True)

    # Also observe libraries directories
    for libpath in settings.LIBRARY_PATHS:
        observer.schedule(lib_handler, libpath, recursive=True)

    # Start watching
    logger.warning("Launching the watcher, use CTRL+C to stop it")
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        logger.warning("CTRL+C used, stopping..")
        observer.stop()

    observer.join()
Exemple #27
0
def watch_command(context, config):
    """
    Watch for change on your SASS project sources then compile them to CSS.

    Watched events are:

    \b
    * Create: when a new source file is created;
    * Change: when a source is changed;
    * Delete: when a source is deleted;
    * Move: When a source file is moved;

    Almost all errors occurring during compile won't break watcher, so you can
    resolve them and watcher will try again to compile once an a new event
    occurs.

    You can stop watcher using key combo "CTRL+C" (or CMD+C on MacOSX).
    """
    logger = context.obj['logger']
    logger.info("Watching project")

    # Load settings file
    try:
        backend = SettingsBackendJson(basedir=os.getcwd())
        settings = backend.load(filepath=config)
    except SettingsBackendError as e:
        logger.critical(e.message)
        raise click.Abort()

    logger.debug("Project sources directory: {}".format(
                settings.SOURCES_PATH))
    logger.debug("Project destination directory: {}".format(
                settings.TARGET_PATH))
    logger.debug("Exclude patterns: {}".format(
                settings.EXCLUDES))

    # Watcher settings
    watcher_templates_patterns = {
        'patterns': ['*.scss'],
        'ignore_patterns': ['*.part'],
        'ignore_directories': False,
        'case_sensitive': True,
    }

    # Init inspector instance shared through all handlers
    inspector = ScssInspector()

    # Registering event handlers to observer
    observer = Observer()
    project_handler = WatchdogProjectEventHandler(settings, logger, inspector,
                                                  **watcher_templates_patterns)

    lib_handler = WatchdogLibraryEventHandler(settings, logger, inspector,
                                              **watcher_templates_patterns)

    # Observe source directory
    observer.schedule(project_handler, settings.SOURCES_PATH, recursive=True)

    # Also observe libraries directories
    for libpath in settings.LIBRARY_PATHS:
        observer.schedule(lib_handler, libpath, recursive=True)

    # Start watching
    logger.warning("Launching the watcher, use CTRL+C to stop it")
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        logger.warning("CTRL+C used, stopping..")
        observer.stop()

    observer.join()