diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-12 13:02:59 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-01-12 13:02:59 +0000 |
commit | 28dd2ba113f40370586d693dd62e699897521ed8 (patch) | |
tree | 16032707e914bdadafea74319a510c0a7c43e7ff /morphlib/gitdir_tests.py | |
parent | f3197d814a5e883f47631a4f0acfa51bd1285daf (diff) | |
parent | 7e975343c7f00e98962d2edd07ac87630c4936c4 (diff) | |
download | morph-28dd2ba113f40370586d693dd62e699897521ed8.tar.gz |
Merge branch 'sam/cached-repo-cleanup'
Reviewed-By: Adam Coldrick <adam.coldrick@codethink.co.uk>
Reviewed-By: Richard Maw <richard.maw@codethink.co.uk>
Diffstat (limited to 'morphlib/gitdir_tests.py')
-rw-r--r-- | morphlib/gitdir_tests.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/morphlib/gitdir_tests.py b/morphlib/gitdir_tests.py index fe71ab3a..50de18d7 100644 --- a/morphlib/gitdir_tests.py +++ b/morphlib/gitdir_tests.py @@ -16,6 +16,7 @@ # =*= License: GPL-2 =*= +import contextlib import datetime import os import shutil @@ -25,6 +26,26 @@ import unittest import morphlib +@contextlib.contextmanager +def monkeypatch(obj, attr, new_value): + old_value = getattr(obj, attr) + setattr(obj, attr, new_value) + yield + setattr(obj, attr, old_value) + + +def allow_nonexistant_git_repos(): + '''Disable the gitdir._ensure_is_git_repo() function. + + This is used in other unit tests to avoid needing to run 'git init' at the + start of each test. A library like 'mock' would be a better solution for + this problem. + + ''' + return monkeypatch( + morphlib.gitdir.GitDirectory, '_ensure_is_git_repo', lambda x: None) + + class GitDirectoryTests(unittest.TestCase): def setUp(self): @@ -154,6 +175,12 @@ class GitDirectoryContentsTests(unittest.TestCase): self.assertRaises(morphlib.gitdir.InvalidRefError, gd.read_file, 'bar', 'no-such-ref') + def test_read_raises_io_error(self): + for gitdir in (self.dirname, self.mirror): + gd = morphlib.gitdir.GitDirectory(gitdir) + self.assertRaises(IOError, + gd.read_file, 'non-existant-file', 'HEAD') + def test_HEAD(self): gd = morphlib.gitdir.GitDirectory(self.dirname) self.assertEqual(gd.HEAD, 'master') |