Exemple #1
0
def test_001_basic(settings, sample_project_settings):
    """conf.Settings: Ensure cleans don't drop available settings"""
    settings_object = Settings()

    fake_settings = copy.deepcopy(sample_project_settings)

    assert settings_object.clean(fake_settings) == sample_project_settings
Exemple #2
0
def test_001_basic(settings, sample_project_settings):
    """conf.Settings: Ensure dummy update is correct"""
    settings_object = Settings()

    settings_object.update(sample_project_settings)

    assert settings_object._settings == sample_project_settings
Exemple #3
0
def test_001_basic(settings, sample_project_settings):
    """conf.Settings: Ensure dummy update is correct"""
    settings_object = Settings()

    settings_object.update(sample_project_settings)

    assert settings_object._settings == sample_project_settings
Exemple #4
0
def test_001_basic(settings, sample_project_settings):
    """conf.Settings: Ensure cleans don't drop available settings"""
    settings_object = Settings()

    fake_settings = copy.deepcopy(sample_project_settings)

    assert settings_object.clean(fake_settings) == sample_project_settings
Exemple #5
0
def test_002_polluted(settings, sample_project_settings):
    """conf.Settings: Ensure update filtering is done"""
    settings_object = Settings(initial=sample_project_settings)

    # Add some wrong settings
    settings_object.update({'PLOP': True, 'Foo': 42, 'BAR': [1, 5, 10]})

    assert settings_object._settings == sample_project_settings
Exemple #6
0
def test_002_polluted(settings, sample_project_settings):
    """conf.Settings: Ensure update filtering is done"""
    settings_object = Settings(initial=sample_project_settings)

    # Add some wrong settings
    settings_object.update({
        'PLOP': True,
        'Foo': 42,
        'BAR': [1, 5, 10]
    })

    assert settings_object._settings == sample_project_settings
Exemple #7
0
def test_002_custom(settings, sample_project_settings):
    """conf.Settings: Filter unavailable settings"""
    settings_object = Settings()

    fake_settings = copy.deepcopy(sample_project_settings)

    # Add some dummy settings to remove
    fake_settings.update({
        'foo': True,
        'bar': 42,
        'plonk': [],
    })

    assert settings_object.clean(fake_settings) == sample_project_settings
Exemple #8
0
def test_002_custom(settings, sample_project_settings):
    """conf.Settings: Filter unavailable settings"""
    settings_object = Settings()

    fake_settings = copy.deepcopy(sample_project_settings)

    # Add some dummy settings to remove
    fake_settings.update({
        'foo': True,
        'bar': 42,
        'plonk': [],
    })

    assert settings_object.clean(fake_settings) == sample_project_settings
Exemple #9
0
def test_source_map_content(compiler, temp_builds_dir):
    """
    Check about source map content
    """
    basic_settings = Settings(
        initial={
            'SOURCES_PATH': '.',
            'TARGET_PATH': 'css',
            'SOURCE_MAP': True,
            'OUTPUT_STYLES': 'compact',
        })

    basedir = temp_builds_dir.join('compiler_source_map_content').strpath

    sourcedir = os.path.normpath(
        os.path.join(basedir, basic_settings.SOURCES_PATH))
    targetdir = os.path.normpath(
        os.path.join(basedir, basic_settings.TARGET_PATH))

    os.makedirs(sourcedir)
    os.makedirs(targetdir)

    src = os.path.join(sourcedir, "app.scss")
    dst = os.path.join(targetdir, "app.css")
    src_map = os.path.join(targetdir, "app.map")

    # Create sample source to compile
    with io.open(src, 'w', encoding='utf-8') as f:
        f.write(u"""#content{ color:#ff0000; font-weight:bold; }""")

    # Compile
    success, message = compiler.safe_compile(basic_settings, src, dst)

    assert os.path.exists(dst)
    assert os.path.exists(src_map)

    with io.open(dst, 'r', encoding='utf-8') as f:
        content = f.read()

    with io.open(src_map, 'r', encoding='utf-8') as f:
        sourcemap = json.load(f)

    # Assert compiled file is ok
    assert content == (
        """#content { color: #ff0000; font-weight: bold; }\n\n"""
        """/*# sourceMappingURL=app.map */""")

    # Drop 'version' key since it will cause problem with futur libsass
    # versions
    del sourcemap['version']

    # Assert source map is ok
    assert sourcemap == {
        "file":
        "app.css",
        "sources": ["../app.scss"],
        "mappings": ("AAAA,AAAA,QAAQ,CAAA,EAAE,KAAK,EAAC,OAAO,EAAE,WAAW,EAAC,"
                     "IAAI,GAAI"),
        "names": []
    }
Exemple #10
0
def test_explicit_css_import_ok(compiler, temp_builds_dir):
    """
    Explicitely imported CSS file allways insert ``@import [..]`` instead of
    including CSS source no matter CUSTOM_IMPORT_EXTENSIONS settings
    """
    name = 'compiler_css_compat_explicit_css_import_ok'
    basedir = temp_builds_dir.join(name).strpath

    basic_settings = Settings(
        initial={
            'SOURCES_PATH': 'scss',
            'TARGET_PATH': 'css',
            'SOURCE_MAP': False,
            'OUTPUT_STYLES': 'compact',
            'CUSTOM_IMPORT_EXTENSIONS': [".css"],
        })

    sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
    targetdir = os.path.join(basedir, basic_settings.TARGET_PATH)

    src = os.path.join(sourcedir, "app.scss")
    css_include = os.path.join(sourcedir, "_dummy.css")
    dst = os.path.join(targetdir, "app.css")

    os.makedirs(sourcedir)
    os.makedirs(targetdir)

    # Create sample main Sass source
    with io.open(src, 'w', encoding='utf-8') as f:
        result = f.write(u"""
            @import "dummy.css";
            #content{
            color: #ff0000;
            font-weight: bold;
            &.foo{ border: 1px solid #000000; }
            }
            """)

    # Create sample main Sass source
    with io.open(css_include, 'w', encoding='utf-8') as f:
        result = f.write(u"""
            .dummy{
                color: #00ff00;
            }
            """)

    # Compile
    success, message = compiler.safe_compile(basic_settings, src, dst)

    assert os.path.exists(dst) == True

    # Assert compiled file is ok
    with io.open(dst, 'r', encoding='utf-8') as f:
        content = f.read()

    attempted = ("""@import url(dummy.css);\n"""
                 """#content { color: #ff0000; font-weight: bold; }\n\n"""
                 """#content.foo { border: 1px solid #000000; }\n""")

    assert content == attempted
Exemple #11
0
def test_001_default(settings, sample_project_settings):
    """conf.Settings: Create a empty Settings object width default values"""
    settings_object = Settings()

    assert settings_object._settings == DEFAULT_SETTINGS

    assert settings_object.TARGET_PATH == DEFAULT_SETTINGS['TARGET_PATH']
    assert settings_object.OUTPUT_STYLES == DEFAULT_SETTINGS['OUTPUT_STYLES']
Exemple #12
0
def test_css_compat_ok(compiler, temp_builds_dir):
    """
    Ensure CSS import compatibility is still ok on default behavior
    """
    basedir = temp_builds_dir.join('compiler_css_compat_ok').strpath

    basic_settings = Settings(
        initial={
            'SOURCES_PATH': 'scss',
            'TARGET_PATH': 'css',
            'SOURCE_MAP': False,
            'OUTPUT_STYLES': 'compact',
            #'CUSTOM_IMPORT_EXTENSIONS': [".css"],
        })

    sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
    targetdir = os.path.join(basedir, basic_settings.TARGET_PATH)

    src = os.path.join(sourcedir, "app.scss")
    css_include = os.path.join(sourcedir, "_dummy.css")
    dst = os.path.join(targetdir, "app.css")

    os.makedirs(sourcedir)
    os.makedirs(targetdir)

    # Create sample main Sass source
    with io.open(src, 'w', encoding='utf-8') as f:
        result = f.write(u"""
            @import "dummy";
            #content{
            color: #ff0000;
            font-weight: bold;
            &.foo{ border: 1px solid #000000; }
            }
            """)

    # Create sample main Sass source
    with io.open(css_include, 'w', encoding='utf-8') as f:
        result = f.write(u"""
            .dummy{
                color: #00ff00;
            }
            """)

    # Compile
    success, message = compiler.safe_compile(basic_settings, src, dst)

    assert os.path.exists(dst) == True

    # Assert compiled file is ok
    with io.open(dst, 'r', encoding='utf-8') as f:
        content = f.read()

    attempted = (""".dummy { color: #00ff00; }\n\n"""
                 """#content { color: #ff0000; font-weight: bold; }\n\n"""
                 """#content.foo { border: 1px solid #000000; }\n""")

    assert content == attempted
Exemple #13
0
def test_source_map_path_002(compiler, temp_builds_dir):
    """
    Check about source map path from 'sourceMappingURL' with CSS dir below
    Sass source dir
    """
    basic_settings = Settings(
        initial={
            'SOURCES_PATH': 'scss',
            'TARGET_PATH': 'project/css',
            'SOURCE_MAP': True,
            'OUTPUT_STYLES': 'compact',
        })

    basedir = temp_builds_dir.join('compiler_source_map_path_002').strpath
    sourcedir = os.path.normpath(
        os.path.join(basedir, basic_settings.SOURCES_PATH))
    targetdir = os.path.normpath(
        os.path.join(basedir, basic_settings.TARGET_PATH))

    os.makedirs(sourcedir)
    os.makedirs(targetdir)

    src = os.path.join(sourcedir, "app.scss")
    dst = os.path.join(targetdir, "app.css")
    src_map = os.path.join(targetdir, "app.map")

    # Create sample source to compile
    with io.open(src, 'w', encoding='utf-8') as f:
        f.write(u"""#content{ color:#ff0000; font-weight:bold; }""")

    # Compile
    success, message = compiler.safe_compile(basic_settings, src, dst)

    assert os.path.exists(dst)
    assert os.path.exists(src_map)

    with io.open(dst, 'r', encoding='utf-8') as f:
        content = f.read()

    with io.open(src_map, 'r', encoding='utf-8') as f:
        sourcemap = json.load(f)

    # Assert compiled file is ok
    assert content == (
        """#content { color: #ff0000; font-weight: bold; }\n\n"""
        """/*# sourceMappingURL=app.map */""")

    # Drop keys we don't care for this test
    del sourcemap['version']
    del sourcemap['mappings']
    del sourcemap['names']

    # Assert source map is ok
    assert sourcemap == {
        "file": "app.css",
        "sources": ["../../scss/app.scss"],
    }
Exemple #14
0
def test_003_mixed(settings, sample_project_settings):
    """conf.Settings: Ensure update filtering is correct on both enabled and
       not enabled setting names"""
    settings_object = Settings(initial=sample_project_settings)

    # Add one available setting and some other wrong settings
    settings_object.update({
        'OUTPUT_STYLES': 'compressed',
        'PLOP': True,
        'Foo': 42,
        'BAR': [1, 5, 10]
    })

    # New settings reference with modified setting
    mixed = copy.deepcopy(sample_project_settings)
    mixed.update({
        'OUTPUT_STYLES': 'compressed',
    })

    assert settings_object._settings == mixed
Exemple #15
0
def test_003_mixed(settings, sample_project_settings):
    """conf.Settings: Ensure update filtering is correct on both enabled and
       not enabled setting names"""
    settings_object = Settings(initial=sample_project_settings)

    # Add one available setting and some other wrong settings
    settings_object.update({
        'OUTPUT_STYLES': 'compressed',
        'PLOP': True,
        'Foo': 42,
        'BAR': [1, 5, 10]
    })

    # New settings reference with modified setting
    mixed = copy.deepcopy(sample_project_settings)
    mixed.update({
        'OUTPUT_STYLES': 'compressed',
    })

    assert settings_object._settings == mixed
Exemple #16
0
def test_css_compat_fail(compiler, temp_builds_dir):
    """
    Check CSS compat is disabled from settings
    """
    basedir = temp_builds_dir.join('compiler_css_compat_fail').strpath

    basic_settings = Settings(
        initial={
            'SOURCES_PATH': 'scss',
            'TARGET_PATH': 'css',
            'SOURCE_MAP': False,
            'OUTPUT_STYLES': 'compact',
            'CUSTOM_IMPORT_EXTENSIONS': [],
        })

    sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
    targetdir = os.path.join(basedir, basic_settings.TARGET_PATH)

    src = os.path.join(sourcedir, "app.scss")
    css_include = os.path.join(sourcedir, "_dummy.css")
    dst = os.path.join(targetdir, "app.css")

    os.makedirs(sourcedir)
    os.makedirs(targetdir)

    # Create sample main Sass source
    with io.open(src, 'w', encoding='utf-8') as f:
        result = f.write(u"""
            @import "dummy";
            #content{
            color: #ff0000;
            font-weight: bold;
            &.foo{ border: 1px solid #000000; }
            }
            """)

    # Create sample main Sass source
    with io.open(css_include, 'w', encoding='utf-8') as f:
        result = f.write(u"""
            .dummy{
                color: #00ff00;
            }
            """)

    # Compile
    success, message = compiler.safe_compile(basic_settings, src, dst)

    attempted_error = "Error: File to import not found or unreadable: dummy."

    assert (attempted_error in message) == True
    assert success == False
Exemple #17
0
def test_002_minimal(settings, sample_project_settings):
    """conf.Settings: Very minimalistic settings"""
    minimal_conf = {
        'SOURCES_PATH': '.',
        'TARGET_PATH': './css',
    }

    settings_object = Settings(initial=minimal_conf)

    attempted = copy.deepcopy(DEFAULT_SETTINGS)
    attempted.update(minimal_conf)

    assert settings_object._settings == attempted

    assert settings_object.TARGET_PATH == attempted['TARGET_PATH']
    assert settings_object.OUTPUT_STYLES == attempted['OUTPUT_STYLES']
Exemple #18
0
def test_001(compiler, temp_builds_dir):
    """
    Basic sample without source map
    """
    basedir = temp_builds_dir.join('compiler_safecompile').strpath

    basic_settings = Settings(
        initial={
            'SOURCES_PATH': 'scss',
            'TARGET_PATH': 'css',
            'SOURCE_MAP': False,
            'OUTPUT_STYLES': 'compact',
        })

    sourcedir = os.path.join(basedir, basic_settings.SOURCES_PATH)
    targetdir = os.path.join(basedir, basic_settings.TARGET_PATH)

    src = os.path.join(sourcedir, "app.scss")
    dst = os.path.join(targetdir, "app.css")
    src_map = os.path.join(targetdir, "app.map")

    os.makedirs(sourcedir)
    os.makedirs(targetdir)

    # Create sample source to compile
    with io.open(src, 'w', encoding='utf-8') as f:
        result = f.write(u"""#content{
            color: #ff0000;
            font-weight: bold;
            &.foo{ border: 1px solid #000000; }
            }
            """)

    # Compile
    success, message = compiler.safe_compile(basic_settings, src, dst)

    assert os.path.exists(dst) == True
    assert os.path.exists(src_map) == False

    # Assert compiled file is ok
    with io.open(dst, 'r', encoding='utf-8') as f:
        content = f.read()

    assert content == (
        """#content { color: #ff0000; font-weight: bold; }\n\n"""
        """#content.foo { border: 1px solid #000000; }\n""")
Exemple #19
0
def start_env(basedir):
    """
    Init all needed stuff for handler testing
    """
    join_basedir_curry = join_basedir(basedir.strpath)

    inspector = ScssInspector()

    minimal_conf = {
        'SOURCES_PATH': basedir.join('sass').strpath,
        'TARGET_PATH': basedir.join('css').strpath,
        'LIBRARY_PATHS': [basedir.join('lib').strpath],
    }
    settings = Settings(initial=minimal_conf)

    watcher_opts = {
        'patterns': ['*.scss'],
        'ignore_patterns': ['*.part'],
        'ignore_directories': False,
        'case_sensitive': True,
    }
    return join_basedir_curry, inspector, settings, watcher_opts
Exemple #20
0
    def load(self, filepath=None):
        """
        Load settings file from given path and optionnal filepath.

        During path resolving, the ``projectdir`` is updated to the file path
        directory.

        Keyword Arguments:
            filepath (str): Filepath to the settings file.

        Returns:
            boussole.conf.model.Settings: Settings object with loaded elements.

        """
        self.projectdir, filename = self.parse_filepath(filepath)

        settings_path = self.check_filepath(self.projectdir, filename)

        parsed = self.parse(settings_path, self.open(settings_path))

        settings = self.clean(parsed)

        return Settings(initial=settings)