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
This commit is contained in:
parent
5cdd306e1e
commit
5a06edd448
@ -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):
|
||||
|
@ -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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user