summaryrefslogtreecommitdiff
path: root/tests/test_GitVfs.py
blob: 7004db1f6e78f3eac1c829f37b7387ad22db7bae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# vim: set fileencoding=utf-8 :

"""
Test L{gbp.git.GitVfs}
"""

import gbp.log

from . import context

gbp.log.setup(color=False, verbose=True)
import gbp.git


def test_read():
    """
    Create a repository

    Methods tested:
         - L{gbp.git.GitVfs.open}
         - L{gbp.git.GitVfs._File.readline}
         - L{gbp.git.GitVfs._File.readlines}
         - L{gbp.git.GitVfs._File.read}
         - L{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()
    """