summaryrefslogtreecommitdiff
path: root/morphlib/sourcemanager_tests.py
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-01-19 15:32:58 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-01-20 18:31:51 +0000
commitc73ca82e0c67ba3d05f47f61766f8838d0e9d8d4 (patch)
treefb3fb2f063af4167da1c287d67e4ae2d818e7748 /morphlib/sourcemanager_tests.py
parent55751d6de5927c3bbcdd21321f7c3a6655e87a76 (diff)
downloadmorph-c73ca82e0c67ba3d05f47f61766f8838d0e9d8d4.tar.gz
Port everything to using Treeish objects instead of (repo, ref).
This affects pretty much every part of morph, so this might not be fully working and stable yet. This commit also introduces the "update-gits" command that can be used to update all cached repositories from the list of base URLs. The tree walk when resolving the Treeish objects in Builder.get_cache_id() is a bit similar to what we do in BuildDependencyGraph, maybe we can merge that one day.
Diffstat (limited to 'morphlib/sourcemanager_tests.py')
-rw-r--r--morphlib/sourcemanager_tests.py46
1 files changed, 30 insertions, 16 deletions
diff --git a/morphlib/sourcemanager_tests.py b/morphlib/sourcemanager_tests.py
index c781327f..1fb0b6c0 100644
--- a/morphlib/sourcemanager_tests.py
+++ b/morphlib/sourcemanager_tests.py
@@ -25,8 +25,13 @@ import morphlib
class DummyApp(object):
- def __init__(self):
- self.settings = { 'git-base-url': ['.',] }
+
+ def __init__(self):
+ self.settings = {
+ 'git-base-url': ['.',],
+ 'bundle-server': None,
+ 'cachedir': '/foo/bar/baz',
+ }
self.msg = lambda msg: None
@@ -37,18 +42,29 @@ class SourceManagerTests(unittest.TestCase):
env = os.environ
env["DATADIR"]=self.temprepodir
subprocess.call("./tests/show-dependencies.setup", shell=True, env=env)
- self.temprepo = self.temprepodir + '/test-repo/'
+ self.temprepo = self.temprepodir + '/test-repo/'
bundle_name = morphlib.sourcemanager.quote_url(self.temprepo) + '.bndl'
subprocess.call("git bundle create %s/%s master" % (self.temprepodir, bundle_name),
- shell=True, cwd=self.temprepo)
+ shell=True, cwd=self.temprepo)
def tearDown(self):
shutil.rmtree(self.temprepodir)
+ def test_constructor_with_and_without_cachedir(self):
+ app = DummyApp()
+
+ tempdir = '/bla/bla/bla'
+ s = morphlib.sourcemanager.SourceManager(app, tempdir)
+ self.assertEqual(s.cache_dir, tempdir)
+
+ s = morphlib.sourcemanager.SourceManager(app)
+ self.assertEqual(s.cache_dir,
+ os.path.join(app.settings['cachedir'], 'gits'))
+
def test_get_sha1_treeish_for_self(self):
tempdir = tempfile.mkdtemp()
- s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp())
+ s = morphlib.sourcemanager.SourceManager(DummyApp(), tempdir)
t = s.get_treeish(self.temprepo,
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
self.assertEquals(t.sha1, 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
@@ -58,12 +74,12 @@ class SourceManagerTests(unittest.TestCase):
def test_get_sha1_treeish_for_self_twice(self):
tempdir = tempfile.mkdtemp()
- s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp())
+ s = morphlib.sourcemanager.SourceManager(DummyApp(), tempdir)
t = s.get_treeish(self.temprepo,
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
self.assertEquals(t.sha1, 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
- s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp())
+ s = morphlib.sourcemanager.SourceManager(DummyApp(), tempdir)
t = s.get_treeish(self.temprepo,
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
self.assertEquals(t.sha1, 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
@@ -73,9 +89,9 @@ class SourceManagerTests(unittest.TestCase):
def test_get_ref_treeish_for_self(self):
tempdir = tempfile.mkdtemp()
- s = morphlib.sourcemanager.SourceManager(tempdir, DummyApp())
+ s = morphlib.sourcemanager.SourceManager(DummyApp(), tempdir)
t = s.get_treeish(self.temprepo, 'master')
- self.assertEquals(t.ref, 'refs/heads/master')
+ self.assertEquals(t.ref, 'refs/remotes/origin/master')
shutil.rmtree(tempdir)
@@ -86,11 +102,11 @@ class SourceManagerTests(unittest.TestCase):
app = DummyApp()
app.settings['bundle-server'] = 'file://' + bundle_server_loc
- s = morphlib.sourcemanager.SourceManager(tempdir, app)
+ s = morphlib.sourcemanager.SourceManager(app, tempdir)
def wget(url):
path=urlparse(url).path
- shutil.copy(path, s.source_cache_dir)
+ shutil.copy(path, s.cache_dir)
s._wget = wget
@@ -100,17 +116,16 @@ class SourceManagerTests(unittest.TestCase):
shutil.rmtree(tempdir)
-
def test_get_sha1_treeish_for_self_bundle_fail(self):
tempdir = tempfile.mkdtemp()
app = DummyApp()
app.settings['bundle-server'] = 'file://' + self.temprepodir
- s = morphlib.sourcemanager.SourceManager(tempdir, app)
+ s = morphlib.sourcemanager.SourceManager(app, tempdir)
def wget(url):
path=urlparse(url).path
- shutil.copy(path, s.source_cache_dir)
+ shutil.copy(path, s.cache_dir)
s._wget = wget
self.assertRaises(morphlib.sourcemanager.SourceNotFound, s.get_treeish,
@@ -124,8 +139,7 @@ class SourceManagerTests(unittest.TestCase):
app = DummyApp()
app.settings['git-base-url'] = ['.', '/somewhere/else']
-
- s = morphlib.sourcemanager.SourceManager(tempdir, app)
+ s = morphlib.sourcemanager.SourceManager(app, tempdir)
t = s.get_treeish(self.temprepo,
'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')
self.assertEquals(t.sha1, 'e28a23812eadf2fce6583b8819b9c5dbd36b9fb9')