diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2016-03-03 15:56:40 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2016-03-03 17:11:25 +0000 |
commit | 014a029ade9a045a839ca86c35690b218098ea33 (patch) | |
tree | 4806d6cc1f0572604a4d027bf7a7141e381f85d6 /morphlib/localrepocache_tests.py | |
parent | e8a67a7d12d2defbf975d707e7513837403d93a2 (diff) | |
download | morph-014a029ade9a045a839ca86c35690b218098ea33.tar.gz |
Get rid of the CachedRepo class (almost)
For a long time the CachedRepo class has basically been a wrapper around
the GitDir class, but with a few extra methods that don't really even
belong there.
It is now a tiny class in the localrepocache module which just keeps
track of a few extra attributes. All other functionality is provided
by the gitdir module.
This commit also removes the `git clone` approach for copying repos out
of the cache. The alternative approach implemented by
git.copy_repository() was slightly faster when I tested, so for now we
should use that everywhere. Longer term we should find out why this is
quicker than `git clone`, and fix Git itself to be fast.
Change-Id: I1686ab43253d44c3903d9a0bad8bb75528e9cf75
Diffstat (limited to 'morphlib/localrepocache_tests.py')
-rw-r--r-- | morphlib/localrepocache_tests.py | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/morphlib/localrepocache_tests.py b/morphlib/localrepocache_tests.py index ea56bdf2..91fdb216 100644 --- a/morphlib/localrepocache_tests.py +++ b/morphlib/localrepocache_tests.py @@ -57,7 +57,7 @@ class LocalRepoCacheTests(unittest.TestCase): self.lrc._git = self.fake_git self.lrc._fetch = self.not_found self.lrc._mkdtemp = self.fake_mkdtemp - self.lrc._new_cached_repo_instance = self.new_cached_repo_instance + self.lrc._update_repo = lambda *args: None self._mkdtemp_count = 0 def fake_git(self, args, **kwargs): @@ -88,13 +88,6 @@ class LocalRepoCacheTests(unittest.TestCase): self.lrc.fs.makedir(dirname+"/"+thing) return thing - def new_cached_repo_instance(self, *args): - with morphlib.gitdir_tests.allow_nonexistant_git_repos(): - repo = morphlib.cachedrepo.CachedRepo( - FakeApplication(), *args) - repo.update = lambda: None - return repo - def not_found(self, url, path): raise cliapp.AppException('Not found') @@ -108,12 +101,14 @@ class LocalRepoCacheTests(unittest.TestCase): self.assertFalse(self.lrc.fs.exists(self.cachedir)) def test_creates_cachedir_if_missing(self): - self.lrc.get_updated_repo(self.repourl, ref='master') + with morphlib.gitdir_tests.allow_nonexistant_git_repos(): + self.lrc.get_updated_repo(self.repourl, ref='master') self.assertTrue(self.lrc.fs.exists(self.cachedir)) def test_happily_caches_same_repo_twice(self): - self.lrc.get_updated_repo(self.repourl, ref='master') - self.lrc.get_updated_repo(self.repourl, ref='master') + with morphlib.gitdir_tests.allow_nonexistant_git_repos(): + self.lrc.get_updated_repo(self.repourl, ref='master') + self.lrc.get_updated_repo(self.repourl, ref='master') def test_fails_to_cache_when_remote_does_not_exist(self): def fail(args, **kwargs): @@ -124,14 +119,14 @@ class LocalRepoCacheTests(unittest.TestCase): self.lrc.get_updated_repo, self.repourl, 'master') def test_does_not_mind_a_missing_tarball(self): - self.lrc.get_updated_repo(self.repourl, ref='master') + with morphlib.gitdir_tests.allow_nonexistant_git_repos(): + self.lrc.get_updated_repo(self.repourl, ref='master') self.assertEqual(self.fetched, []) def test_fetches_tarball_when_it_exists(self): self.lrc._fetch = lambda url, path: self.fetched.append(url) - with morphlib.gitdir_tests.monkeypatch( - morphlib.cachedrepo.CachedRepo, 'update', lambda self: None): + with morphlib.gitdir_tests.allow_nonexistant_git_repos(): self.lrc.get_updated_repo(self.repourl, ref='master') self.assertEqual(self.fetched, [self.tarball_url]) @@ -148,5 +143,7 @@ class LocalRepoCacheTests(unittest.TestCase): def test_avoids_caching_local_repo(self): self.lrc.fs.makedir('/local/repo', recursive=True) - cached = self.lrc.get_updated_repo('file:///local/repo', refs='master') - assert cached.path == '/local/repo' + with morphlib.gitdir_tests.allow_nonexistant_git_repos(): + cached = self.lrc.get_updated_repo('file:///local/repo', + refs='master') + assert cached.dirname == '/local/repo' |