Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
 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')
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 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')
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
 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
Exemplo n.º 7
0
Arquivo: git.py Projeto: natano/tiget
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')
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
 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
Exemplo n.º 10
0
 def _inner(*args, **kwargs):
     try:
         with transaction.wrap():
             return fn(*args, **kwargs)
     except GitError:
         raise ImportError()
Exemplo n.º 11
0
 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']))
Exemplo n.º 12
0
 def test_current(self):
     assert_raises(GitError, transaction.current)
     with transaction.wrap():
         transaction.current()
     assert_raises(GitError, transaction.current)
Exemplo n.º 13
0
 def _foo():
     with transaction.wrap() as trans:
         trans.set_blob(['foo'], 'bar'.encode('utf-8'))
         self.assert_commit_count(0)
         raise TestException()
Exemplo n.º 14
0
 def test_nochanges(self):
     with transaction.wrap():
         pass
     self.assert_commit_count(0)
Exemplo n.º 15
0
 def test_nochanges(self):
     with transaction.wrap():
         pass
     self.assert_commit_count(0)
Exemplo n.º 16
0
 def _foo():
     with transaction.wrap() as trans:
         trans.set_blob(['foo'], 'bar'.encode('utf-8'))
         self.assert_commit_count(0)
         raise TestException()
Exemplo n.º 17
0
 def _foo():
     with transaction.wrap() as trans:
         trans.set_blob(['foo'], 'bar'.encode('utf-8'))
         raise TestException()
Exemplo n.º 18
0
 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']))
Exemplo n.º 19
0
 def _foo():
     with transaction.wrap() as trans:
         trans.set_blob(['foo'], 'bar'.encode('utf-8'))
         raise TestException()
Exemplo n.º 20
0
 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))
Exemplo n.º 21
0
 def _inner(*args, **kwargs):
     try:
         with transaction.wrap():
             return fn(*args, **kwargs)
     except GitError:
         raise ImportError()
Exemplo n.º 22
0
 def test_current(self):
     assert_raises(GitError, transaction.current)
     with transaction.wrap():
         transaction.current()
     assert_raises(GitError, transaction.current)
Exemplo n.º 23
0
 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']))
Exemplo n.º 24
0
 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']))