Example #1
0
def test_library_modified_101(temp_builds_dir):
    """watcher.SassLibraryEventHandler: 'Modified' event on a library
       component"""
    basedir = temp_builds_dir.join('watcher_success_101')

    bdir, inspector, settings_object, watcher_opts = start_env(basedir)

    build_sample_structure(settings_object, basedir)

    # Init handler
    project_handler = UnitTestableLibraryEventHandler(settings_object,
                                                      inspector,
                                                      **watcher_opts)

    project_handler.on_modified(
        DummyBaseEvent(bdir('lib/components/_buttons.scss')))

    project_handler.on_modified(DummyBaseEvent(bdir('lib/libmain.scss')))

    results = os.listdir(basedir.join("css").strpath)
    results.sort()

    # Almost dummy validation because on wrong behavior (with
    # UnitTestableProjectEventHandler instead of
    # UnitTestableLibraryEventHandler) CSS files are writed to "../lib"
    # path, that is under the "css" dir.
    assert results == [
        'main_usinglib.css',
    ]
Example #2
0
def test_whole_050(temp_builds_dir):
    """watcher.SassProjectEventHandler: Routine using some events on various
       sources"""
    basedir = temp_builds_dir.join('watcher_success_050')

    bdir, logger, inspector, settings_object, watcher_opts = start_env(basedir)

    build_sample_structure(settings_object, basedir)

    # Init handler
    project_handler = UnitTestableProjectEventHandler(settings_object, logger,
                                                      inspector,
                                                      **watcher_opts)

    # Modify a partial source
    project_handler.on_modified(DummyBaseEvent(bdir('sass/_toinclude.scss')))
    assert os.listdir(basedir.join("css").strpath) == [
        'main_usinglib.css', 'main.css', 'main_importing.css'
    ]

    # Create a new main source
    source = "\n".join((
        """/* New main source */""",
        """#content{ padding: 10px; margin: 5px 0; }""",
    ))
    with open(basedir.join('sass/new_main.scss').strpath, 'w') as f:
        f.write(source)

    project_handler.on_created(DummyBaseEvent(bdir('sass/new_main.scss')))
    assert os.listdir(basedir.join("css").strpath) == [
        'new_main.css', 'main_usinglib.css', 'main.css', 'main_importing.css'
    ]

    # Delete a main source
    os.remove(bdir('css/main_importing.css'))
    os.remove(bdir('sass/main_importing.scss'))

    project_handler.on_deleted(DummyBaseEvent(
        bdir('sass/main_importing.scss')))
    assert os.listdir(basedir.join("css").strpath) == [
        'new_main.css', 'main_usinglib.css', 'main.css'
    ]

    # Simulate moved source
    project_handler.on_moved(DummyMoveEvent(bdir('sass/_toinclude.scss')))
    assert os.listdir(basedir.join("css").strpath) == [
        'new_main.css', 'main_usinglib.css', 'main.css'
    ]
Example #3
0
def test_created_030(temp_builds_dir):
    """watcher.SassProjectEventHandler: 'Created' event for a new main source"""
    basedir = temp_builds_dir.join('watcher_success_030')

    bdir, inspector, settings_object, watcher_opts = start_env(basedir)

    build_sample_structure(settings_object, basedir)

    # Init handler
    project_handler = UnitTestableProjectEventHandler(settings_object,
                                                      inspector,
                                                      **watcher_opts)

    # Write a new main source
    source = "\n".join((
        """/* New main source */""",
        """#content{ padding: 10px; margin: 5px 0; }""",
    ))
    with open(basedir.join('sass/new_main.scss').strpath, 'w') as f:
        f.write(source)

    project_handler.on_created(DummyBaseEvent(bdir('sass/new_main.scss')))

    results = os.listdir(basedir.join("css").strpath)
    results.sort()

    assert results == [
        'new_main.css',
    ]
Example #4
0
def test_deleted_001(caplog, temp_builds_dir):
    """watcher.SassProjectEventHandler: UnresolvablePath on 'Deleted' event for a partial
       source included by other files"""
    basedir = temp_builds_dir.join('watcher_fails_041')

    bdir, logger, inspector, settings_object, watcher_opts = start_env(basedir)

    build_sample_structure(settings_object, basedir)

    # Init handler
    project_handler = UnitTestableProjectEventHandler(settings_object, logger,
                                                      inspector,
                                                      **watcher_opts)

    os.remove(bdir('sass/_toinclude.scss'))

    # Error is catched
    project_handler.on_deleted(DummyBaseEvent(bdir('sass/_toinclude.scss')))

    # Error from core API is catched
    assert project_handler._event_error == True
    # Logged error
    assert caplog.record_tuples == [
        ('boussole', 40,
         "Imported path 'toinclude' does not exist in '{}'".format(
             basedir.join('sass').strpath))
    ]
Example #5
0
def test_modified_020(temp_builds_dir):
    """
    'Modified' event on included partial source
    """
    basedir = temp_builds_dir.join('watcher_success_020')

    bdir, inspector, settings_object, watcher_opts = start_env(basedir)

    build_scss_sample_structure(settings_object, basedir)

    # Init handler
    project_handler = UnitTestableProjectEventHandler(settings_object,
                                                      inspector,
                                                      **watcher_opts)

    project_handler.on_modified(DummyBaseEvent(bdir('sass/_toinclude.scss')))

    results = os.listdir(basedir.join("css").strpath)
    results.sort()

    assert results == [
        'main.css',
        'main_importing.css',
        'main_usinglib.css',
    ]
Example #6
0
def test_deleted_040(temp_builds_dir):
    """watcher.SassProjectEventHandler: 'Deleted' event for a main source"""
    basedir = temp_builds_dir.join('watcher_success_040')

    bdir, logger, inspector, settings_object, watcher_opts = start_env(basedir)

    build_sample_structure(settings_object, basedir)

    # Init handler
    project_handler = UnitTestableProjectEventHandler(settings_object, logger,
                                                      inspector,
                                                      **watcher_opts)

    os.remove(bdir('sass/main_importing.scss'))

    project_handler.on_deleted(DummyBaseEvent(
        bdir('sass/main_importing.scss')))
    assert os.listdir(basedir.join("css").strpath) == []