5 from common import GET, OscTestCase
7 FIXTURES_DIR = os.path.join(os.getcwd(), 'deletefile_fixtures')
11 return unittest.makeSuite(TestDeleteFiles)
13 class TestDeleteFiles(OscTestCase):
14 def _get_fixtures_dir(self):
17 def testSimpleRemove(self):
18 """delete a file ('foo') from the wc"""
19 self._change_to_pkg('simple')
20 p = osc.core.Package('.')
21 ret = p.delete_file('foo')
22 self.__check_ret(ret, True, ' ')
23 self.assertFalse(os.path.exists('foo'))
24 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
25 self._check_deletelist('foo\n')
26 self._check_status(p, 'foo', 'D')
28 def testDeleteModified(self):
29 """delete modified file ('nochange') from the wc (without force)"""
30 self._change_to_pkg('simple')
31 p = osc.core.Package('.')
32 ret = p.delete_file('nochange')
33 self.__check_ret(ret, False, 'M')
34 self.assertTrue(os.path.exists('nochange'))
35 self.assertTrue(os.path.exists(os.path.join('.osc', 'nochange')))
36 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
37 self._check_status(p, 'nochange', 'M')
39 def testDeleteUnversioned(self):
40 """delete an unversioned file ('toadd2') from the wc"""
41 self._change_to_pkg('simple')
42 p = osc.core.Package('.')
43 ret = p.delete_file('toadd2')
44 self.__check_ret(ret, False, '?')
45 self.assertTrue(os.path.exists('toadd2'))
46 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
47 self._check_status(p, 'toadd2', '?')
49 def testDeleteAdded(self):
50 """delete an added file ('toadd1') from the wc (without force)"""
51 self._change_to_pkg('simple')
52 p = osc.core.Package('.')
53 ret = p.delete_file('toadd1')
54 self.__check_ret(ret, False, 'A')
55 self.assertTrue(os.path.exists('toadd1'))
56 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
57 self._check_status(p, 'toadd1', 'A')
59 def testDeleteReplaced(self):
60 """delete an added file ('merge') from the wc (without force)"""
61 self._change_to_pkg('replace')
62 p = osc.core.Package('.')
63 ret = p.delete_file('merge')
64 self.__check_ret(ret, False, 'R')
65 self.assertTrue(os.path.exists('merge'))
66 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
67 self._check_addlist('toadd1\nmerge\n')
68 self._check_status(p, 'merge', 'R')
70 def testDeleteConflict(self):
71 """delete a file ('foo', state='C') from the wc (without force)"""
72 self._change_to_pkg('conflict')
73 p = osc.core.Package('.')
74 ret = p.delete_file('foo')
75 self.__check_ret(ret, False, 'C')
76 self.assertTrue(os.path.exists('foo'))
77 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
78 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
79 self._check_conflictlist('foo\n')
80 self._check_status(p, 'foo', 'C')
82 def testDeleteModifiedForce(self):
83 """force deletion modified file ('nochange') from wc"""
84 self._change_to_pkg('simple')
85 p = osc.core.Package('.')
86 ret = p.delete_file('nochange', force=True)
87 self.__check_ret(ret, True, 'M')
88 self.assertFalse(os.path.exists('nochange'))
89 self.assertTrue(os.path.exists(os.path.join('.osc', 'nochange')))
90 self._check_deletelist('nochange\n')
91 self._check_status(p, 'nochange', 'D')
93 def testDeleteUnversionedForce(self):
94 """delete an unversioned file ('toadd2') from the wc (with force)"""
95 self._change_to_pkg('simple')
96 p = osc.core.Package('.')
97 ret = p.delete_file('toadd2', force=True)
98 self.__check_ret(ret, True, '?')
99 self.assertFalse(os.path.exists('toadd2'))
100 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
101 self.assertRaises(osc.oscerr.OscIOError, p.status, 'toadd2')
103 def testDeleteAddedForce(self):
104 """delete an added file ('toadd1') from the wc (with force)"""
105 self._change_to_pkg('simple')
106 p = osc.core.Package('.')
107 ret = p.delete_file('toadd1', force=True)
108 self.__check_ret(ret, True, 'A')
109 self.assertFalse(os.path.exists('toadd1'))
110 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
111 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
112 self.assertRaises(osc.oscerr.OscIOError, p.status, 'toadd1')
114 def testDeleteReplacedForce(self):
115 """delete an added file ('merge') from the wc (with force)"""
116 self._change_to_pkg('replace')
117 p = osc.core.Package('.')
118 ret = p.delete_file('merge', force=True)
119 self.__check_ret(ret, True, 'R')
120 self.assertFalse(os.path.exists('merge'))
121 self.assertTrue(os.path.exists(os.path.join('.osc', 'merge')))
122 self._check_deletelist('merge\n')
123 self._check_addlist('toadd1\n')
124 self._check_status(p, 'merge', 'D')
126 def testDeleteConflictForce(self):
127 """delete a file ('foo', state='C') from the wc (with force)"""
128 self._change_to_pkg('conflict')
129 p = osc.core.Package('.')
130 ret = p.delete_file('foo', force=True)
131 self.__check_ret(ret, True, 'C')
132 self.assertFalse(os.path.exists('foo'))
133 self.assertTrue(os.path.exists('foo.r2'))
134 self.assertTrue(os.path.exists('foo.mine'))
135 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
136 self._check_deletelist('foo\n')
137 self.assertFalse(os.path.exists(os.path.join('.osc', '_in_conflict')))
138 self._check_status(p, 'foo', 'D')
140 def testDeleteMultiple(self):
141 """delete mutliple files from the wc"""
142 self._change_to_pkg('simple')
143 p = osc.core.Package('.')
144 ret = p.delete_file('foo')
145 self.__check_ret(ret, True, ' ')
146 ret = p.delete_file('merge')
147 self.__check_ret(ret, True, ' ')
148 self.assertFalse(os.path.exists('foo'))
149 self.assertFalse(os.path.exists('merge'))
150 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
151 self.assertTrue(os.path.exists(os.path.join('.osc', 'merge')))
152 self._check_deletelist('foo\nmerge\n')
154 def testDeleteAlreadyDeleted(self):
155 """delete already deleted file from the wc"""
156 self._change_to_pkg('already_deleted')
157 p = osc.core.Package('.')
158 ret = p.delete_file('foo')
159 self.__check_ret(ret, True, 'D')
160 self.assertFalse(os.path.exists('foo'))
161 self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
162 self._check_deletelist('foo\n')
163 self._check_status(p, 'foo', 'D')
165 def testDeleteAddedMissing(self):
167 delete a file which was added to the wc and is removed again
168 (via a non osc command). It's current state is '!'
170 self._change_to_pkg('delete')
171 p = osc.core.Package('.')
172 ret = p.delete_file('toadd1')
173 self.__check_ret(ret, True, '!')
174 self.assertFalse(os.path.exists('toadd1'))
175 self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
176 self._check_deletelist('foo\n')
177 self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
179 def __check_ret(self, ret, exp1, exp2):
180 self.assertTrue(len(ret) == 2)
181 self.assertTrue(ret[0] == exp1)
182 self.assertTrue(ret[1] == exp2)
184 if __name__ == '__main__':