# `doctests.test_GitVfs` module documentation

Part of `doctests`

Test `gbp.git.GitVfs`

Function | setup_repo | Undocumented
Function | test_read | Create a repository
Function | test_binary_read | Create a repository
Function | test_content_manager | Create a repository

def setup_repo():
Undocumented
def 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 gbp.git.vfs
    >>> (repo, content) = setup_repo()
    >>> 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()
    ''
    >>> gf.close()
    >>> gbp.git.vfs.GitVfs(repo, 'HEAD').open('foo.txt').read() == content.decode()
    True
    >>> gf = vfs.open('doesnotexist')
    Traceback (most recent call last):
    ...
    OSError: can't get HEAD:doesnotexist: fatal: Path 'doesnotexist' does not exist in 'HEAD'
    >>> context.teardown()

def test_binary_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 gbp.git.vfs
    >>> (repo, content) = setup_repo()
    >>> vfs = gbp.git.vfs.GitVfs(repo, 'HEAD')
    >>> gf = vfs.open('foo.txt', 'rb')
    >>> gf.readline()
    b'al pha\n'
    >>> gf.readline()
    b'a\n'
    >>> gf.readlines()
    [b'b\n', b'c']
    >>> gf.readlines()
    []
    >>> gf.readline()
    b''
    >>> gf.readline()
    b''
    >>> gf.close()
    >>> gbp.git.vfs.GitVfs(repo, 'HEAD').open('foo.txt', 'rb').read() == content
    True
    >>> gf = vfs.open('doesnotexist')
    Traceback (most recent call last):
    ...
    OSError: can't get HEAD:doesnotexist: fatal: Path 'doesnotexist' does not exist in 'HEAD'
    >>> context.teardown()

def test_content_manager():

Create a repository

Methods tested:

- `gbp.git.GitVfs.open`

    >>> import gbp.git.vfs
    >>> (repo, content) = setup_repo()
    >>> vfs = gbp.git.vfs.GitVfs(repo, 'HEAD')
    >>> with vfs.open('foo.txt') as gf:
    ...   data = gf.readlines()
    >>> data
    ['al pha\n', 'a\n', 'b\n', 'c']