def test_set_get_separate_transactions(self): with transaction.wrap() as trans: trans.add_message('dummy') trans.set_blob(['foo'], 'bar'.encode('utf-8')) self.assert_file_exists('foo') with transaction.wrap() as trans: eq_(trans.get_blob(['foo']).decode('utf-8'), 'bar') self.assert_file_exists('foo')
def __get__(self, instance, owner): if instance is None: return self with transaction.wrap() as trans: if instance.pk: return trans.stat(instance.path).updated_at return None
def test_wrap(self): with transaction.wrap() as trans: trans.set_blob(['foo'], 'bar'.encode('utf-8')) trans.add_message('foobar') self.assert_commit_count(0) self.assert_commit_count(1) self.assert_file_exists('foo')
def init_repo(): from git_orm import transaction if is_repo_initialized(): raise GitError('repository is already initialized') with transaction.wrap() as trans: tigetrc = pkg_resources.resource_string('tiget', 'data/tigetrc') trans.set_blob(['config', 'tigetrc'], tigetrc) trans.add_message('Initialize Repository')
def load_module(self, fullname): with transaction.wrap(): code = self.get_code(fullname) is_pkg = self.is_package(fullname) is_reload = fullname in sys.modules mod = sys.modules.setdefault(fullname, imp.new_module(fullname)) mod.__file__ = code.co_filename mod.__loader__ = self if is_pkg: path = '/'.join( [PATH_PREFIX, self.path, fullname.rpartition('.')[2]]) mod.__path__ = [path] mod.__package__ = fullname else: mod.__package__ = fullname.rpartition('.')[0] try: exec(code, mod.__dict__) except: if not is_reload: del sys.modules[fullname] raise return mod
def _inner(*args, **kwargs): try: with transaction.wrap(): return fn(*args, **kwargs) except GitError: raise ImportError()
def test_exists_separate_transaction(self): with transaction.wrap() as trans: trans.set_blob(['foo'], 'bar'.encode('utf-8')) trans.add_message('dummy') with transaction.wrap() as trans: ok_(trans.exists(['foo']))
def test_current(self): assert_raises(GitError, transaction.current) with transaction.wrap(): transaction.current() assert_raises(GitError, transaction.current)
def _foo(): with transaction.wrap() as trans: trans.set_blob(['foo'], 'bar'.encode('utf-8')) self.assert_commit_count(0) raise TestException()
def test_nochanges(self): with transaction.wrap(): pass self.assert_commit_count(0)
def _foo(): with transaction.wrap() as trans: trans.set_blob(['foo'], 'bar'.encode('utf-8')) raise TestException()
def test_list_blobs_separate_transaction(self): with transaction.wrap() as trans: trans.set_blob(['foo'], 'bar'.encode('utf-8')) trans.add_message('dummy') with transaction.wrap() as trans: eq_(trans.list_blobs([]), set(['foo']))
def create_file(self, path, id_): with transaction.wrap() as trans: trans.set_blob( path.lstrip('/').split('/'), 'ID = {!r}'.format(id_).encode('utf-8')) trans.add_message('create file {}'.format(path))
def test_exists(self): with transaction.wrap() as trans: trans.add_message('dummy') trans.set_blob(['foo'], 'bar'.encode('utf-8')) ok_(trans.exists(['foo']))