1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 09:16:16 +02:00

- moved common methods into the OscTestCase class

This commit is contained in:
Marcus Huewe 2010-08-25 11:20:25 +02:00
parent 3fefbfbc5f
commit 62dc807378
4 changed files with 25 additions and 22 deletions

View File

@ -89,10 +89,19 @@ class OscTestCase(unittest.TestCase):
def _change_to_pkg(self, name):
os.chdir(os.path.join(self.tmpdir, 'osctest', name))
def _check_list(self, fname, exp):
def __check_list(self, fname, exp):
fname = os.path.join('.osc', fname)
self.assertTrue(os.path.exists(fname))
self.assertEqual(open(fname, 'r').read(), exp)
def _check_addlist(self, exp):
self.__check_list('_to_be_added', exp)
def _check_deletelist(self, exp):
self.__check_list('_to_be_deleted', exp)
def _check_conflictlist(self, exp):
self.__check_list('_in_conflict', exp)
def _check_status(self, p, fname, exp):
self.assertEqual(p.status(fname), exp)

View File

@ -23,7 +23,7 @@ class TestAddFiles(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
self._check_status(p, 'toadd1', 'A')
self.__check_addlist('toadd1\n')
self._check_addlist('toadd1\n')
def testSimpleMultipleAdd(self):
"""add multiple files ('toadd1', 'toadd2') to the wc"""
@ -37,7 +37,7 @@ class TestAddFiles(OscTestCase):
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd2')))
self._check_status(p, 'toadd1', 'A')
self._check_status(p, 'toadd2', 'A')
self.__check_addlist('toadd1\ntoadd2\n')
self._check_addlist('toadd1\ntoadd2\n')
def testAddVersionedFile(self):
"""add a versioned file"""
@ -57,7 +57,7 @@ class TestAddFiles(OscTestCase):
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertFalse(os.path.exists(os.path.join('.osc', 'toadd1')))
self._check_status(p, 'toadd1', 'A')
self.__check_addlist('toadd1\n')
self._check_addlist('toadd1\n')
def testReplace(self):
"""replace a deleted file ('foo')"""
@ -71,7 +71,7 @@ class TestAddFiles(OscTestCase):
self.assertNotEqual(open(os.path.join('.osc', 'foo'), 'r').read(), 'replaced file\n')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self._check_status(p, 'foo', 'R')
self.__check_addlist('foo\n')
self._check_addlist('foo\n')
def testAddNonExistentFile(self):
"""add a non existent file"""
@ -80,9 +80,6 @@ class TestAddFiles(OscTestCase):
self.assertRaises(IOError, p.addfile, 'doesnotexist')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
def __check_addlist(self, exp):
self._check_list('_to_be_added', exp)
if __name__ == '__main__':
import unittest
unittest.main()

View File

@ -22,7 +22,7 @@ class TestDeleteFiles(OscTestCase):
self.__check_ret(ret, True, ' ')
self.assertFalse(os.path.exists('foo'))
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
self.__check_deletelist('foo\n')
self._check_deletelist('foo\n')
self._check_status(p, 'foo', 'D')
def testDeleteModified(self):
@ -64,7 +64,7 @@ class TestDeleteFiles(OscTestCase):
self.__check_ret(ret, False, 'R')
self.assertTrue(os.path.exists('merge'))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self._check_list('_to_be_added', 'toadd1\nmerge\n')
self._check_addlist('toadd1\nmerge\n')
self._check_status(p, 'merge', 'R')
def testDeleteConflict(self):
@ -87,7 +87,7 @@ class TestDeleteFiles(OscTestCase):
self.__check_ret(ret, True, 'M')
self.assertFalse(os.path.exists('nochange'))
self.assertTrue(os.path.exists(os.path.join('.osc', 'nochange')))
self.__check_deletelist('nochange\n')
self._check_deletelist('nochange\n')
self._check_status(p, 'nochange', 'D')
def testDeleteUnversionedForce(self):
@ -119,8 +119,8 @@ class TestDeleteFiles(OscTestCase):
self.__check_ret(ret, True, 'R')
self.assertFalse(os.path.exists('merge'))
self.assertTrue(os.path.exists(os.path.join('.osc', 'merge')))
self.__check_deletelist('merge\n')
self._check_list('_to_be_added', 'toadd1\n')
self._check_deletelist('merge\n')
self._check_addlist('toadd1\n')
self._check_status(p, 'merge', 'D')
def testDeleteConflictForce(self):
@ -133,7 +133,7 @@ class TestDeleteFiles(OscTestCase):
self.assertTrue(os.path.exists('foo.r2'))
self.assertTrue(os.path.exists('foo.mine'))
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
self.__check_deletelist('foo\n')
self._check_deletelist('foo\n')
self.assertFalse(os.path.exists(os.path.join('.osc', '_in_conflict')))
self._check_status(p, 'foo', 'D')
@ -149,7 +149,7 @@ class TestDeleteFiles(OscTestCase):
self.assertFalse(os.path.exists('merge'))
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
self.assertTrue(os.path.exists(os.path.join('.osc', 'merge')))
self.__check_deletelist('foo\nmerge\n')
self._check_deletelist('foo\nmerge\n')
def testDeleteAlreadyDeleted(self):
"""delete already deleted file from the wc"""
@ -159,7 +159,7 @@ class TestDeleteFiles(OscTestCase):
self.__check_ret(ret, True, 'D')
self.assertFalse(os.path.exists('foo'))
self.assertTrue(os.path.exists(os.path.join('.osc', 'foo')))
self.__check_deletelist('foo\n')
self._check_deletelist('foo\n')
self._check_status(p, 'foo', 'D')
def __check_ret(self, ret, exp1, exp2):
@ -167,9 +167,6 @@ class TestDeleteFiles(OscTestCase):
self.assertTrue(ret[0] == exp1)
self.assertTrue(ret[1] == exp2)
def __check_deletelist(self, exp):
self._check_list('_to_be_deleted', exp)
if __name__ == '__main__':
import unittest
unittest.main()

View File

@ -79,7 +79,7 @@ class TestUpdate(OscTestCase):
exp = 'C merge\nAt revision 2.\n'
self.__check_digests('testUpdateConflict_files')
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertEqual(open(os.path.join('.osc', '_in_conflict'), 'r').read(), 'merge\n')
self._check_conflictlist('merge\n')
@GET('http://localhost/source/osctest/already_in_conflict?rev=2', file='testUpdateAlreadyInConflict_files')
@GET('http://localhost/source/osctest/already_in_conflict/merge?rev=2', file='testUpdateAlreadyInConflict_merge')
@ -109,8 +109,8 @@ class TestUpdate(OscTestCase):
osc.core.Package('.').update(rev=2)
exp = 'U foo\nC merge\nAt revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertEqual(open(os.path.join('.osc', '_to_be_deleted'), 'r').read(), 'foo\n')
self.assertEqual(open(os.path.join('.osc', '_in_conflict'), 'r').read(), 'merge\n')
self._check_deletelist('foo\n')
self._check_conflictlist('merge\n')
self.assertEqual(open('foo', 'r').read(), open(os.path.join('.osc', 'foo'), 'r').read())
self.__check_digests('testUpdateLocalDeletions_files')