From 5a06edd4486faf6a4a9bcb3f521ce446fdc07813 Mon Sep 17 00:00:00 2001 From: Lance Bragstad Date: Tue, 16 Jan 2018 21:10:13 +0000 Subject: [PATCH] Move _capture_stdout to a common place The _capture_stdout method was duplicated in a couple different test classes that all inherited from PolicyBaseTestCase. This commit just moves the method into PolicyBaseTestCase and removes the duplicate implementations across test classes. Change-Id: Id62db9bb0e6f0e6d0d2917714302947415cb9829 --- oslo_policy/tests/base.py | 6 ++++++ oslo_policy/tests/test_generator.py | 15 --------------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/oslo_policy/tests/base.py b/oslo_policy/tests/base.py index 9c073c16..670ef4b8 100644 --- a/oslo_policy/tests/base.py +++ b/oslo_policy/tests/base.py @@ -16,10 +16,12 @@ import codecs import os import os.path +import sys import fixtures from oslo_config import fixture as config from oslotest import base as test_base +from six import moves from oslo_policy import _checks from oslo_policy import policy @@ -52,6 +54,10 @@ class PolicyBaseTestCase(test_base.BaseTestCase): with codecs.open(path, 'w', encoding='utf-8') as f: f.write(contents) + def _capture_stdout(self): + self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) + return sys.stdout + class FakeCheck(_checks.BaseCheck): def __init__(self, result=None): diff --git a/oslo_policy/tests/test_generator.py b/oslo_policy/tests/test_generator.py index 74f75014..06d9de9c 100644 --- a/oslo_policy/tests/test_generator.py +++ b/oslo_policy/tests/test_generator.py @@ -10,13 +10,10 @@ # under the License. import operator -import sys import warnings -import fixtures import mock from oslo_config import cfg -from six import moves import stevedore import testtools @@ -50,10 +47,6 @@ class GenerateSampleYAMLTestCase(base.PolicyBaseTestCase): super(GenerateSampleYAMLTestCase, self).setUp() self.enforcer = policy.Enforcer(self.conf, policy_file='policy.yaml') - def _capture_stdout(self): - self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) - return sys.stdout - def test_generate_loadable_yaml(self): extensions = [] for name, opts in OPTS.items(): @@ -343,10 +336,6 @@ class GenerateSampleJSONTestCase(base.PolicyBaseTestCase): super(GenerateSampleJSONTestCase, self).setUp() self.enforcer = policy.Enforcer(self.conf, policy_file='policy.json') - def _capture_stdout(self): - self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) - return sys.stdout - def test_generate_loadable_json(self): extensions = [] for name, opts in OPTS.items(): @@ -530,10 +519,6 @@ class ListRedundantTestCase(base.PolicyBaseTestCase): def setUp(self): super(ListRedundantTestCase, self).setUp() - def _capture_stdout(self): - self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO())) - return sys.stdout - def test_matched_rules(self): extensions = [] for name, opts in OPTS.items():