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 codecs
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import sys
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
from oslo_config import fixture as config
|
from oslo_config import fixture as config
|
||||||
from oslotest import base as test_base
|
from oslotest import base as test_base
|
||||||
|
from six import moves
|
||||||
|
|
||||||
from oslo_policy import _checks
|
from oslo_policy import _checks
|
||||||
from oslo_policy import policy
|
from oslo_policy import policy
|
||||||
@ -52,6 +54,10 @@ class PolicyBaseTestCase(test_base.BaseTestCase):
|
|||||||
with codecs.open(path, 'w', encoding='utf-8') as f:
|
with codecs.open(path, 'w', encoding='utf-8') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
||||||
|
def _capture_stdout(self):
|
||||||
|
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO()))
|
||||||
|
return sys.stdout
|
||||||
|
|
||||||
|
|
||||||
class FakeCheck(_checks.BaseCheck):
|
class FakeCheck(_checks.BaseCheck):
|
||||||
def __init__(self, result=None):
|
def __init__(self, result=None):
|
||||||
|
@ -10,13 +10,10 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import operator
|
import operator
|
||||||
import sys
|
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import fixtures
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from six import moves
|
|
||||||
import stevedore
|
import stevedore
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@ -50,10 +47,6 @@ class GenerateSampleYAMLTestCase(base.PolicyBaseTestCase):
|
|||||||
super(GenerateSampleYAMLTestCase, self).setUp()
|
super(GenerateSampleYAMLTestCase, self).setUp()
|
||||||
self.enforcer = policy.Enforcer(self.conf, policy_file='policy.yaml')
|
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):
|
def test_generate_loadable_yaml(self):
|
||||||
extensions = []
|
extensions = []
|
||||||
for name, opts in OPTS.items():
|
for name, opts in OPTS.items():
|
||||||
@ -343,10 +336,6 @@ class GenerateSampleJSONTestCase(base.PolicyBaseTestCase):
|
|||||||
super(GenerateSampleJSONTestCase, self).setUp()
|
super(GenerateSampleJSONTestCase, self).setUp()
|
||||||
self.enforcer = policy.Enforcer(self.conf, policy_file='policy.json')
|
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):
|
def test_generate_loadable_json(self):
|
||||||
extensions = []
|
extensions = []
|
||||||
for name, opts in OPTS.items():
|
for name, opts in OPTS.items():
|
||||||
@ -530,10 +519,6 @@ class ListRedundantTestCase(base.PolicyBaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ListRedundantTestCase, self).setUp()
|
super(ListRedundantTestCase, self).setUp()
|
||||||
|
|
||||||
def _capture_stdout(self):
|
|
||||||
self.useFixture(fixtures.MonkeyPatch('sys.stdout', moves.StringIO()))
|
|
||||||
return sys.stdout
|
|
||||||
|
|
||||||
def test_matched_rules(self):
|
def test_matched_rules(self):
|
||||||
extensions = []
|
extensions = []
|
||||||
for name, opts in OPTS.items():
|
for name, opts in OPTS.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user