1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-14 16:26:13 +01:00
github.com_openSUSE_osc/tests/test_revertfiles.py

101 lines
3.2 KiB
Python
Raw Normal View History

import os
2010-08-25 13:50:49 +02:00
import osc.core
import osc.oscerr
2022-02-17 13:28:47 +01:00
from .common import OscTestCase
2010-08-25 13:50:49 +02:00
2022-02-17 13:28:47 +01:00
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'revertfile_fixtures')
2010-08-25 13:50:49 +02:00
def suite():
import unittest
return unittest.defaultTestLoader.loadTestsFromTestCase(TestRevertFiles)
2010-08-25 13:50:49 +02:00
class TestRevertFiles(OscTestCase):
def _get_fixtures_dir(self):
return FIXTURES_DIR
def testRevertUnchanged(self):
"""revert an unchanged file (state == ' ')"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self.assertRaises(osc.oscerr.OscIOError, p.revert, 'toadd2')
2010-08-25 13:50:49 +02:00
self._check_status(p, 'toadd2', '?')
def testRevertModified(self):
"""revert a modified file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('nochange')
self.__check_file('nochange')
self._check_status(p, 'nochange', ' ')
def testRevertAdded(self):
"""revert an added file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('toadd1')
self.assertTrue(os.path.exists('toadd1'))
self._check_addlist('replaced\naddedmissing\n')
2010-08-25 13:50:49 +02:00
self._check_status(p, 'toadd1', '?')
def testRevertDeleted(self):
"""revert a deleted file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('somefile')
self.__check_file('somefile')
2010-09-08 16:18:35 +02:00
self._check_deletelist('deleted\n')
2010-08-25 13:50:49 +02:00
self._check_status(p, 'somefile', ' ')
def testRevertMissing(self):
"""revert a missing (state == '!') file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('missing')
self.__check_file('missing')
self._check_status(p, 'missing', ' ')
def testRevertMissingAdded(self):
"""revert a missing file which was added to the wc"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('addedmissing')
self._check_addlist('toadd1\nreplaced\n')
self.assertRaises(osc.oscerr.OscIOError, p.status, 'addedmissing')
2010-08-25 13:50:49 +02:00
def testRevertReplaced(self):
"""revert a replaced (state == 'R') file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('replaced')
self.__check_file('replaced')
self._check_addlist('toadd1\naddedmissing\n')
2010-08-25 13:50:49 +02:00
self._check_status(p, 'replaced', ' ')
def testRevertConflict(self):
"""revert a file which is in the conflict state"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
p.revert('foo')
self.__check_file('foo')
self.assertFalse(os.path.exists(os.path.join('.osc', '_in_conflict')))
self._check_status(p, 'foo', ' ')
def testRevertSkipped(self):
"""revert a skipped file"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self.assertRaises(osc.oscerr.OscIOError, p.revert, 'skipped')
2010-08-25 13:50:49 +02:00
def __check_file(self, fname):
storefile = os.path.join('.osc', fname)
self.assertTrue(os.path.exists(fname))
self.assertTrue(os.path.exists(storefile))
2022-08-24 08:43:09 +02:00
self.assertFilesEqual(fname, storefile)
2010-08-25 13:50:49 +02:00
if __name__ == '__main__':
import unittest
unittest.main()