diff options
author | Jon Bernard <jbernard@tuxion.com> | 2016-01-22 08:54:19 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2016-01-22 08:54:19 -0500 |
commit | 0eadef7f8034dc07d6322b7afb8c51a17472011e (patch) | |
tree | b15b20f61c1cc617c88fa5fae8b82bd51caa7baa /tests/test_repository.py | |
parent | 252d359d0c937a8ff9801a3079c865b4c7abe448 (diff) | |
download | dotfiles-0eadef7f8034dc07d6322b7afb8c51a17472011e.tar.gz dotfiles-0eadef7f8034dc07d6322b7afb8c51a17472011e.tar.bz2 dotfiles-0eadef7f8034dc07d6322b7afb8c51a17472011e.zip |
Simplify test fixtures into a single repository
Diffstat (limited to 'tests/test_repository.py')
-rw-r--r-- | tests/test_repository.py | 114 |
1 files changed, 55 insertions, 59 deletions
diff --git a/tests/test_repository.py b/tests/test_repository.py index 05328e6..73d5315 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -6,98 +6,94 @@ from dotfiles.exceptions import NotRootedInHome, InRepository, TargetIgnored, \ IsDirectory -def test_repo_create(repo, home): - repo.remove() - assert repo.check(exists=0) - Repository(repo, home) - assert repo.check(exists=1, dir=1) +def test_repo_create(repo): + repo.path.remove() + assert repo.path.check(exists=0) + Repository(repo.path, repo.homedir) + assert repo.path.check(exists=1, dir=1) -def test_str(repo, home): - repo.ensure('.a') - repo.ensure('.b') - repo.ensure('.c') - - r = Repository(repo, home) - - assert str(r) == ( - '%s\n%s\n%s' % (home.join('.a'), - home.join('.b'), - home.join('.c'))) +def test_str(repo): + repo.path.ensure('a') + repo.path.ensure('b') + repo.path.ensure('c') + assert str(repo) == ( + '%s\n%s\n%s' % (repo.homedir.join('.a'), + repo.homedir.join('.b'), + repo.homedir.join('.c'))) @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) -def test_target_to_name(repo, home, path): - r = Repository(repo, home, dot=True) - assert r._target_to_name(repo.join(path)) == home.join(path) - - r = Repository(repo, home, dot=False) - assert r._target_to_name(repo.join(path)) == home.join('.%s' % path) +def test_dotfile_path(repo, path): + repo.preserve_leading_dot = True + assert (repo._dotfile_path(repo.path.join(path)) == + repo.homedir.join(path)) + repo.preserve_leading_dot = False + assert (repo._dotfile_path(repo.path.join(path)) == + repo.homedir.join('.%s' % path)) @pytest.mark.parametrize('path', ['.foo', '.foo/bar/baz']) -def test_name_to_target(repo, home, path): - r = Repository(repo, home, dot=True) - assert r._name_to_target(home.join(path)) == repo.join(path) - - r = Repository(repo, home, dot=False) - assert r._name_to_target(home.join(path)) == repo.join(path[1:]) +def test_dotfile_target(repo, path): + repo.preserve_leading_dot = True + assert (repo._dotfile_target(repo.homedir.join(path)) == + repo.path.join(path)) + repo.preserve_leading_dot = False + assert (repo._dotfile_target(repo.homedir.join(path)) == + repo.path.join(path[1:])) -def test_dotfile(repo, home): +def test_dotfile(repo): with pytest.raises(NotRootedInHome): - Repository(repo, home)._dotfile(py.path.local('/tmp/foo')) + repo._dotfile(py.path.local('/tmp/foo')) with pytest.raises(TargetIgnored): - Repository(repo, home, - ignore_patterns=['.foo'])._dotfile(home.join('.foo')) + repo.ignore_patterns = ['.foo'] + repo.preserve_leading_dot = True + repo._dotfile(py.path.local(repo.homedir.join('.foo'))) with pytest.raises(TargetIgnored): - Repository(repo, home, - ignore_patterns=['foo'])._dotfile(home.join('.bar/foo')) + repo.ignore_patterns = ['foo'] + repo._dotfile(repo.homedir.join('.bar/foo')) with pytest.raises(IsDirectory): - Repository(repo, home)._dotfile(home.ensure_dir('.config')) + repo._dotfile(repo.homedir.ensure_dir('.config')) - # The home fixture is parametrized, we can only expect InRepository + # The repo fixture is parametrized, we can only expect InRepository # exception when the repository is contained in the home directory. - if repo.dirname == home.basename: + if repo.path.dirname == repo.homedir.basename: with pytest.raises(InRepository): - Repository(repo, home)._dotfile(repo.join('.foo/bar')) + repo._dotfile(repo.path.join('.foo/bar')) - Repository(repo, home)._dotfile(home.join('.foo')) + repo._dotfile(repo.homedir.join('.foo')) -def test_dotfiles(repo, home): - file = home.join('.baz') - dir = home.ensure_dir('.dir') +def test_dotfiles(repo): + file = repo.homedir.join('.baz') + dir = repo.homedir.ensure_dir('.dir') dir.ensure('foo/bat') dir.ensure('foo/buz') dir.ensure('bar') dir.ensure('boo') - dotfiles = Repository(repo, home).dotfiles([str(file), str(dir)]) + dotfiles = repo.dotfiles([str(file), str(dir)]) assert len(dotfiles) == 5 -def test_contents(repo, home): - assert Repository(repo, home).contents() == [] +def test_contents(repo): + assert repo.contents() == [] - target_a = repo.ensure('a') - target_b = repo.ensure('b/b') - target_c = repo.ensure('c/c/c') - contents = Repository(repo, home).contents() + target_a = repo.path.ensure('a') + target_b = repo.path.ensure('b/b') + target_c = repo.path.ensure('c/c/c') + contents = repo.contents() assert contents[0].target == target_a assert contents[1].target == target_b assert contents[2].target == target_c -# TODO: Need tests for whatever-dot option - - -def test_prune(repo, home): - repo.ensure_dir('.a/a') - repo.ensure_dir('.b/b/b/b') - repo.ensure_dir('.c/c/c/c/c/c/c/c') - - Repository(repo, home).prune() +def test_prune(repo): + repo.path.ensure_dir('.a/a') + repo.path.ensure_dir('.b/b/b/b') + repo.path.ensure_dir('.c/c/c/c/c/c/c/c') - assert len(repo.listdir()) == 0 + repo.prune() + assert len(repo.path.listdir()) == 0 |