diff options
author | Guido Günther <agx@sigxcpu.org> | 2017-01-02 15:36:19 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2017-01-02 16:01:18 +0100 |
commit | bbee246b1e2c62fa869c7918c1dfcda52354283f (patch) | |
tree | 53e1eb2d5c2280ef5e5c4a4ac6ae50850a74a33b /tests/doctests | |
parent | 351d45c5e49363c9b5d0f4eb4a3867a7f111a42a (diff) |
GitVfs: make objects usable as context managers
Diffstat (limited to 'tests/doctests')
-rw-r--r-- | tests/doctests/test_GitVfs.py | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/tests/doctests/test_GitVfs.py b/tests/doctests/test_GitVfs.py index fb845e58..fdb15455 100644 --- a/tests/doctests/test_GitVfs.py +++ b/tests/doctests/test_GitVfs.py @@ -4,6 +4,7 @@ Test L{gbp.git.GitVfs} """ +import os import gbp.log from .. import context # noqa: F401 @@ -11,6 +12,17 @@ from .. import context # noqa: F401 gbp.log.setup(color=False, verbose=True) +def setup_repo(): + repo_dir = context.new_tmpdir(__name__) + repo = gbp.git.GitRepository.create(str(repo_dir)) + content = 'al pha\na\nb\nc' + with open(os.path.join(repo.path, 'foo.txt'), 'w') as f: + f.write(content) + repo.add_files(repo.path, force=True) + repo.commit_all(msg="foo") + return (repo, content) + + def test_read(): """ Create a repository @@ -22,15 +34,8 @@ def test_read(): - 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' - >>> ret = f.write('al pha\\na\\nb\\nc') - >>> f.close() - >>> repo.add_files(repo.path, force=True) - >>> repo.commit_all(msg="foo") + >>> import gbp.git.vfs + >>> (repo, content) = setup_repo() >>> vfs = gbp.git.vfs.GitVfs(repo, 'HEAD') >>> gf = vfs.open('foo.txt') >>> gf.readline() @@ -54,3 +59,20 @@ def test_read(): IOError: can't get HEAD:doesnotexist: fatal: Path 'doesnotexist' does not exist in 'HEAD' >>> context.teardown() """ + + +def test_content_manager(): + """ + Create a repository + + Methods tested: + - L{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'] + """ |