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 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')
Example #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
 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 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')
Example #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
Example #7
0
File: git.py Project: 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')
Example #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
Example #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
Example #10
0
 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']))
Example #12
0
 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)
Example #15
0
 def test_nochanges(self):
     with transaction.wrap():
         pass
     self.assert_commit_count(0)
Example #16
0
 def _foo():
     with transaction.wrap() as trans:
         trans.set_blob(['foo'], 'bar'.encode('utf-8'))
         self.assert_commit_count(0)
         raise TestException()
 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']))
Example #19
0
 def _foo():
     with transaction.wrap() as trans:
         trans.set_blob(['foo'], 'bar'.encode('utf-8'))
         raise TestException()
Example #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))
Example #21
0
 def _inner(*args, **kwargs):
     try:
         with transaction.wrap():
             return fn(*args, **kwargs)
     except GitError:
         raise ImportError()
 def test_current(self):
     assert_raises(GitError, transaction.current)
     with transaction.wrap():
         transaction.current()
     assert_raises(GitError, transaction.current)
Example #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']))
Example #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']))