Exemple #1
0
def test_action_delete_file(fs):
    path = Path('./from/to-be-removed/example.txt')
    fs.create_file(str(path))

    action = Action(SourceAction.DELETE, path)
    action.perform()

    assert not path.exists()
Exemple #2
0
def test_action_directory_to_file(fs, source_action):
    source = Path('/from')
    target = Path('/to/example.txt')
    fs.create_dir(str(source))
    fs.create_file(str(target))

    action = Action(source_action, source, target)

    with pytest.raises(IOError):
        action.perform()
Exemple #3
0
def test_action_file_to_existing_file(fs, source_action):
    source = Path('/from/to-be-copied/example.txt')
    target = Path('/new/target/example.txt')
    fs.create_file(str(source))
    fs.create_file(str(target))

    # file does not exist
    action = Action(source_action, source, target)
    # file exists now and should lead to an error if performed again
    with pytest.raises(Exception):
        action.perform()
Exemple #4
0
def test_action_file_to_directory(fs, source_action):
    source = Path('/from/to-be-copied/example.txt')
    target = Path('/to/target')
    fs.create_file(str(source))

    action = Action(source_action, source, target)
    action.perform()

    assert (target / 'example.txt').exists()

    if source_action == SourceAction.MOVE:
        assert not source.exists()
Exemple #5
0
def test_action_file_to_file(fs, source_action):
    source = Path('/from/to-be-copied/example.txt')
    target = Path('/new/target/example.txt')
    fs.create_file(str(source))
    fs.create_dir('/new')

    # file does not exist
    action = Action(source_action, source, target)
    action.perform()
    assert target.exists()

    if source_action == SourceAction.MOVE:
        assert not source.exists()
Exemple #6
0
def test_action_directory_to_new_directory(fs, source_action):
    source = Path('/from/some-directory')
    target = Path('/to/some-directory')
    fs.create_dir(str(source))
    fs.create_file(str(source / 'example.txt'))
    fs.create_dir(str(target.parent))

    action = Action(source_action, source, target)
    action.perform()

    assert target.exists()

    # test also if moved
    if source_action == SourceAction.MOVE:
        assert not source.exists()
Exemple #7
0
def test_action_copy_directory_to_existing_directory(fs, source_action):
    source = Path('/from/some-directory')
    target = Path('/to/another-directory')
    fs.create_dir(str(source))
    fs.create_file(str(source / 'example.txt'))
    fs.create_dir(str(target))

    action = Action(source_action, source, target)
    action.perform()

    assert (target / 'some-directory' / 'example.txt').exists()

    # test also if moved
    if source_action == SourceAction.MOVE:
        assert not source.exists()
Exemple #8
0
def test_ignore_inside_copy_or_move(source_action, fs):
    target_path = Path('/target-directory/example')
    fs.create_dir(target_path)

    source_path = Path('/source-directory/example')
    source_path_action = source_path / 'action'
    source_path_ignore = source_path / 'ignore' / 'me'
    fs.create_dir(source_path_action)
    fs.create_dir(source_path_ignore)

    actions = {
        source_path:
        Action(source_action, source_path, target_path, priority=0),
        source_path_ignore:
        Action(SourceAction.IGNORE, source_path_ignore, priority=1),
    }

    perform_actions(actions)

    assert (target_path / 'action').exists()
    assert not (target_path / 'ignore' / 'me').exists()
Exemple #9
0
def test_action_copy_file_like_directory_to_directory(fs):
    source_path = Path('/source/aFileWithoutExtension')
    target_path = Path('/target/directory')
    target_success = Path(target_path / 'aFileWithoutExtension')

    fs.create_file(source_path)
    fs.create_dir(target_path)

    Action(SourceAction.COPY, source_path, target_path).perform()

    assert target_success.exists()
    assert target_success.is_file()
Exemple #10
0
def test_encapsulated_ignore(fs):
    source_path = Path('/source')
    encapuslated_path = source_path / 'encapsulated' / 'directory'

    target_path = Path('/target')

    fs.create_dir(encapuslated_path)
    fs.create_dir(target_path)

    action = Action(SourceAction.COPY, source_path, target_path, 1)
    action.ignore_sub_folder(encapuslated_path)

    action.perform()

    assert target_path.exists()
    assert Path('/target/source/encapsulated').exists()
    assert not Path('/target/source/encapsulated/directory').exists()