From ddb402e8359f6cb2e29b73a82b78cb2fc53b4932 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sat, 25 Mar 2006 15:31:48 +0000 Subject: [PATCH] Improved coverage. git-svn-id: file:///home/talex/Backups/sf.net/Subversion/zero-install/trunk/0launch@727 9f8c893c-44ee-0310-b757-c8ca8341c71e --- tests/testautopolicy.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/tests/testautopolicy.py b/tests/testautopolicy.py index 1f1f951..70d48c6 100755 --- a/tests/testautopolicy.py +++ b/tests/testautopolicy.py @@ -3,7 +3,6 @@ import sys, tempfile, os, shutil, logging from StringIO import StringIO import unittest from logging import getLogger, DEBUG, INFO -#getLogger().setLevel(DEBUG) sys.path.insert(0, '..') @@ -12,12 +11,15 @@ cache_home = tempfile.mktemp() os.environ['XDG_CONFIG_HOME'] = config_home os.environ['XDG_CACHE_HOME'] = cache_home -from zeroinstall.injector import model, basedir, autopolicy, gpg, iface_cache, namespaces +from zeroinstall import NeedDownload +from zeroinstall.injector import model, basedir, autopolicy, gpg, iface_cache, namespaces, reader import data reload(basedir) foo_iface_uri = 'http://foo' +logger = logging.getLogger() + class TestAutoPolicy(unittest.TestCase): def setUp(self): os.mkdir(config_home, 0700) @@ -224,7 +226,6 @@ class TestAutoPolicy(unittest.TestCase): stream.write('hello!') stream.close() - logger = logging.getLogger() logger.setLevel(logging.ERROR) policy = autopolicy.AutoPolicy(foo_iface_uri, download_only = False) @@ -257,11 +258,67 @@ class TestAutoPolicy(unittest.TestCase): """ % foo_iface_uri) policy = autopolicy.AutoPolicy(foo_iface_uri, download_only = False) - policy.network_use = model.network_offline + policy.network_use = model.network_full + policy.freshness = 0 impls = policy.get_ranked_implementations( policy.get_interface(policy.root)) assert len(impls) == 4 + policy.network_use = model.network_offline + policy.recalculate() # Changes sort order tests + + logger.setLevel(logging.ERROR) + policy.recalculate() # Triggers feed-for warning + logger.setLevel(logging.WARN) + + def testNoLocal(self): + self.cache_iface(foo_iface_uri, +""" + + Foo + Foo + Foo + +""" % foo_iface_uri) + policy = autopolicy.AutoPolicy(foo_iface_uri, + download_only = False) + policy.network_use = model.network_offline + try: + policy.get_interface(foo_iface_uri) + assert false + except reader.InvalidInterface, ex: + assert 'Invalid feed URL' in str(ex) + + def testDLfeed(self): + self.cache_iface(foo_iface_uri, +""" + + Foo + Foo + Foo + +""" % foo_iface_uri) + policy = autopolicy.AutoPolicy(foo_iface_uri, dry_run = True) + policy.network_use = model.network_full + policy.freshness = 0 + + try: + policy.recalculate() + assert False + except NeedDownload, ex: + pass + + iface = policy.get_interface(foo_iface_uri) + iface.feeds = [model.Feed('/BadFeed', None, False)] + + logger.setLevel(logging.ERROR) + policy.recalculate() # Triggers warning + logger.setLevel(logging.WARN) + def testBestUnusable(self): self.cache_iface(foo_iface_uri, """ -- 2.11.4.GIT