Exemplo n.º 1
0
 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'))
Exemplo n.º 2
0
 def test_update5(self):
     """test update (add package)"""
     path = self.fixture_file('prj1')
     # it is ok to use the simple TL class because we have no
     # duplicate keys (for instance a package and a file with the same name)
     tl = TL(abort=False)
     tl_abort = TL(abort=True)
     prj = Project(path, transaction_listener=[tl, tl_abort])
     self._not_exists(path, 'foo')
     self.assertEqual(prj._status('foo'), '?')
     prj.update('foo')
     # no abort this time
     tl = TL(abort=False)
     prj = Project(path, transaction_listener=[tl])
     self._not_exists(path, 'foo')
     self.assertEqual(prj._status('foo'), '?')
     prj.update('foo')
     self.assertEqual(prj._status('foo'), ' ')
     self._exists(path, 'foo')
     self._exists(path, 'foo', 'file')
     self._exists(path, '.osc', 'data', 'foo')
     # check transaction listener
     self.assertEqual(tl._begin, ['prj_update', 'update'])
     self.assertEqual(tl._finished, ['update', 'prj_update'])
     self.assertEqual(tl._transfer, [('download', 'file')])
     keys = tl._processed.keys()
     keys.sort()
     self.assertEqual(keys, ['file', 'foo'])
     self.assertEqual(tl._processed['file'], (' ', None))
     self.assertEqual(tl._processed['foo'], (' ', None))
Exemplo n.º 3
0
 def test_commit5(self):
     """test commit (finish pending transaction (delete))"""
     path = self.fixture_file('prj2_commit_resume')
     prj = Project(path, finish_pending_transaction=False)
     self.assertEqual(prj._status('abc'), 'D')
     prj.commit('abc')
     self.assertEqual(prj._status('abc'), '?')
Exemplo n.º 4
0
 def test_commit11(self):
     """test commit (package in *packages and package_filenames)"""
     path = self.fixture_file('prj2')
     todo = {'bar': ['add']}
     prj = Project(path)
     self.assertRaises(ValueError, prj.commit, 'bar',
                       package_filenames=todo)
Exemplo n.º 5
0
 def test3(self):
     """read project"""
     path = self.fixture_file('prj1')
     prj = Project(path)
     self.assertEqual(prj.name, 'prj1')
     self.assertEqual(prj.apiurl, 'http://apiurl')
     self.assertTrue(len(prj.packages()) == 2)
Exemplo n.º 6
0
 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'])
Exemplo n.º 7
0
 def test_update1(self):
     """test update"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     self.assertEqual(prj._status('foo'), ' ')
     prj.update('foo', foo='bar')
     self.assertEqual(prj._status('foo'), ' ')
     self._not_exists(path, '.osc', '_transaction')
Exemplo n.º 8
0
 def test_update3(self):
     """test update (delete package; local state '!')"""
     path = self.fixture_file('prj2')
     self._not_exists(path, 'xxx')
     prj = Project(path)
     prj.update('xxx')
     self.assertEqual(prj._status('xxx'), '?')
     self._not_exists(path, '.osc', 'data', 'xxx')
Exemplo n.º 9
0
 def test_update7(self):
     """test update (finish pending add transaction auto)"""
     path = self.fixture_file('prj1_update_resume')
     self._not_exists(path, 'foo')
     prj = Project(path, finish_pending_transaction=True)
     self.assertEqual(prj._status('foo'), ' ')
     self._exists(path, 'foo')
     self._exists(path, 'foo', 'file')
     self._exists(path, '.osc', 'data', 'foo')
Exemplo n.º 10
0
 def test18(self):
     """test remove (also check if the files were removed)"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     self.assertEqual(prj._status('bar'), 'A')
     prj.remove('bar')
     self.assertEqual(prj._status('bar'), '?')
     self._not_exists(path, 'bar')
     self._not_exists(path, 'bar', data=True)
Exemplo n.º 11
0
 def test10_3(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)
     self.assertRaises(ValueError, prj.add, 'added', 'foo', no_files=True)
Exemplo n.º 12
0
 def test7(self):
     """test _calculate_updateinfo"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     uinfo = prj._calculate_updateinfo()
     self.assertEqual(uinfo.candidates, ['foo', 'abc'])
     self.assertEqual(uinfo.added, ['osc'])
     self.assertEqual(uinfo.deleted, ['del', 'foo_modified'])
     self.assertEqual(uinfo.conflicted, ['xxx'])
     self.assertEqual(uinfo.name, 'prj2')
Exemplo n.º 13
0
 def test8(self):
     """test _calculate_updateinfo 2"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     uinfo = prj._calculate_updateinfo()
     self.assertEqual(uinfo.candidates, ['foo', 'foo_modified'])
     self.assertEqual(uinfo.added, ['osc'])
     self.assertEqual(uinfo.deleted, ['abc', 'xxx', 'del'])
     # local state: A
     self.assertEqual(uinfo.conflicted, ['bar'])
Exemplo n.º 14
0
 def test_update10(self):
     """test update (rollback commit transaction)"""
     path = self.fixture_file('prj2_update_rollback_commit')
     self._exists(path, '.osc', '_transaction')
     # the rest is identical to test_update1
     prj = Project(path)
     self.assertEqual(prj._status('foo'), ' ')
     prj.update('foo', foo='bar')
     self.assertEqual(prj._status('foo'), ' ')
     self._not_exists(path, '.osc', '_transaction')
Exemplo n.º 15
0
 def test8_1(self):
     """test _calculate_updateinfo 3 (specify packages)"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     uinfo = prj._calculate_updateinfo('foo', 'osc', 'del')
     self.assertEqual(uinfo.candidates, ['foo'])
     self.assertEqual(uinfo.added, ['osc'])
     self.assertEqual(uinfo.deleted, ['del'])
     # no conflicts because bar shouldn't be added/updated
     self.assertEqual(uinfo.conflicted, [])
Exemplo n.º 16
0
 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'))
Exemplo n.º 17
0
 def test_repair1(self):
     """test repair (missing _project and storefile)"""
     path = self.fixture_file('inv1')
     self._not_exists(path, '_project', store=True)
     self.assertRaises(WCInconsistentError, Project, path)
     self.assertRaises(ValueError, Project.repair, path)
     Project.repair(path, project='inv1')
     self.assertEqual(Project.wc_check(path), ([], '', []))
     self._exists(path, '_project', store=True)
     prj = Project(path)
     self.assertEqual(prj.name, 'inv1')
Exemplo n.º 18
0
 def test6(self):
     """test _status"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     self.assertEqual(prj._status('foo'), ' ')
     self.assertEqual(prj._status('bar'), 'A')
     self.assertEqual(prj._status('abc'), 'D')
     self.assertEqual(prj._status('xxx'), '!')
     # del is not ! because it's also marked for deletion
     self.assertEqual(prj._status('del'), 'D')
     self.assertEqual(prj._status('asdf'), '?')
Exemplo n.º 19
0
 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')
Exemplo n.º 20
0
    def project_obj(self, *args, **kwargs):
        """Returns a Project object if possible.

        *args and **kwargs are optional arguments for Project's
        __init__ method. If no Project can be returned None is
        returned.

        """
        if self.project_path is None:
            return None
        return Project(self.project_path, *args, **kwargs)
Exemplo n.º 21
0
 def test14(self):
     """do not add deleted package"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     self.assertEqual(prj._status('abc'), 'D')
     pkg_dir = self.fixture_file('prj2', 'abc')
     shutil.rmtree(pkg_dir)
     os.mkdir(pkg_dir)
     self.assertEqual(prj._status('abc'), 'D')
     self.assertRaises(ValueError, prj.add, 'abc')
     self.assertEqual(prj._status('abc'), 'D')
Exemplo n.º 22
0
 def test9(self):
     """test _calculate_updateinfo 3 (empty package list)"""
     path = self.fixture_file('prj2')
     prj = Project(path)
     self.assertEqual(prj._status('bar'), 'A')
     uinfo = prj._calculate_updateinfo()
     self.assertEqual(uinfo.candidates, [])
     self.assertEqual(uinfo.added, [])
     self.assertEqual(uinfo.deleted, ['foo', 'abc', 'xxx', 'del',
                                      'foo_modified'])
     self.assertEqual(uinfo.conflicted, [])