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 = list(tl._processed.keys()) keys.sort() self.assertEqual(keys, ['file', 'foo']) self.assertEqual(tl._processed['file'], (' ', None)) self.assertEqual(tl._processed['foo'], (' ', None))
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))
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')
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')
def _checkout(info): path = os.path.join(os.getcwd(), info.project) if not os.path.exists(path): Project.init(path, info.project, info.apiurl) packages = [] if hasattr(info, 'package'): packages.append(info.package) prj = Project(path, transaction_listener=[MyTransactionListener()]) prj.update(*packages)
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')
def test_update6(self): """test update (finish pending add transaction)""" path = self.fixture_file('prj1_update_resume') self._exists(path, '.osc', '_transaction') prj = Project(path, finish_pending_transaction=False) 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') self._not_exists(path, '.osc', '_transaction')
def _update(info): path = os.getcwd() par_path = os.path.join(path, os.pardir) expand = '' if hasattr(info, 'expand'): expand = info.expand if hasattr(info, 'package') and not wc_is_project(par_path): pkg = Package(path, transaction_listner=[MyTransactionListener()]) pkg.update(expand=expand) elif hasattr(info, 'package') and wc_is_project(par_path): prj = Project(par_path, transaction_listener=[MyTransactionListener()]) prj.update(*[info.package], expand=expand) elif wc_is_project(path): prj = Project(path, transaction_listener=[MyTransactionListener()]) prj.update(expand=expand)
def test_update2(self): """test update (delete package; local state 'D')""" path = self.fixture_file('prj2') self._exists(path, 'abc') self._exists(path, 'abc', 'modified') self._exists(path, 'abc', 'untracked') self._exists(path, 'abc', '.osc') self._exists(path, '.osc', 'data', 'abc') prj = Project(path) self.assertEqual(prj._status('abc'), 'D') prj.update('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')
def test_update4(self): """test update (delete package: local state ' ')""" path = self.fixture_file('prj2') # 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) self._exists(path, 'foo') self._exists(path, '.osc', 'data', 'foo') prj = Project(path, transaction_listener=[tl]) self.assertEqual(prj._status('foo'), ' ') prj.update('foo') self.assertEqual(prj._status('foo'), '?') self._not_exists(path, 'foo') self._not_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, []) keys = list(tl._processed.keys()) keys.sort() self.assertEqual(keys, ['file', 'foo']) self.assertEqual(tl._processed['file'], (None, ' ')) self.assertEqual(tl._processed['foo'], (None, ' '))
def test_update4(self): """test update (delete package: local state ' ')""" path = self.fixture_file('prj2') # 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) self._exists(path, 'foo') self._exists(path, '.osc', 'data', 'foo') prj = Project(path, transaction_listener=[tl]) self.assertEqual(prj._status('foo'), ' ') prj.update('foo') self.assertEqual(prj._status('foo'), '?') self._not_exists(path, 'foo') self._not_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, []) keys = tl._processed.keys() keys.sort() self.assertEqual(keys, ['file', 'foo']) self.assertEqual(tl._processed['file'], (None, ' ')) self.assertEqual(tl._processed['foo'], (None, ' '))
def test_update9(self): """test update (with project transaction_listener)""" path = self.fixture_file('prj2') tl = ProjectTL() prj = Project(path, transaction_listener=[tl]) self.assertEqual(prj._status('add'), '?') self.assertEqual(prj._status('abc'), 'D') self.assertEqual(prj._status('foo'), ' ') prj.update('foo', 'abc', 'add') # check status after update self.assertEqual(prj._status('add'), ' ') self.assertEqual(prj._status('foo'), ' ') self.assertEqual(prj._status('abc'), '?') self._not_exists(path, '.osc', '_transaction') # check transaction listener keys = list(tl._processed.keys()) keys.sort() self.assertEqual(keys, ['prj_update:abc', 'prj_update:add', 'prj_update:foo', 'update:added', 'update:dummy', 'update:file', 'update:foo', 'update:modified']) self.assertEqual(tl._begin, ['prj_update', 'update', 'update', 'update']) self.assertEqual(tl._finished, ['update', 'update', 'update', 'prj_update']) self.assertEqual(tl._transfer, [('download', 'file'), ('download', 'added')]) self.assertEqual(tl._processed['update:file'], (' ', None)) self.assertEqual(tl._processed['prj_update:add'], (' ', None)) # file belong to package foo self.assertEqual(tl._processed['update:added'], (' ', None)) self.assertEqual(tl._processed['prj_update:foo'], (' ', ' ')) # files belong to package abc self.assertEqual(tl._processed['update:dummy'], (None, 'D')) self.assertEqual(tl._processed['update:foo'], (None, 'D')) self.assertEqual(tl._processed['update:modified'], (None, 'D')) self.assertEqual(tl._processed['prj_update:abc'], (None, 'D'))
def test_update9(self): """test update (with project transaction_listener)""" path = self.fixture_file('prj2') tl = ProjectTL() prj = Project(path, transaction_listener=[tl]) self.assertEqual(prj._status('add'), '?') self.assertEqual(prj._status('abc'), 'D') self.assertEqual(prj._status('foo'), ' ') prj.update('foo', 'abc', 'add') # check status after update self.assertEqual(prj._status('add'), ' ') self.assertEqual(prj._status('foo'), ' ') self.assertEqual(prj._status('abc'), '?') self._not_exists(path, '.osc', '_transaction') # check transaction listener keys = tl._processed.keys() keys.sort() self.assertEqual(keys, ['prj_update:abc', 'prj_update:add', 'prj_update:foo', 'update:added', 'update:dummy', 'update:file', 'update:foo', 'update:modified']) self.assertEqual(tl._begin, ['prj_update', 'update', 'update', 'update']) self.assertEqual(tl._finished, ['update', 'update', 'update', 'prj_update']) self.assertEqual(tl._transfer, [('download', 'file'), ('download', 'added')]) self.assertEqual(tl._processed['update:file'], (' ', None)) self.assertEqual(tl._processed['prj_update:add'], (' ', None)) # file belong to package foo self.assertEqual(tl._processed['update:added'], (' ', None)) self.assertEqual(tl._processed['prj_update:foo'], (' ', ' ')) # files belong to package abc self.assertEqual(tl._processed['update:dummy'], (None, 'D')) self.assertEqual(tl._processed['update:foo'], (None, 'D')) self.assertEqual(tl._processed['update:modified'], (None, 'D')) self.assertEqual(tl._processed['prj_update:abc'], (None, 'D'))