Package tests :: Module test_GitVfs

[hide private]
[frames] | no frames]

# Module test_GitVfs

Test gbp.git.GitVfs

Functions | [hide private]

test_read() Create a repository |

Variables | [hide private]

| __package__ = ``'``tests``'``

Function Details | [hide private]

### test_read()

Create a repository

Methods tested:

- gbp.git.GitVfs.open
- gbp.git.GitVfs._File.readline
- gbp.git.GitVfs._File.readlines
- gbp.git.GitVfs._File.read
- gbp.git.GitVfs._File.close

    >>> import os, gbp.git.vfs
    >>> repo_dir = context.new_tmpdir(__name__)
    >>> repo = gbp.git.GitRepository.create(str(repo_dir))
    >>> f = open(os.path.join(repo.path, 'foo.txt'), 'w')
    >>> content = 'al pha\na\nb\nc'
    >>> f.write('al pha\na\nb\nc')
    >>> f.close()
    >>> repo.add_files(repo.path, force=True)
    >>> repo.commit_all(msg="foo")
    >>> vfs = gbp.git.vfs.GitVfs(repo, 'HEAD')
    >>> gf = vfs.open('foo.txt')
    >>> gf.readline()
    'al pha\n'
    >>> gf.readline()
    'a\n'
    >>> gf.readlines()
    ['b\n', 'c']
    >>> gf.readlines()
    []
    >>> gf.readline()
    ''
    >>> gf.readline()
    ''
    >>> gbp.git.vfs.GitVfs(repo, 'HEAD').open('foo.txt').read() == content
    True
    >>> gf = vfs.open('doesnotexist')
    Traceback (most recent call last):
    ...
    IOError: can't get HEAD:doesnotexist: fatal: Path 'doesnotexist' does not exist in 'HEAD'
    >>> context.teardown()