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