def test_commit7(self): """test commit (local state: 'A')""" path = self.fixture_file('prj1') tl = TL(abort=False) tl_abort = TL(abort=True) prj = Project(path, transaction_listener=[tl, tl_abort]) pkg = prj.package('added') self.assertEqual(pkg.status('foo'), 'A') self.assertEqual(prj._status('added'), 'A') prj.commit('added') # this time no abort tl = TL(abort=False) prj = Project(path, transaction_listener=[tl]) pkg = prj.package('added') self.assertEqual(pkg.status('foo'), 'A') self.assertEqual(prj._status('added'), 'A') prj.commit('added') self.assertEqual(prj._status('added'), ' ') pkg = prj.package('added') self.assertEqual(pkg.status('foo'), ' ') self._exists(path, '.osc', 'data', 'added') # check transaction listener self.assertEqual(tl._begin, ['prj_commit', 'commit']) self.assertEqual(tl._finished, ['commit', 'prj_commit']) self.assertEqual(tl._transfer, [('upload', 'foo')]) self.assertEqual(set(tl._processed.keys()), set(['foo', 'added'])) self.assertEqual(tl._processed['foo'], (' ', 'A')) self.assertEqual(tl._processed['added'], (' ', 'A'))
def test_project1(self): """test project convert""" path = self.fixture_file('project_1') self.assertRaises(WCFormatVersionError, Project, path) self.assertRaises(WCInconsistentError, Project, path, verify_format=False) self._not_exists(path, 'data', store=True) convert_project(path) self._exists(path, 'data', store=True) self._exists(path, 'foo', data=True) self._exists(path, 'added', data=True) self._exists(path, 'deleted', data=True) os.path.islink(os.path.join(path, 'foo', '.osc')) os.path.islink(os.path.join(path, 'added', '.osc')) os.path.islink(os.path.join(path, 'deleted', '.osc')) prj = Project(path) pkg = prj.package('foo') self.assertEqual(pkg.files(), ['file', 'deleted', 'modified', 'added', 'added2']) pkg = prj.package('added') self.assertEqual(pkg.files(), ['add']) pkg = prj.package('deleted') self.assertEqual(pkg.files(), ['deleted'])
def test_commit6(self): """test commit (package with a conflicted file)""" path = self.fixture_file('prj3') prj = Project(path) pkg = prj.package('conflict') self.assertEqual(pkg.status('conflict'), 'C') self.assertEqual(prj._status('conflict'), ' ') self.assertRaises(FileConflictError, prj.commit, 'conflict') self.assertEqual(prj._status('conflict'), ' ') pkg = prj.package('conflict') self.assertEqual(pkg.status('conflict'), 'C')
def test_commit4(self): """test commit (same as test_commit4 but remote package exists)""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('bar') self.assertEqual(pkg.status('add'), 'A') self.assertEqual(prj._status('bar'), 'A') prj.commit('bar') self.assertEqual(prj._status('bar'), ' ') pkg = prj.package('bar') self.assertEqual(pkg.status('add'), ' ') self._exists(path, '.osc', 'data', 'bar')
def test_update8(self): """test update (package with a conflicted file)""" path = self.fixture_file('prj3') prj = Project(path) pkg = prj.package('conflict') self.assertEqual(pkg.status('conflict'), 'C') self.assertEqual(prj._status('conflict'), ' ') # Note: package conflict would be deleted (if update were possible) self.assertRaises(FileConflictError, prj.update, 'conflict') self.assertEqual(prj._status('conflict'), ' ') pkg = prj.package('conflict') self.assertEqual(pkg.status('conflict'), 'C')
def test_revert1(self): """revert modified package""" path = self.fixture_file('prj_revert') prj = Project(path) self.assertEqual(prj._status('modified'), ' ') pkg = prj.package('modified') self.assertEqual(pkg.status('add'), 'A') self.assertEqual(pkg.status('file'), 'M') prj.revert('modified') self.assertEqual(prj._status('modified'), ' ') pkg = prj.package('modified') self.assertEqual(pkg.status('add'), '?') self.assertEqual(pkg.status('file'), ' ')
def test_commit9(self): """test commit (specify file + comment; local state ' ')""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('foo_modified') self.assertEqual(pkg.status('file'), 'M') self.assertEqual(pkg.status('add'), 'A') self.assertEqual(prj._status('foo'), ' ') todo = {'foo_modified': ['file']} prj.commit(package_filenames=todo, comment='foo bar') self.assertEqual(prj._status('foo'), ' ') pkg = prj.package('foo_modified') self.assertEqual(pkg.status('file'), ' ') self.assertEqual(pkg.status('add'), 'A')
def test_commit2(self): """test commit (local state: 'A')""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('bar') self.assertEqual(pkg.status('add'), 'A') self.assertEqual(pkg.status('add2'), 'A') self.assertEqual(prj._status('bar'), 'A') prj.commit('bar') self.assertEqual(prj._status('bar'), ' ') pkg = prj.package('bar') self.assertEqual(pkg.status('add'), ' ') self.assertEqual(pkg.status('add2'), ' ') self._exists(path, '.osc', 'data', 'bar')
def test_commit1(self): """test commit (local state: ' ')""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('foo_modified') self.assertEqual(pkg.status('file'), 'M') self.assertEqual(pkg.status('add'), 'A') self.assertEqual(prj._status('foo'), ' ') prj.commit('foo_modified') self.assertEqual(prj._status('foo'), ' ') pkg = prj.package('foo_modified') self.assertEqual(pkg.status('file'), ' ') self.assertEqual(pkg.status('add'), ' ') self._not_exists(path, '.osc', '_transaction')
def test19(self): """test remove (all files removed)""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('foo') self.assertEqual(pkg.status('file'), ' ') self.assertEqual(prj._status('foo'), ' ') self._exists(path, 'foo', 'file') prj.remove('foo') self._exists(path, 'foo') self._not_exists(path, 'foo', 'file') self.assertEqual(prj._status('foo'), 'D') pkg = prj.package('foo') self.assertEqual(pkg.status('file'), 'D')
def test_commit12(self): """test commit (rollback update transaction)""" path = self.fixture_file('prj3_commit_rollback_update') self._exists(path, '.osc', '_transaction') # similar to test_commit6 - except that we rollback an update # transaction (behind the scenes) prj = Project(path) pkg = prj.package('conflict') self.assertEqual(pkg.status('conflict'), 'C') self.assertEqual(prj._status('conflict'), ' ') self.assertRaises(FileConflictError, prj.commit, 'conflict') self.assertEqual(prj._status('conflict'), ' ') pkg = prj.package('conflict') self.assertEqual(pkg.status('conflict'), 'C') self._not_exists(path, '.osc', '_transaction')
def test_commit10(self): """test commit (specify file + comment; local state 'A')""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('bar') self.assertEqual(pkg.status('add'), 'A') self.assertEqual(pkg.status('add2'), 'A') self.assertEqual(prj._status('bar'), 'A') todo = {'bar': ['add']} prj.commit(package_filenames=todo, comment='foo') self.assertEqual(prj._status('bar'), ' ') pkg = prj.package('bar') self.assertEqual(pkg.status('add'), ' ') self.assertEqual(pkg.status('add2'), 'A') self._exists(path, '.osc', 'data', 'bar')
def test_revert5(self): """revert a deleted package (dir does not exist)""" path = self.fixture_file('prj_revert') prj = Project(path) self.assertEqual(prj._status('del'), 'D') self._not_exists(path, 'del') prj.revert('del') self.assertEqual(prj._status('del'), ' ') self._exists(path, 'del') pkg = prj.package('del') self.assertEqual(pkg.status('file'), ' ')
def test_repair2(self): """test repair (missing pkg data; state ' ')""" path = self.fixture_file('inv3') self._not_exists(path, 'conflict', data=True) self.assertRaises(WCInconsistentError, Project, path) Project.repair(path) self.assertEqual(Project.wc_check(path), ([], '', [])) self._exists(path, 'conflict', data=True) prj = Project(path) self.assertEqual(prj._status('conflict'), ' ') self.assertIsNotNone(prj.package('conflict'))
def test_revert6(self): """revert a package whose storedir was deleted""" path = self.fixture_file('prj_revert') prj = Project(path) self.assertEqual(prj._status('modified_no_storedir'), ' ') self._not_exists(path, 'modified_no_storedir', '.osc') prj.revert('modified_no_storedir') self._exists(path, 'modified_no_storedir', '.osc') self.assertEqual(prj._status('modified_no_storedir'), ' ') pkg = prj.package('modified_no_storedir') self.assertEqual(pkg.status('add'), '?') self.assertEqual(pkg.status('file'), ' ')
def test_revert4(self): """revert a deleted package (dir exists)""" path = self.fixture_file('prj_revert') prj = Project(path) self.assertEqual(prj._status('deleted'), 'D') self._exists(path, 'deleted') pkg = prj.package('deleted') self.assertEqual(pkg.status('dummy'), 'D') self.assertEqual(pkg.status('foo'), 'D') self.assertEqual(pkg.status('modified'), 'D') self.assertEqual(pkg.status('untracked'), '?') prj.revert('deleted') self.assertEqual(prj._status('deleted'), ' ') self._exists(path, 'deleted') pkg = prj.package('deleted') self.assertEqual(pkg.status('dummy'), ' ') self.assertEqual(pkg.status('foo'), ' ') # this file is modified and its old state was 'D' # so the new state is 'M' (after the revert) self.assertEqual(pkg.status('modified'), 'M') # untracked files are kept self.assertEqual(pkg.status('untracked'), '?')
def test10_2(self): """test add (all files)""" path = self.fixture_file('project') pkg_path = os.path.join(path, 'added') os.mkdir(pkg_path) open(os.path.join(pkg_path, 'foo'), 'w').close() open(os.path.join(pkg_path, 'bar'), 'w').close() prj = Project(path) prj.add('added') self.assertEqual(prj._status('added'), 'A') self.assertTrue(os.path.islink(os.path.join(pkg_path, '.osc'))) pkg = prj.package('added') self.assertEqual(pkg.status('foo'), 'A') self.assertEqual(pkg.status('bar'), 'A')
def test_commit3(self): """test commit (local state: 'D')""" path = self.fixture_file('prj2') prj = Project(path) pkg = prj.package('abc') self.assertEqual(pkg.status('modified'), 'D') self.assertEqual(pkg.status('untracked'), '?') self.assertEqual(prj._status('abc'), 'D') prj.commit('abc') self.assertEqual(prj._status('abc'), '?') self._exists(path, 'abc') self._exists(path, 'abc', 'modified') self._exists(path, 'abc', 'untracked') self._not_exists(path, 'abc', '.osc') self._not_exists(path, '.osc', 'data', 'abc')