Merge "Capture logs with FakeLogging Fixture"
This commit is contained in:
commit
3f0ff2dff6
|
@ -18,10 +18,11 @@
|
|||
# under the License.
|
||||
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import doctest
|
||||
import logging
|
||||
import fixtures
|
||||
import json
|
||||
import operator
|
||||
import testtools
|
||||
|
@ -96,7 +97,15 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml',
|
|||
return scenarios
|
||||
|
||||
|
||||
class BaseTestCase(object):
|
||||
class LoggingFixture(object):
|
||||
|
||||
def setUp(self):
|
||||
|
||||
super(LoggingFixture, self).setUp()
|
||||
self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
|
||||
|
||||
|
||||
class BaseTestCase(LoggingFixture):
|
||||
scenarios = []
|
||||
fixtures_path = None
|
||||
|
||||
|
@ -104,8 +113,6 @@ class BaseTestCase(object):
|
|||
maxDiff = None # always dump text difference
|
||||
longMessage = True # keep normal error message when providing our
|
||||
|
||||
logging.basicConfig()
|
||||
|
||||
def _read_utf8_content(self):
|
||||
# if None assume empty file
|
||||
if self.out_filename is None:
|
||||
|
|
|
@ -16,19 +16,20 @@
|
|||
|
||||
|
||||
import jenkins_jobs.builder
|
||||
from tests.base import LoggingFixture
|
||||
from tests.base import mock
|
||||
from testtools import TestCase
|
||||
|
||||
|
||||
@mock.patch('jenkins_jobs.builder.CacheStorage', mock.MagicMock)
|
||||
class TestCaseTestBuilder(TestCase):
|
||||
class TestCaseTestBuilder(LoggingFixture, TestCase):
|
||||
def setUp(self):
|
||||
super(TestCaseTestBuilder, self).setUp()
|
||||
self.builder = jenkins_jobs.builder.Builder(
|
||||
'http://jenkins.example.com',
|
||||
'doesnot', 'matter',
|
||||
plugins_list=['plugin1', 'plugin2'],
|
||||
)
|
||||
TestCase.setUp(self)
|
||||
|
||||
def test_plugins_list(self):
|
||||
self.assertEqual(self.builder.plugins_list, ['plugin1', 'plugin2'])
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import builders
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleBuilders(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleBuilders(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = builders.Builders
|
||||
|
|
|
@ -17,10 +17,11 @@ import os
|
|||
import testtools
|
||||
|
||||
import jenkins_jobs
|
||||
from tests.base import LoggingFixture
|
||||
from tests.base import mock
|
||||
|
||||
|
||||
class TestCaseCacheStorage(testtools.TestCase):
|
||||
class TestCaseCacheStorage(LoggingFixture, testtools.TestCase):
|
||||
|
||||
@mock.patch('jenkins_jobs.builder.CacheStorage.get_cache_dir',
|
||||
lambda x: '/bad/file')
|
||||
|
|
|
@ -2,10 +2,11 @@ import os
|
|||
from six.moves import configparser, StringIO
|
||||
import testtools
|
||||
from jenkins_jobs import cmd
|
||||
from tests.base import LoggingFixture
|
||||
from tests.base import mock
|
||||
|
||||
|
||||
class CmdTestsBase(testtools.TestCase):
|
||||
class CmdTestsBase(LoggingFixture, testtools.TestCase):
|
||||
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
parser = cmd.create_parser()
|
||||
|
|
|
@ -24,8 +24,8 @@ from tests.base import get_scenarios
|
|||
from tests.base import mock
|
||||
|
||||
|
||||
class TestCaseModuleDuplicates(TestWithScenarios, TestCase,
|
||||
SingleJobTestCase):
|
||||
class TestCaseModuleDuplicates(TestWithScenarios,
|
||||
SingleJobTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from testtools import ExpectedException, TestCase
|
||||
|
||||
from jenkins_jobs import errors
|
||||
from tests.base import LoggingFixture
|
||||
|
||||
|
||||
def dispatch(exc, *args):
|
||||
|
@ -20,7 +21,7 @@ def gen_xml(exc, *args):
|
|||
raise exc(*args)
|
||||
|
||||
|
||||
class TestInvalidAttributeError(TestCase):
|
||||
class TestInvalidAttributeError(LoggingFixture, TestCase):
|
||||
|
||||
def test_no_valid_values(self):
|
||||
# When given no valid values, InvalidAttributeError simply displays a
|
||||
|
@ -47,7 +48,7 @@ class TestInvalidAttributeError(TestCase):
|
|||
valid_values)
|
||||
|
||||
|
||||
class TestMissingAttributeError(TestCase):
|
||||
class TestMissingAttributeError(LoggingFixture, TestCase):
|
||||
|
||||
def test_with_single_missing_attribute(self):
|
||||
# When passed a single missing attribute, display a message indicating
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import general
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleGeneral(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleGeneral(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = general.General
|
||||
|
|
|
@ -19,7 +19,7 @@ from jenkins_jobs.modules import hipchat_notif
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModulePublishers(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModulePublishers(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = hipchat_notif.HipChat
|
||||
|
|
|
@ -21,7 +21,7 @@ from testscenarios.testcase import TestWithScenarios
|
|||
from tests.base import get_scenarios, SingleJobTestCase
|
||||
|
||||
|
||||
class TestCaseModuleJsonParser(TestWithScenarios, TestCase,
|
||||
SingleJobTestCase):
|
||||
class TestCaseModuleJsonParser(TestWithScenarios,
|
||||
SingleJobTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path, in_ext='json', out_ext='xml')
|
||||
|
|
|
@ -22,13 +22,14 @@ from yaml.composer import ComposerError
|
|||
|
||||
from jenkins_jobs import builder
|
||||
from tests.base import get_scenarios, JsonTestCase, YamlTestCase
|
||||
from tests.base import LoggingFixture
|
||||
|
||||
|
||||
def _exclude_scenarios(input_filename):
|
||||
return os.path.basename(input_filename).startswith("custom_")
|
||||
|
||||
|
||||
class TestCaseLocalYamlInclude(TestWithScenarios, TestCase, JsonTestCase):
|
||||
class TestCaseLocalYamlInclude(TestWithScenarios, JsonTestCase, TestCase):
|
||||
"""
|
||||
Verify application specific tags independently of any changes to
|
||||
modules XML parsing behaviour
|
||||
|
@ -47,7 +48,7 @@ class TestCaseLocalYamlInclude(TestWithScenarios, TestCase, JsonTestCase):
|
|||
super(TestCaseLocalYamlInclude, self).test_yaml_snippet()
|
||||
|
||||
|
||||
class TestCaseLocalYamlAnchorAlias(TestWithScenarios, TestCase, YamlTestCase):
|
||||
class TestCaseLocalYamlAnchorAlias(TestWithScenarios, YamlTestCase, TestCase):
|
||||
"""
|
||||
Verify yaml input is expanded to the expected yaml output when using yaml
|
||||
anchors and aliases.
|
||||
|
@ -56,7 +57,7 @@ class TestCaseLocalYamlAnchorAlias(TestWithScenarios, TestCase, YamlTestCase):
|
|||
scenarios = get_scenarios(fixtures_path, 'iyaml', 'oyaml')
|
||||
|
||||
|
||||
class TestCaseLocalYamlIncludeAnchors(TestCase):
|
||||
class TestCaseLocalYamlIncludeAnchors(LoggingFixture, TestCase):
|
||||
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
|
||||
|
|
|
@ -21,6 +21,6 @@ from testscenarios.testcase import TestWithScenarios
|
|||
from tests.base import get_scenarios, SingleJobTestCase
|
||||
|
||||
|
||||
class TestCaseModuleSCMMacro(TestWithScenarios, TestCase, SingleJobTestCase):
|
||||
class TestCaseModuleSCMMacro(TestWithScenarios, SingleJobTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
|
|
|
@ -6,9 +6,11 @@ from six.moves import configparser, StringIO
|
|||
|
||||
from jenkins_jobs import cmd
|
||||
from jenkins_jobs.registry import ModuleRegistry
|
||||
from tests.base import LoggingFixture
|
||||
|
||||
|
||||
class ModuleRegistryPluginInfoTestsWithScenarios(TestWithScenarios,
|
||||
LoggingFixture,
|
||||
tt.TestCase):
|
||||
scenarios = [
|
||||
('s1', dict(v1='1.0.0', op='__gt__', v2='0.8.0')),
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import notifications
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleNotifications(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleNotifications(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = notifications.Notifications
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import parameters
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleParameters(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleParameters(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = parameters.Parameters
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import properties
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleProperties(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleProperties(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = properties.Properties
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import publishers
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModulePublishers(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModulePublishers(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = publishers.Publishers
|
||||
|
|
|
@ -21,7 +21,7 @@ from jenkins_jobs.modules import reporters
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleReporters(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleReporters(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = reporters.Reporters
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import scm
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleSCM(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleSCM(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = scm.SCM
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import triggers
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleTriggers(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleTriggers(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = triggers.Triggers
|
||||
|
|
|
@ -22,7 +22,7 @@ from jenkins_jobs.modules import wrappers
|
|||
from tests.base import get_scenarios, BaseTestCase
|
||||
|
||||
|
||||
class TestCaseModuleWrappers(TestWithScenarios, TestCase, BaseTestCase):
|
||||
class TestCaseModuleWrappers(TestWithScenarios, BaseTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
klass = wrappers.Wrappers
|
||||
|
|
|
@ -21,7 +21,7 @@ from testscenarios.testcase import TestWithScenarios
|
|||
from tests.base import get_scenarios, SingleJobTestCase
|
||||
|
||||
|
||||
class TestCaseModuleYamlInclude(TestWithScenarios, TestCase,
|
||||
SingleJobTestCase):
|
||||
class TestCaseModuleYamlInclude(TestWithScenarios,
|
||||
SingleJobTestCase, TestCase):
|
||||
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures')
|
||||
scenarios = get_scenarios(fixtures_path)
|
||||
|
|
Loading…
Reference in New Issue