1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
import os
import pytest
from dotfiles.dotfile import Dotfile
from dotfiles.repository import Repository
def test_getters():
repo = Repository('foo', 'bar')
assert isinstance(repo.homedir, str)
assert isinstance(repo.repodir, str)
def test_setters():
repodir = '/foo/bar'
homedir = '/fizz/buzz'
repo = Repository('foo', 'bar')
repo.repodir = repodir
repo.homedir = homedir
assert repodir == repo.repodir
assert homedir == repo.homedir
def test_custom_paths():
homedir = '/foo/bar'
repodir = '/fizz/buzz'
repo = Repository(repodir, homedir)
assert homedir == repo.homedir
assert repodir == repo.repodir
def test_path_expansion():
repo = Repository('~/foo', '~/bar')
assert os.path.expanduser('~/foo') == repo.repodir
assert os.path.expanduser('~/bar') == repo.homedir
def test_create_repo(tmpdir):
repodir = tmpdir.join("test_create_repo")
repodir.check(exists=0)
Repository(repodir)
repodir.check(exists=1, dir=1)
def test_empty_status(tmpdir):
repo = Repository(tmpdir.join("repo"))
assert '[no dotfiles found]' == repo.status()
def test_status_manual(tmpdir, monkeypatch):
repodir = tmpdir.join("Dotfiles", dir=1)
name = tmpdir.join(".vimrc")
target = repodir.ensure("vimrc")
dotfile = Dotfile(name, target)
repo = Repository(repodir, tmpdir)
monkeypatch.setattr(Repository, "_load",
lambda self: [dotfile, dotfile, dotfile])
expected_status = (".vimrc -> Dotfiles/vimrc (unknown)\n"
".vimrc -> Dotfiles/vimrc (unknown)\n"
".vimrc -> Dotfiles/vimrc (unknown)")
assert expected_status == repo.status()
def test_status_discover(tmpdir):
repodir = tmpdir.ensure("Dotfiles", dir=1)
tmpdir.join('.bashrc').mksymlinkto(repodir.ensure('bashrc'))
tmpdir.join('.inputrc').mksymlinkto(repodir.ensure('inputrc'))
tmpdir.join('.vimrc').mksymlinkto(repodir.ensure('vimrc'))
repo = Repository(repodir, tmpdir)
expected_status = (".bashrc -> Dotfiles/bashrc (unknown)\n"
".inputrc -> Dotfiles/inputrc (unknown)\n"
".vimrc -> Dotfiles/vimrc (unknown)")
assert expected_status == repo.status()
def test_check(tmpdir, monkeypatch):
repodir = tmpdir.join('repo')
dotfile_a = Dotfile(tmpdir.join('.aaa'), repodir.join('aaa'))
dotfile_b = Dotfile(tmpdir.join('.bbb'), repodir.join('bbb'))
dotfile_c = Dotfile(tmpdir.join('.ccc'), repodir.join('ccc'))
dotfile_b.state = '(ok)'
repo = Repository(tmpdir)
monkeypatch.setattr(Repository, "_load",
lambda self: [dotfile_a, dotfile_b, dotfile_c])
assert ('.aaa -> repo/aaa (unknown)\n'
'.ccc -> repo/ccc (unknown)') == repo.check()
def test_sync():
with pytest.raises(NotImplementedError):
Repository('todo').sync()
def test_unsync():
with pytest.raises(NotImplementedError):
Repository('todo').unsync()
def test_add():
with pytest.raises(NotImplementedError):
Repository('todo').add()
def test_remove():
with pytest.raises(NotImplementedError):
Repository('todo').remove()
def test_move():
with pytest.raises(NotImplementedError):
Repository('todo').move()
|