-
-
Notifications
You must be signed in to change notification settings - Fork 707
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for known issues with snapshot
- Loading branch information
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2014 Thomas Amland <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import pytest | ||
from functools import partial | ||
from .shell import mkdtemp, mkdir, touch, mv | ||
from watchdog.utils.dirsnapshot import DirectorySnapshot | ||
from watchdog.utils.dirsnapshot import DirectorySnapshotDiff | ||
from watchdog.utils import platform | ||
|
||
|
||
skip_if_windows = pytest.mark.skipif(platform.is_windows(), | ||
reason="Can't detect moves on windows file systems") | ||
|
||
|
||
@pytest.fixture() | ||
def tmpdir(): | ||
return mkdtemp() | ||
|
||
|
||
@pytest.fixture() | ||
def p(tmpdir, *args): | ||
""" | ||
Convenience function to join the temporary directory path | ||
with the provided arguments. | ||
""" | ||
return partial(os.path.join, tmpdir) | ||
|
||
|
||
def test_move_to(p): | ||
mkdir(p('dir1')) | ||
mkdir(p('dir2')) | ||
touch(p('dir1', 'a')) | ||
ref = DirectorySnapshot(p('dir2')) | ||
mv(p('dir1/a'), p('dir2/b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p('dir2'))) | ||
assert diff.files_created == [p('dir2/b')] | ||
|
||
|
||
def test_move_from(p): | ||
mkdir(p('dir1')) | ||
mkdir(p('dir2')) | ||
touch(p('dir1', 'a')) | ||
ref = DirectorySnapshot(p('dir1')) | ||
mv(p('dir1/a'), p('dir2/b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p('dir1'))) | ||
assert diff.files_deleted == [p('dir1/a')] | ||
|
||
|
||
@pytest.mark.skipif(not platform.is_windows(), reason="Should detect moves instead") | ||
def test_move_on_windows(p): | ||
touch(p('a')) | ||
ref = DirectorySnapshot(p('')) | ||
mv(p('a'), p('b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p(''))) | ||
assert diff.files_created == [p('b')] | ||
assert diff.files_deleted == [p('a')] | ||
|
||
|
||
@skip_if_windows | ||
def test_move_internal(p): | ||
mkdir(p('dir1')) | ||
mkdir(p('dir2')) | ||
touch(p('dir1', 'a')) | ||
ref = DirectorySnapshot(p('')) | ||
mv(p('dir1/a'), p('dir2/b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p(''))) | ||
assert diff.files_moved == [(p('dir1/a'), p('dir2/b'))] | ||
assert diff.files_created == [] | ||
assert diff.files_deleted == [] | ||
assert diff.files_modified == [] | ||
|
||
|
||
@skip_if_windows | ||
def test_move_replace(p): | ||
mkdir(p('dir1')) | ||
mkdir(p('dir2')) | ||
touch(p('dir1', 'a')) | ||
touch(p('dir1', 'b')) | ||
ref = DirectorySnapshot(p('')) | ||
mv(p('dir1/a'), p('dir2/b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p(''))) | ||
assert diff.files_moved == [(p('dir1/a'), p('dir2/b'))] | ||
assert diff.files_deleted == [p('dir2/b')] | ||
assert diff.files_created == [] | ||
assert diff.files_modified == [] | ||
|
||
|
||
def test_dir_modify_on_create(p): | ||
ref = DirectorySnapshot(p('')) | ||
touch(p('a')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p(''))) | ||
assert diff.dirs_modified == [p('')] | ||
|
||
|
||
def test_dir_modify_on_move(p): | ||
mkdir(p('dir1')) | ||
mkdir(p('dir2')) | ||
touch(p('dir1', 'a')) | ||
ref = DirectorySnapshot(p('')) | ||
mv(p('dir1/a'), p('dir2/b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p(''))) | ||
assert set(diff.dirs_modified) == set([p('dir1'), p('dir2')]) | ||
|
||
|
||
@skip_if_windows | ||
def test_detect_modify_on_moved(p): | ||
touch(p('a')) | ||
ref = DirectorySnapshot(p('')) | ||
touch(p('a')) | ||
mv(p('a'), p('b')) | ||
diff = DirectorySnapshotDiff(ref, DirectorySnapshot(p(''))) | ||
assert diff.files_moved == [(p('a'), p('b'))] | ||
assert diff.files_modified == [p('b')] |