- bump version to 0.130.1
[opensuse:osc.git] / tests / test_revertfiles.py
1 import osc.core
2 import osc.oscerr
3 import os
4 import sys
5 from common import GET, OscTestCase
6
7 FIXTURES_DIR = os.path.join(os.getcwd(), 'revertfile_fixtures')
8
9 def suite():
10     import unittest
11     return unittest.makeSuite(TestRevertFiles)
12
13 class TestRevertFiles(OscTestCase):
14     def _get_fixtures_dir(self):
15         return FIXTURES_DIR
16
17     def testRevertUnchanged(self):
18         """revert an unchanged file (state == ' ')"""
19         self._change_to_pkg('simple')
20         p = osc.core.Package('.')
21         self.assertRaises(osc.oscerr.OscIOError, p.revert, 'toadd2')
22         self._check_status(p, 'toadd2', '?')
23
24     def testRevertModified(self):
25         """revert a modified file"""
26         self._change_to_pkg('simple')
27         p = osc.core.Package('.')
28         p.revert('nochange')
29         self.__check_file('nochange')
30         self._check_status(p, 'nochange', ' ')
31
32     def testRevertAdded(self):
33         """revert an added file"""
34         self._change_to_pkg('simple')
35         p = osc.core.Package('.')
36         p.revert('toadd1')
37         self.assertTrue(os.path.exists('toadd1'))
38         self._check_addlist('replaced\naddedmissing\n')
39         self._check_status(p, 'toadd1', '?')
40
41     def testRevertDeleted(self):
42         """revert a deleted file"""
43         self._change_to_pkg('simple')
44         p = osc.core.Package('.')
45         p.revert('somefile')
46         self.__check_file('somefile')
47         self._check_deletelist('deleted\n')
48         self._check_status(p, 'somefile', ' ')
49
50     def testRevertMissing(self):
51         """revert a missing (state == '!') file"""
52         self._change_to_pkg('simple')
53         p = osc.core.Package('.')
54         p.revert('missing')
55         self.__check_file('missing')
56         self._check_status(p, 'missing', ' ')
57
58     def testRevertMissingAdded(self):
59         """revert a missing file which was added to the wc"""
60         self._change_to_pkg('simple')
61         p = osc.core.Package('.')
62         p.revert('addedmissing')
63         self._check_addlist('toadd1\nreplaced\n')
64         self.assertRaises(osc.oscerr.OscIOError, p.status, 'addedmissing')
65
66     def testRevertReplaced(self):
67         """revert a replaced (state == 'R') file"""
68         self._change_to_pkg('simple')
69         p = osc.core.Package('.')
70         p.revert('replaced')
71         self.__check_file('replaced')
72         self._check_addlist('toadd1\naddedmissing\n')
73         self._check_status(p, 'replaced', ' ')
74
75     def testRevertConflict(self):
76         """revert a file which is in the conflict state"""
77         self._change_to_pkg('simple')
78         p = osc.core.Package('.')
79         p.revert('foo')
80         self.__check_file('foo')
81         self.assertFalse(os.path.exists(os.path.join('.osc', '_in_conflict')))
82         self._check_status(p, 'foo', ' ')
83
84     def testRevertSkipped(self):
85         """revert a skipped file"""
86         self._change_to_pkg('simple')
87         p = osc.core.Package('.')
88         self.assertRaises(osc.oscerr.OscIOError, p.revert, 'skipped')
89
90     def __check_file(self, fname):
91         storefile = os.path.join('.osc', fname)
92         self.assertTrue(os.path.exists(fname))
93         self.assertTrue(os.path.exists(storefile))
94         self.assertEqual(open(fname, 'r').read(), open(storefile, 'r').read())
95
96 if __name__ == '__main__':
97     import unittest
98     unittest.main()