コード例 #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()
コード例 #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()
コード例 #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()
コード例 #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()
コード例 #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()
コード例 #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()
コード例 #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()
コード例 #8
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()