From c0e766e92876d5e002cb41d38fa310477f0357a7 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 16 Jan 2011 14:22:29 +0000 Subject: [PATCH] Tests pass without get_deprecated_singleton_config --- tests/basetest.py | 7 ++++++- tests/testdownload.py | 14 +++++++------- tests/testpolicy.py | 6 +++--- tests/testreader.py | 10 +++++----- tests/testsat.py | 10 +++++----- tests/testselections.py | 6 +++--- tests/testsolver.py | 23 ++++++++++++----------- zeroinstall/cmd/select.py | 2 +- zeroinstall/injector/background.py | 6 +++--- zeroinstall/injector/iface_cache.py | 7 ++----- zeroinstall/injector/policy.py | 7 ++++--- zeroinstall/injector/reader.py | 5 +---- zeroinstall/injector/selections.py | 14 ++++++++------ 13 files changed, 60 insertions(+), 57 deletions(-) diff --git a/tests/basetest.py b/tests/basetest.py index e5e1af9..0e52025 100755 --- a/tests/basetest.py +++ b/tests/basetest.py @@ -11,7 +11,7 @@ os.environ['LANGUAGE'] = 'C' sys.path.insert(0, '..') from zeroinstall.injector import qdom -from zeroinstall.injector import iface_cache, download, distro, model, handler, policy +from zeroinstall.injector import iface_cache, download, distro, model, handler, policy, reader from zeroinstall.zerostore import Store, Stores; Store._add_with_helper = lambda *unused: False from zeroinstall import support, helpers from zeroinstall.support import basedir @@ -141,3 +141,8 @@ class BaseTest(unittest.TestCase): shutil.rmtree(self.gnupg_home) os.environ['PATH'] = self.old_path + + def import_feed(self, url, path): + iface_cache = self.config.iface_cache + iface_cache.get_interface(url) + iface_cache._feeds[url] = reader.load_feed(path) diff --git a/tests/testdownload.py b/tests/testdownload.py index 22e3ab5..43e7d4a 100755 --- a/tests/testdownload.py +++ b/tests/testdownload.py @@ -11,7 +11,7 @@ sys.path.insert(0, '..') os.environ["http_proxy"] = "localhost:8000" -from zeroinstall.injector import model, gpg, iface_cache, download, reader, trust, handler, background, arch, selections, qdom, run +from zeroinstall.injector import model, gpg, iface_cache, download, trust, handler, background, arch, selections, qdom, run from zeroinstall.injector.policy import Policy from zeroinstall.zerostore import Store, NotStored; Store._add_with_helper = lambda *unused: False from zeroinstall.support import basedir, tasks @@ -167,10 +167,10 @@ class TestDownload(BaseTest): except NotStored: pass cli.main(['--download-only', 'selections.xml']) - path = self.config.iface_cache.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) + path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) - assert sels.download_missing(self.config.iface_cache, None) is None + assert sels.download_missing(self.config) is None def testHelpers(self): from zeroinstall import helpers @@ -181,7 +181,7 @@ class TestDownload(BaseTest): sels = helpers.ensure_cached('http://example.com:8000/Hello.xml') path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) - assert sels.download_missing(self.config.iface_cache, None) is None + assert sels.download_missing(self.config) is None def testSelectionsWithFeed(self): from zeroinstall.injector import cli @@ -198,7 +198,7 @@ class TestDownload(BaseTest): path = self.config.stores.lookup_any(sels.selections['http://example.com:8000/Hello.xml'].digests) assert os.path.exists(os.path.join(path, 'HelloWorld', 'main')) - assert sels.download_missing(self.config.iface_cache, None) is None + assert sels.download_missing(self.config) is None def testAcceptKey(self): with output_suppressed(): @@ -364,11 +364,11 @@ class TestDownload(BaseTest): def testBackground(self, verbose = False): p = Policy('http://example.com:8000/Hello.xml', config = self.config) - reader.update(p.config.iface_cache.get_interface(p.root), 'Hello.xml') + self.import_feed(p.root, 'Hello.xml') p.freshness = 0 p.network_use = model.network_minimal p.solver.solve(p.root, arch.get_host_architecture()) - assert p.ready + assert p.ready, p.solver.get_failure_reason() @tasks.async def choose_download(registed_cb, nid, actions): diff --git a/tests/testpolicy.py b/tests/testpolicy.py index 7d1a52d..2f0e08a 100755 --- a/tests/testpolicy.py +++ b/tests/testpolicy.py @@ -18,11 +18,11 @@ class TestPolicy(BaseTest): warnings.filterwarnings("ignore", category = DeprecationWarning) foo = iface_cache.get_interface('http://foo/Binary.xml') - reader.update(foo, 'Binary.xml') + self.import_feed(foo.uri, 'Binary.xml') foo_src = iface_cache.get_interface('http://foo/Source.xml') - reader.update(foo_src, 'Source.xml') + self.import_feed(foo_src.uri, 'Source.xml') compiler = iface_cache.get_interface('http://foo/Compiler.xml') - reader.update(compiler, 'Compiler.xml') + self.import_feed(compiler.uri, 'Compiler.xml') p = Policy('http://foo/Binary.xml', config = self.config) p.freshness = 0 diff --git a/tests/testreader.py b/tests/testreader.py index 19e9079..30dc77c 100755 --- a/tests/testreader.py +++ b/tests/testreader.py @@ -72,7 +72,7 @@ class TestReader(BaseTest): """ % (foo_iface_uri, bar_iface_uri, bar_iface_uri)) tmp.flush() iface = model.Interface(foo_iface_uri) - reader.update(iface, tmp.name) + reader.update(iface, tmp.name, iface_cache = self.config.iface_cache) feed = self.config.iface_cache.get_feed(foo_iface_uri) impl = feed.implementations['sha1=123'] @@ -112,7 +112,7 @@ class TestReader(BaseTest): """) tmp.flush() iface = model.Interface(foo_iface_uri) - reader.update(iface, tmp.name, local = True) + reader.update(iface, tmp.name, local = True, iface_cache = self.config.iface_cache) feed = self.config.iface_cache.get_feed(foo_iface_uri) @@ -150,7 +150,7 @@ class TestReader(BaseTest): """ % foo_iface_uri) tmp.flush() iface = model.Interface(foo_iface_uri) - reader.update(iface, tmp.name) + reader.update(iface, tmp.name, iface_cache = self.config.iface_cache) feed = self.config.iface_cache.get_feed(foo_iface_uri) impl = feed.implementations['sha1=123'] assert impl.version == [[1, 0], -1, [3], -2] @@ -173,7 +173,7 @@ class TestReader(BaseTest): """ % foo_iface_uri) tmp.flush() iface = model.Interface(foo_iface_uri) - reader.update(iface, tmp.name) + reader.update(iface, tmp.name, iface_cache = self.config.iface_cache) feed = iface_cache.get_feed(foo_iface_uri) @@ -201,7 +201,7 @@ class TestReader(BaseTest): tmp.flush() iface = model.Interface(foo_iface_uri) - reader.update(iface, tmp.name, True) + reader.update(iface, tmp.name, True, iface_cache = self.config.iface_cache) master_feed = iface_cache.get_feed(foo_iface_uri) assert len(master_feed.implementations) == 0 diff --git a/tests/testsat.py b/tests/testsat.py index f1fff36..a0f600a 100755 --- a/tests/testsat.py +++ b/tests/testsat.py @@ -147,8 +147,8 @@ def assertSelection(expected, repo): assert s.ready actual = [] - for iface, impl in s.selections.iteritems(): - actual.append(((iface.uri.rsplit('/', 1)[1]), impl.get_version())) + for iface_uri, impl in s.selections.selections.iteritems(): + actual.append(((iface_uri.rsplit('/', 1)[1]), impl.version)) expected.sort() actual.sort() @@ -287,9 +287,9 @@ class TestSAT(BaseTest): """) assert not s.ready selected = {} - for iface, impl in s.selections.iteritems(): - if impl is not None: impl = impl.get_version() - selected[iface.uri.rsplit('/', 1)[1]] = impl + for iface_uri, impl in s.selections.selections.iteritems(): + if impl is not None: impl = impl.version + selected[iface_uri.rsplit('/', 1)[1]] = impl self.assertEquals({ 'prog': '2', 'liba': '2', diff --git a/tests/testselections.py b/tests/testselections.py index 38e2020..161d3ff 100755 --- a/tests/testselections.py +++ b/tests/testselections.py @@ -5,7 +5,7 @@ import sys, os import unittest sys.path.insert(0, '..') -from zeroinstall.injector import selections, model, reader, policy, namespaces, qdom +from zeroinstall.injector import selections, model, policy, namespaces, qdom mydir = os.path.dirname(os.path.abspath(__file__)) @@ -14,8 +14,8 @@ class TestSelections(BaseTest): p = policy.Policy('http://foo/Source.xml', src = True, config = self.config) source = self.config.iface_cache.get_interface('http://foo/Source.xml') compiler = self.config.iface_cache.get_interface('http://foo/Compiler.xml') - reader.update(source, 'Source.xml') - reader.update(compiler, 'Compiler.xml') + self.import_feed(source.uri, 'Source.xml') + self.import_feed(compiler.uri, 'Compiler.xml') p.freshness = 0 p.network_use = model.network_full diff --git a/tests/testsolver.py b/tests/testsolver.py index ac515f7..36f09e2 100755 --- a/tests/testsolver.py +++ b/tests/testsolver.py @@ -18,11 +18,11 @@ class TestSolver(BaseTest): s = solver.DefaultSolver(self.config) foo = iface_cache.get_interface('http://foo/Binary.xml') - reader.update(foo, 'Binary.xml') + self.import_feed(foo.uri, 'Binary.xml') foo_src = iface_cache.get_interface('http://foo/Source.xml') - reader.update(foo_src, 'Source.xml') + self.import_feed(foo_src.uri, 'Source.xml') compiler = iface_cache.get_interface('http://foo/Compiler.xml') - reader.update(compiler, 'Compiler.xml') + self.import_feed(compiler.uri, 'Compiler.xml') binary_arch = arch.Architecture({None: 1}, {None: 1}) assert str(binary_arch).startswith("