summaryrefslogtreecommitdiff
path: root/morphlib/morphologyfactory_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-04-20 10:12:56 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-04-20 11:25:03 +0000
commitb75fec924f2082d5a5a13421ecec0e866e3c011c (patch)
tree8be007c4de78674cbb3223ec2c4a637fe753885a /morphlib/morphologyfactory_tests.py
parent9ee4e4c57624cfee21d3bcc132f780bff04a59c4 (diff)
downloadmorph-b75fec924f2082d5a5a13421ecec0e866e3c011c.tar.gz
morphologyfactory: work without RemoteRepoCache
There are cases where we would not need a remote cache, so it should be able to operate without one.
Diffstat (limited to 'morphlib/morphologyfactory_tests.py')
-rw-r--r--morphlib/morphologyfactory_tests.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py
index 2a0709ed..5748aca0 100644
--- a/morphlib/morphologyfactory_tests.py
+++ b/morphlib/morphologyfactory_tests.py
@@ -17,7 +17,9 @@
import unittest
from morphlib.morph2 import Morphology
-from morphlib.morphologyfactory import MorphologyFactory, AutodetectError
+from morphlib.morphologyfactory import (MorphologyFactory,
+ AutodetectError,
+ NotcachedError)
class FakeRemoteRepoCache(object):
def cat_file(self, reponame, sha1, filename):
@@ -53,6 +55,7 @@ class MorphologyFactoryTests(unittest.TestCase):
self.lrc = FakeLocalRepoCache(self.lr)
self.rrc = FakeRemoteRepoCache()
self.mf = MorphologyFactory(self.lrc, self.rrc)
+ self.lmf = MorphologyFactory(self.lrc, None)
def nosuchfile(self):
raise IOError('File not found')
@@ -60,12 +63,14 @@ class MorphologyFactoryTests(unittest.TestCase):
return False
def test_gets_morph_from_local_repo(self):
- morph = self.mf.get_morphology('reponame', 'sha1', 'foo.morph')
+ morph = self.mf.get_morphology('reponame', 'sha1',
+ 'foo.morph')
self.assertEqual('local-foo', morph['name'])
def test_gets_morph_from_remote_repo(self):
self.lrc.has_repo = self.doesnothaverepo
- morph = self.mf.get_morphology('reponame', 'sha1', 'foo.morph')
+ morph = self.mf.get_morphology('reponame', 'sha1',
+ 'foo.morph')
self.assertEqual('remote-foo', morph['name'])
def test_autodetects_local_morphology(self):
@@ -88,3 +93,19 @@ class MorphologyFactoryTests(unittest.TestCase):
self.rrc.list_files = lambda x: ['.']
self.assertRaises(AutodetectError, self.mf.get_morphology,
'reponame', 'sha1', 'unreached.morph')
+
+ def test_looks_locally_with_no_remote(self):
+ morph = self.lmf.get_morphology('reponame', 'sha1',
+ 'foo.morph')
+ self.assertEqual('local-foo', morph['name'])
+
+ def test_autodetects_locally_with_no_remote(self):
+ self.lr.cat = self.nosuchfile
+ morph = self.lmf.get_morphology('reponame', 'sha1',
+ 'assumed-local.morph')
+ self.assertEqual('assumed-local', morph['name'])
+
+ def test_fails_when_local_not_cached_and_no_remote(self):
+ self.lrc.has_repo = self.doesnothaverepo
+ self.assertRaises(NotcachedError, self.lmf.get_morphology,
+ 'reponame', 'sha1', 'unreached.morph')