summaryrefslogtreecommitdiff
path: root/morphlib/gitdir_tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/gitdir_tests.py')
-rw-r--r--morphlib/gitdir_tests.py27
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')