From fb64bd85fb98c14f83fb3141b9f0742845a69787 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 11 Mar 2015 15:43:29 +0000 Subject: Suppress warnings in test code. Warnings are only for the benefit of users, and they pollute the output of `check` if not suppressed. --- morphlib/artifactresolver_tests.py | 97 +++++++++++++++++++++----------------- morphlib/cachekeycomputer_tests.py | 7 ++- morphlib/morphloader_tests.py | 35 ++++++++++---- 3 files changed, 84 insertions(+), 55 deletions(-) diff --git a/morphlib/artifactresolver_tests.py b/morphlib/artifactresolver_tests.py index b958da4f..29718778 100644 --- a/morphlib/artifactresolver_tests.py +++ b/morphlib/artifactresolver_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 Codethink Limited +# Copyright (C) 2012-2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ import itertools import unittest +import warnings import yaml import morphlib @@ -158,8 +159,12 @@ class ArtifactResolverTests(unittest.TestCase): for chunk in sources: pool.add(chunk) - morph = get_stratum_morphology( - 'stratum', chunks=[('chunk', 'chunk', 'repo', 'ref')]) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + + morph = get_stratum_morphology( + 'stratum', chunks=[('chunk', 'chunk', 'repo', 'ref')]) + stratum_sources = set(morphlib.source.make_sources('repo', 'ref', 'stratum.morph', 'sha1', 'tree', @@ -250,30 +255,33 @@ class ArtifactResolverTests(unittest.TestCase): 'repo', 'original/ref', 'chunk1.morph', 'sha1', 'tree', chunk) pool.add(chunk1) - morph = get_stratum_morphology( - 'stratum1', - chunks=[(loader.save_to_string(chunk), 'chunk1.morph', - 'repo', 'original/ref')], - build_depends=['stratum2']) - sources = morphlib.source.make_sources('repo', 'original/ref', - 'stratum1.morph', 'sha1', - 'tree', morph) - for stratum1 in sources: - pool.add(stratum1) - - chunk = get_chunk_morphology('chunk2') - chunk2, = morphlib.source.make_sources( - 'repo', 'original/ref', 'chunk2.morph', 'sha1', 'tree', chunk) - pool.add(chunk2) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + + morph = get_stratum_morphology( + 'stratum1', + chunks=[(loader.save_to_string(chunk), 'chunk1.morph', + 'repo', 'original/ref')], + build_depends=['stratum2']) + sources = morphlib.source.make_sources('repo', 'original/ref', + 'stratum1.morph', 'sha1', + 'tree', morph) + for stratum1 in sources: + pool.add(stratum1) + + chunk = get_chunk_morphology('chunk2') + chunk2, = morphlib.source.make_sources( + 'repo', 'original/ref', 'chunk2.morph', 'sha1', 'tree', chunk) + pool.add(chunk2) - morph = get_stratum_morphology( - 'stratum2', - chunks=[(loader.save_to_string(chunk), 'chunk2.morph', - 'repo', 'original/ref')], - build_depends=['stratum1']) - sources = morphlib.source.make_sources('repo', 'original/ref', - 'stratum2.morph', 'sha1', - 'tree', morph) + morph = get_stratum_morphology( + 'stratum2', + chunks=[(loader.save_to_string(chunk), 'chunk2.morph', + 'repo', 'original/ref')], + build_depends=['stratum1']) + sources = morphlib.source.make_sources('repo', 'original/ref', + 'stratum2.morph', 'sha1', + 'tree', morph) for stratum2 in sources: pool.add(stratum2) @@ -283,23 +291,26 @@ class ArtifactResolverTests(unittest.TestCase): def test_detection_of_chunk_dependencies_in_invalid_order(self): pool = morphlib.sourcepool.SourcePool() - loader = morphlib.morphloader.MorphologyLoader() - morph = loader.load_from_string( - ''' - name: stratum - kind: stratum - build-depends: [] - chunks: - - name: chunk1 - repo: repo - ref: original/ref - build-depends: - - chunk2 - - name: chunk2 - repo: repo - ref: original/ref - build-depends: [] - ''') + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + loader = morphlib.morphloader.MorphologyLoader() + morph = loader.load_from_string( + ''' + name: stratum + kind: stratum + build-depends: [] + chunks: + - name: chunk1 + repo: repo + ref: original/ref + build-depends: + - chunk2 + - name: chunk2 + repo: repo + ref: original/ref + build-depends: [] + ''') + sources = morphlib.source.make_sources('repo', 'original/ref', 'stratum.morph', 'sha1', 'tree', morph) diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py index 57739983..35c47174 100644 --- a/morphlib/cachekeycomputer_tests.py +++ b/morphlib/cachekeycomputer_tests.py @@ -1,4 +1,4 @@ -# Copyright (C) 2012-2014 Codethink Limited +# Copyright (C) 2012-2015 Codethink Limited # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -16,6 +16,7 @@ import copy import unittest +import warnings import morphlib @@ -83,7 +84,9 @@ class CacheKeyComputerTests(unittest.TestCase): - morph: stratum2 ''', }.iteritems(): - morph = loader.load_from_string(text) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + morph = loader.load_from_string(text) sources = morphlib.source.make_sources('repo', 'original/ref', name, 'sha1', 'tree', morph) diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py index a1fe1674..384c82a1 100644 --- a/morphlib/morphloader_tests.py +++ b/morphlib/morphloader_tests.py @@ -206,7 +206,9 @@ build-system: dummy }) with self.assertRaises( morphlib.morphloader.ChunkSpecRefNotStringError): - self.loader.validate(m) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + self.loader.validate(m) def test_fails_to_validate_stratum_with_empty_refs_for_a_chunk(self): m = morphlib.morphology.Morphology({ @@ -412,9 +414,12 @@ build-system: dummy ] }) - self.assertRaises( - morphlib.morphloader.InvalidTypeError, - self.loader.validate, m) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + + self.assertRaises( + morphlib.morphloader.InvalidTypeError, + self.loader.validate, m) def test_validate_requires_chunks_in_strata(self): m = morphlib.morphology.Morphology( @@ -645,8 +650,12 @@ build-system: dummy }, ], }) - self.loader.set_defaults(m) - self.loader.validate(m) + + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + + self.loader.set_defaults(m) + self.loader.validate(m) self.assertEqual( dict(m), { @@ -684,7 +693,10 @@ build-system: dummy } test_dict_with_build_depends = dict(test_dict) test_dict_with_build_depends["build-depends"] = [] - m = morphlib.morphology.Morphology(test_dict_with_build_depends) + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + m = morphlib.morphology.Morphology( + test_dict_with_build_depends) self.loader.unset_defaults(m) self.assertEqual( dict(m), @@ -795,9 +807,12 @@ build-system: dummy ] }) - self.loader.set_defaults(m) - self.loader.validate(m) - self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + + self.loader.set_defaults(m) + self.loader.validate(m) + self.assertEqual(m['chunks'][0]['repo'], 'le-chunk') def test_collapses_stratum_chunks_repo_from_name(self): m = morphlib.morphology.Morphology( -- cgit v1.2.1