summaryrefslogtreecommitdiff
path: root/morphlib/morphologyfactory_tests.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2012-04-20 12:22:30 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2012-04-20 12:26:15 +0000
commit29495567ce1787e426687d7d59653874e2efdcf4 (patch)
tree8615b9b52d10bdad6badd48b32aa555da07ca1a3 /morphlib/morphologyfactory_tests.py
parentc84b5c726509c07c3a1803121cb21046a7987ac7 (diff)
downloadmorph-29495567ce1787e426687d7d59653874e2efdcf4.tar.gz
morphologyfactory: infer build system without list
Detecting the build system is managed by it asking if any files exist detecting if the file exists is done with a callback function. This callback can use cat-file. If list_files existed this could be more efficient as it would not require the files to be read from the remote server and it only needs to be one round-trip
Diffstat (limited to 'morphlib/morphologyfactory_tests.py')
-rw-r--r--morphlib/morphologyfactory_tests.py62
1 files changed, 39 insertions, 23 deletions
diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py
index 5748aca0..0cd9e4b1 100644
--- a/morphlib/morphologyfactory_tests.py
+++ b/morphlib/morphologyfactory_tests.py
@@ -20,26 +20,27 @@ from morphlib.morph2 import Morphology
from morphlib.morphologyfactory import (MorphologyFactory,
AutodetectError,
NotcachedError)
+from morphlib.remoterepocache import CatFileError
class FakeRemoteRepoCache(object):
def cat_file(self, reponame, sha1, filename):
- return '''{
- "name": "remote-foo",
- "kind": "chunk",
- "build-system": "bar"
- }'''
- def list_files(self, reponame, sha1):
- return ['configure', 'Makefile']
+ if filename.endswith('.morph'):
+ return '''{
+ "name": "remote-foo",
+ "kind": "chunk",
+ "build-system": "bar"
+ }'''
+ return 'text'
class FakeLocalRepo(object):
def cat(self, sha1, filename):
- return '''{
- "name": "local-foo",
- "kind": "chunk",
- "build-system": "bar"
- }'''
- def list_files(self, sha1):
- return ['configure', 'Makefile']
+ if filename.endswith('.morph'):
+ return '''{
+ "name": "local-foo",
+ "kind": "chunk",
+ "build-system": "bar"
+ }'''
+ return 'text'
class FakeLocalRepoCache(object):
def __init__(self, lr):
@@ -57,8 +58,19 @@ class MorphologyFactoryTests(unittest.TestCase):
self.mf = MorphologyFactory(self.lrc, self.rrc)
self.lmf = MorphologyFactory(self.lrc, None)
- def nosuchfile(self):
+ def nolocalfile(self, *args):
raise IOError('File not found')
+ def noremotefile(self, *args):
+ raise CatFileError('reponame', 'ref', 'filename')
+ def nolocalmorph(self, *args):
+ if args[-1].endswith('.morph'):
+ raise IOError('File not found')
+ return 'text'
+ def noremotemorph(self, *args):
+ if args[-1].endswith('.morph'):
+ raise CatFileError('reponame', 'ref', 'filename')
+ return 'text'
+
def doesnothaverepo(self, reponame):
return False
@@ -74,23 +86,27 @@ class MorphologyFactoryTests(unittest.TestCase):
self.assertEqual('remote-foo', morph['name'])
def test_autodetects_local_morphology(self):
- self.lr.cat = self.nosuchfile
+ self.lr.cat = self.nolocalmorph
morph = self.mf.get_morphology('reponame', 'sha1',
'assumed-local.morph')
self.assertEqual('assumed-local', morph['name'])
def test_autodetects_remote_morphology(self):
self.lrc.has_repo = self.doesnothaverepo
- self.rrc.cat_file = self.nosuchfile
+ self.rrc.cat_file = self.noremotemorph
morph = self.mf.get_morphology('reponame', 'sha1',
'assumed-remote.morph')
self.assertEqual('assumed-remote', morph['name'])
- def test_raises_error_when_fails_detect(self):
- self.lr.cat = self.nosuchfile
- self.rrc.cat_file = self.nosuchfile
- self.lr.list_files = lambda x: ['.']
- self.rrc.list_files = lambda x: ['.']
+ def test_raises_error_when_fails_detect_locally(self):
+ self.lr.cat = self.nolocalfile
+ self.assertRaises(AutodetectError, self.mf.get_morphology,
+ 'reponame', 'sha1', 'unreached.morph')
+
+ def test_raises_error_when_fails_detect_remotely(self):
+ self.lrc.has_repo = self.doesnothaverepo
+ self.rrc.cat_file = self.noremotefile
+# self.mf.get_morphology('reponame', 'sha1', 'unreached.morph')
self.assertRaises(AutodetectError, self.mf.get_morphology,
'reponame', 'sha1', 'unreached.morph')
@@ -100,7 +116,7 @@ class MorphologyFactoryTests(unittest.TestCase):
self.assertEqual('local-foo', morph['name'])
def test_autodetects_locally_with_no_remote(self):
- self.lr.cat = self.nosuchfile
+ self.lr.cat = self.nolocalmorph
morph = self.lmf.get_morphology('reponame', 'sha1',
'assumed-local.morph')
self.assertEqual('assumed-local', morph['name'])