1
from axiom.store import Store
3
from twisted.python.filepath import FilePath
4
from twisted.trial.unittest import TestCase
6
from renamer import errors, history, irenamer
7
from renamer.plugins.actions import SymlinkAction
16
class FakeAction(object):
17
def do(self, options):
21
def undo(self, options):
26
class HistoryTests(TestCase):
28
Tests for L{renamer.history.History}.
32
self.history = history.History(store=self.store)
35
def test_newChangeset(self):
37
L{renamer.history.History.newChangeset} creates a new changeset
38
instance and does not track it immediately.
40
cs = self.history.newChangeset()
41
self.assertIdentical(type(cs), history.Changeset)
42
self.assertEquals(list(self.history.getChangesets()), [])
45
def test_pruneChangesets(self):
47
L{renamer.history.History.pruneChangesets} removes empty changesets
48
(changesets without any actions) from the database.
50
cs = self.history.newChangeset()
51
self.assertEquals(list(self.history.getChangesets()), [])
53
action = cs.newAction(
54
u'fake', FilePath(u'src'), FilePath(u'dst'), verify=False)
58
u'fake', FilePath(u'src'), FilePath(u'dst'), verify=False)
60
self.assertEquals(list(cs.getActions()), [])
61
self.assertEquals(cs.numActions, 0)
66
cs.do(action, FakeOptions(), _adapter=_adapter)
69
list(cs.getActions()), [action])
70
self.assertEquals(cs.numActions, 1)
71
prunedChangesets, prunedActions = self.history.pruneChangesets()
72
self.assertEquals(prunedChangesets, 0)
73
self.assertEquals(prunedActions, 1)
74
self.assertEquals(list(self.history.getChangesets()), [cs])
76
cs.undo(action, FakeOptions(), _adapter=_adapter)
77
self.assertEquals(list(cs.getActions()), [])
78
self.assertEquals(cs.numActions, 0)
79
prunedChangesets, prunedActions = self.history.pruneChangesets()
80
self.assertEquals(prunedChangesets, 1)
81
self.assertEquals(prunedActions, 0)
82
self.assertEquals(list(self.history.getChangesets()), [])
86
class ChangesetTests(TestCase):
88
Tests for L{renamer.history.Changeset}.
92
self.history = history.History(store=self.store)
95
def test_newInvalidAction(self):
97
L{renamer.history.Changeset.newAction} raises
98
L{renamer.errors.NoSuchAction} if the action name specified does not
99
refer to a valid action.
101
cs = self.history.newChangeset()
102
self.assertRaises(errors.NoSuchAction,
103
cs.newAction, 'THIS_IS_NOT_REAL', FilePath(u'a'), FilePath(u'b'))
106
def test_representations(self):
108
L{renamer.history.Changeset.asHumanly} returns a human-readable and
109
accurate representation of a changeset.
111
L{renamer.history.Changeset.__repr__} returns a useful and accurate
112
representation of a changeset.
114
cs = self.history.newChangeset()
117
cs.asHumanly().startswith(
118
u'Changeset with 0 action(s) ('))
122
'<Changeset 0 action(s) created=%r modified=%r>' % (
123
cs.created, cs.modified))
125
action = cs.newAction(
126
u'fake', FilePath(u'src'), FilePath(u'dst'), verify=False)
128
def _adapter(action):
131
cs.do(action, FakeOptions(), _adapter=_adapter)
134
cs.asHumanly().startswith(
135
u'Changeset with 1 action(s) ('))
139
'<Changeset 1 action(s) created=%r modified=%r>' % (
140
cs.created, cs.modified))
144
class ActionTests(TestCase):
146
Tests for L{renamer.history.Action}.
150
self.history = history.History(store=self.store)
153
def test_adaption(self):
155
Adapting a L{renamer.history.Action} object to
156
L{renamer.irenamer.IRenamingAction} results in an object implementing
157
C{IRenamingAction} that can perform forward and reverse actions.
159
cs = self.history.newChangeset()
160
action = cs.newAction(u'symlink', FilePath(u'src'), FilePath(u'dst'))
161
a = irenamer.IRenamingAction(action)
162
self.assertIdentical(type(a), SymlinkAction)
163
self.assertTrue(irenamer.IRenamingAction.providedBy(type(a)))
166
def test_representations(self):
168
L{renamer.history.Action.asHumanly} returns a human-readable and
169
accurate representation of an action.
171
L{renamer.history.Action.__repr__} returns a useful and accurate
172
representation of an action.
174
cs = self.history.newChangeset()
175
src = FilePath(u'src')
176
dst = FilePath(u'dst')
177
action = cs.newAction(u'fake', src, dst, verify=False)
180
action.asHumanly().startswith(
181
u'Fake: %s => %s (' % (src.path, dst.path)))
185
'<Action name=%r src=%r dst=%r created=%r>' % (
186
action.name, action.src, action.dst, action.created))