diff --git a/tests/base.py b/tests/base.py index 6cca3a5ab..3647ee526 100644 --- a/tests/base.py +++ b/tests/base.py @@ -30,6 +30,7 @@ import fixtures from six.moves import StringIO import testtools from testtools.content import text_content +import testscenarios from yaml import safe_dump from jenkins_jobs.config import JJBConfig @@ -100,22 +101,17 @@ def get_scenarios(fixtures_path, in_ext='yaml', out_ext='xml', return scenarios -class LoggingFixture(object): - - def setUp(self): - - super(LoggingFixture, self).setUp() - self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) - - -class BaseTestCase(LoggingFixture): - scenarios = [] - fixtures_path = None +class BaseTestCase(testtools.TestCase): # TestCase settings: maxDiff = None # always dump text difference longMessage = True # keep normal error message when providing our + def setUp(self): + + super(BaseTestCase, self).setUp() + self.useFixture(fixtures.FakeLogger(level=logging.DEBUG)) + def _read_utf8_content(self): # if None assume empty file if self.out_filename is None: @@ -137,6 +133,12 @@ class BaseTestCase(LoggingFixture): return jjb_config + +class BaseScenariosTestCase(testscenarios.TestWithScenarios, BaseTestCase): + + scenarios = [] + fixtures_path = None + def test_yaml_snippet(self): if not self.in_filename: return @@ -192,7 +194,8 @@ class BaseTestCase(LoggingFixture): ) -class SingleJobTestCase(BaseTestCase): +class SingleJobTestCase(BaseScenariosTestCase): + def test_yaml_snippet(self): config = self._get_config() @@ -223,7 +226,7 @@ class SingleJobTestCase(BaseTestCase): ) -class JsonTestCase(BaseTestCase): +class JsonTestCase(BaseScenariosTestCase): def test_yaml_snippet(self): expected_json = self._read_utf8_content() @@ -240,7 +243,7 @@ class JsonTestCase(BaseTestCase): ) -class YamlTestCase(BaseTestCase): +class YamlTestCase(BaseScenariosTestCase): def test_yaml_snippet(self): expected_yaml = self._read_utf8_content() diff --git a/tests/builder/test_builder.py b/tests/builder/test_builder.py index 3a6721870..12deced7a 100644 --- a/tests/builder/test_builder.py +++ b/tests/builder/test_builder.py @@ -16,14 +16,12 @@ from jenkins_jobs.config import JJBConfig import jenkins_jobs.builder -from tests.base import LoggingFixture +from tests import base from tests.base import mock -from testtools import TestCase - @mock.patch('jenkins_jobs.builder.JobCache', mock.MagicMock) -class TestCaseTestBuilder(LoggingFixture, TestCase): +class TestCaseTestBuilder(base.BaseTestCase): def setUp(self): super(TestCaseTestBuilder, self).setUp() jjb_config = JJBConfig() diff --git a/tests/builders/test_builders.py b/tests/builders/test_builders.py index 191c953ad..350d10e82 100644 --- a/tests/builders/test_builders.py +++ b/tests/builders/test_builders.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import builders -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleBuilders(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleBuilders(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = builders.Builders diff --git a/tests/cachestorage/test_cachestorage.py b/tests/cachestorage/test_cachestorage.py index 0058a3d46..8a9f533d7 100644 --- a/tests/cachestorage/test_cachestorage.py +++ b/tests/cachestorage/test_cachestorage.py @@ -14,14 +14,13 @@ # under the License. import os -import testtools import jenkins_jobs -from tests.base import LoggingFixture +from tests import base from tests.base import mock -class TestCaseJobCache(LoggingFixture, testtools.TestCase): +class TestCaseJobCache(base.BaseTestCase): @mock.patch('jenkins_jobs.builder.JobCache.get_cache_dir', lambda x: '/bad/file') diff --git a/tests/cmd/test_cmd.py b/tests/cmd/test_cmd.py index 2827d4933..5ec1dd7a9 100644 --- a/tests/cmd/test_cmd.py +++ b/tests/cmd/test_cmd.py @@ -1,12 +1,11 @@ import os -import testtools from jenkins_jobs.cli import entry -from tests.base import LoggingFixture +from tests import base from tests.base import mock -class CmdTestsBase(LoggingFixture, testtools.TestCase): +class CmdTestsBase(base.BaseTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') diff --git a/tests/duplicates/test_duplicates.py b/tests/duplicates/test_duplicates.py index ee6a6d37b..0a90c9b44 100644 --- a/tests/duplicates/test_duplicates.py +++ b/tests/duplicates/test_duplicates.py @@ -15,20 +15,16 @@ import os -from testscenarios.testcase import TestWithScenarios from testtools import ExpectedException -from testtools import TestCase from jenkins_jobs.errors import JenkinsJobsException -from tests.base import get_scenarios +from tests import base from tests.base import mock -from tests.base import SingleJobTestCase -class TestCaseModuleDuplicates(TestWithScenarios, - SingleJobTestCase, TestCase): +class TestCaseModuleDuplicates(base.SingleJobTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) @mock.patch('jenkins_jobs.builder.logger', autospec=True) def test_yaml_snippet(self, mock_logger): diff --git a/tests/errors/test_exceptions.py b/tests/errors/test_exceptions.py index c8e016db1..2fba25a6f 100644 --- a/tests/errors/test_exceptions.py +++ b/tests/errors/test_exceptions.py @@ -1,8 +1,7 @@ from testtools import ExpectedException -from testtools import TestCase from jenkins_jobs import errors -from tests.base import LoggingFixture +from tests import base def dispatch(exc, *args): @@ -22,7 +21,7 @@ def gen_xml(exc, *args): raise exc(*args) -class TestInvalidAttributeError(LoggingFixture, TestCase): +class TestInvalidAttributeError(base.BaseTestCase): def test_no_valid_values(self): # When given no valid values, InvalidAttributeError simply displays a @@ -49,7 +48,7 @@ class TestInvalidAttributeError(LoggingFixture, TestCase): valid_values) -class TestMissingAttributeError(LoggingFixture, TestCase): +class TestMissingAttributeError(base.BaseTestCase): def test_with_single_missing_attribute(self): # When passed a single missing attribute, display a message indicating diff --git a/tests/general/test_general.py b/tests/general/test_general.py index 2f4294af7..503310fac 100644 --- a/tests/general/test_general.py +++ b/tests/general/test_general.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import general -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleGeneral(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleGeneral(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = general.General diff --git a/tests/hipchat/test_hipchat.py b/tests/hipchat/test_hipchat.py index 2541c248e..6ff6d969b 100644 --- a/tests/hipchat/test_hipchat.py +++ b/tests/hipchat/test_hipchat.py @@ -14,15 +14,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import hipchat_notif -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModulePublishers(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModulePublishers(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = hipchat_notif.HipChat diff --git a/tests/jsonparser/test_jsonparser.py b/tests/jsonparser/test_jsonparser.py index 4ed4727f1..5e62534be 100644 --- a/tests/jsonparser/test_jsonparser.py +++ b/tests/jsonparser/test_jsonparser.py @@ -17,14 +17,9 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - -from tests.base import get_scenarios -from tests.base import SingleJobTestCase +from tests import base -class TestCaseModuleJsonParser(TestWithScenarios, - SingleJobTestCase, TestCase): +class TestCaseModuleJsonParser(base.SingleJobTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path, in_ext='json', out_ext='xml') + scenarios = base.get_scenarios(fixtures_path, in_ext='json', out_ext='xml') diff --git a/tests/localyaml/test_localyaml.py b/tests/localyaml/test_localyaml.py index 9f5d6923d..28460da6c 100644 --- a/tests/localyaml/test_localyaml.py +++ b/tests/localyaml/test_localyaml.py @@ -16,31 +16,26 @@ import os -from testscenarios.testcase import TestWithScenarios from testtools import ExpectedException -from testtools import TestCase from yaml.composer import ComposerError from jenkins_jobs.config import JJBConfig from jenkins_jobs.parser import YamlParser -from tests.base import get_scenarios -from tests.base import JsonTestCase -from tests.base import LoggingFixture -from tests.base import YamlTestCase +from tests import base def _exclude_scenarios(input_filename): return os.path.basename(input_filename).startswith("custom_") -class TestCaseLocalYamlInclude(TestWithScenarios, JsonTestCase, TestCase): +class TestCaseLocalYamlInclude(base.JsonTestCase): """ Verify application specific tags independently of any changes to modules XML parsing behaviour """ fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path, 'yaml', 'json', - filter_func=_exclude_scenarios) + scenarios = base.get_scenarios(fixtures_path, 'yaml', 'json', + filter_func=_exclude_scenarios) def test_yaml_snippet(self): @@ -52,16 +47,16 @@ class TestCaseLocalYamlInclude(TestWithScenarios, JsonTestCase, TestCase): super(TestCaseLocalYamlInclude, self).test_yaml_snippet() -class TestCaseLocalYamlAnchorAlias(TestWithScenarios, YamlTestCase, TestCase): +class TestCaseLocalYamlAnchorAlias(base.YamlTestCase): """ Verify yaml input is expanded to the expected yaml output when using yaml anchors and aliases. """ fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path, 'iyaml', 'oyaml') + scenarios = base.get_scenarios(fixtures_path, 'iyaml', 'oyaml') -class TestCaseLocalYamlIncludeAnchors(LoggingFixture, TestCase): +class TestCaseLocalYamlIncludeAnchors(base.BaseTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') diff --git a/tests/macros/test_macros.py b/tests/macros/test_macros.py index 776c78755..392154ff9 100644 --- a/tests/macros/test_macros.py +++ b/tests/macros/test_macros.py @@ -17,13 +17,9 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - -from tests.base import get_scenarios -from tests.base import SingleJobTestCase +from tests import base -class TestCaseModuleSCMMacro(TestWithScenarios, SingleJobTestCase, TestCase): +class TestCaseModuleSCMMacro(base.SingleJobTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) diff --git a/tests/moduleregistry/test_moduleregistry.py b/tests/moduleregistry/test_moduleregistry.py index 65e5bde20..a0408f898 100644 --- a/tests/moduleregistry/test_moduleregistry.py +++ b/tests/moduleregistry/test_moduleregistry.py @@ -1,18 +1,15 @@ import pkg_resources -from testscenarios.testcase import TestWithScenarios - -import testtools as tt from testtools.content import text_content +import testscenarios from jenkins_jobs.config import JJBConfig from jenkins_jobs.registry import ModuleRegistry -from tests.base import LoggingFixture +from tests import base -class ModuleRegistryPluginInfoTestsWithScenarios(TestWithScenarios, - LoggingFixture, - tt.TestCase): +class ModuleRegistryPluginInfoTestsWithScenarios( + testscenarios.TestWithScenarios, base.BaseTestCase): scenarios = [ ('s1', dict(v1='1.0.0', op='__gt__', v2='0.8.0')), ('s2', dict(v1='1.0.1alpha', op='__gt__', v2='1.0.0')), diff --git a/tests/modules/test_helpers.py b/tests/modules/test_helpers.py index 47c058753..cdfc4d741 100644 --- a/tests/modules/test_helpers.py +++ b/tests/modules/test_helpers.py @@ -13,7 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -import testtools from testtools.matchers import Equals import xml.etree.ElementTree as XML import yaml @@ -21,10 +20,10 @@ import yaml from jenkins_jobs.errors import InvalidAttributeError from jenkins_jobs.errors import MissingAttributeError from jenkins_jobs.modules.helpers import convert_mapping_to_xml -from tests.base import LoggingFixture +from tests import base -class TestCaseTestHelpers(LoggingFixture, testtools.TestCase): +class TestCaseTestHelpers(base.BaseTestCase): def test_convert_mapping_to_xml(self): """ diff --git a/tests/notifications/test_notifications.py b/tests/notifications/test_notifications.py index be58336e2..e68a269d9 100644 --- a/tests/notifications/test_notifications.py +++ b/tests/notifications/test_notifications.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import notifications -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleNotifications(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleNotifications(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = notifications.Notifications diff --git a/tests/parameters/test_parameters.py b/tests/parameters/test_parameters.py index 209821c4b..ab637ca2d 100644 --- a/tests/parameters/test_parameters.py +++ b/tests/parameters/test_parameters.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import parameters -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleParameters(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleParameters(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = parameters.Parameters diff --git a/tests/properties/test_properties.py b/tests/properties/test_properties.py index f7ca92907..f527d8dcf 100644 --- a/tests/properties/test_properties.py +++ b/tests/properties/test_properties.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import properties -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleProperties(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleProperties(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = properties.Properties diff --git a/tests/publishers/test_publishers.py b/tests/publishers/test_publishers.py index 93c5e8135..e44a4dbaa 100644 --- a/tests/publishers/test_publishers.py +++ b/tests/publishers/test_publishers.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import publishers -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModulePublishers(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModulePublishers(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = publishers.Publishers diff --git a/tests/reporters/test_reporters.py b/tests/reporters/test_reporters.py index a750498ed..920c463f7 100644 --- a/tests/reporters/test_reporters.py +++ b/tests/reporters/test_reporters.py @@ -16,15 +16,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import reporters -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleReporters(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleReporters(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = reporters.Reporters diff --git a/tests/scm/test_scm.py b/tests/scm/test_scm.py index 27bd86975..a4fa998dc 100644 --- a/tests/scm/test_scm.py +++ b/tests/scm/test_scm.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import scm -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleSCM(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleSCM(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = scm.SCM diff --git a/tests/triggers/test_triggers.py b/tests/triggers/test_triggers.py index c87c50158..04b7c8cd2 100644 --- a/tests/triggers/test_triggers.py +++ b/tests/triggers/test_triggers.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import triggers -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleTriggers(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleTriggers(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = triggers.Triggers diff --git a/tests/wrappers/test_wrappers.py b/tests/wrappers/test_wrappers.py index d6f8323de..717a99552 100644 --- a/tests/wrappers/test_wrappers.py +++ b/tests/wrappers/test_wrappers.py @@ -17,15 +17,11 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - from jenkins_jobs.modules import wrappers -from tests.base import BaseTestCase -from tests.base import get_scenarios +from tests import base -class TestCaseModuleWrappers(TestWithScenarios, BaseTestCase, TestCase): +class TestCaseModuleWrappers(base.BaseScenariosTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path) klass = wrappers.Wrappers diff --git a/tests/yamlparser/test_yamlparser.py b/tests/yamlparser/test_yamlparser.py index 39f64c6c4..a3bd90997 100644 --- a/tests/yamlparser/test_yamlparser.py +++ b/tests/yamlparser/test_yamlparser.py @@ -17,14 +17,9 @@ import os -from testscenarios.testcase import TestWithScenarios -from testtools import TestCase - -from tests.base import get_scenarios -from tests.base import SingleJobTestCase +from tests import base -class TestCaseModuleYamlInclude(TestWithScenarios, - SingleJobTestCase, TestCase): +class TestCaseModuleYamlInclude(base.SingleJobTestCase): fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures') - scenarios = get_scenarios(fixtures_path) + scenarios = base.get_scenarios(fixtures_path)