diff options
author | Jan Pokorný <jpokorny@redhat.com> | 2014-09-09 21:19:25 +0200 |
---|---|---|
committer | Jan Pokorný <jpokorny@redhat.com> | 2014-09-09 21:39:08 +0200 |
commit | c5a05612c68dc617757323fcbd82338346962120 (patch) | |
tree | cc09acf1133c3bbf5490de745086a5476d358fc6 /tests | |
parent | 25268e5d0643a5d531804370c35b2777b1354f39 (diff) | |
download | clufter-c5a05612c68dc617757323fcbd82338346962120.tar.gz clufter-c5a05612c68dc617757323fcbd82338346962120.tar.xz clufter-c5a05612c68dc617757323fcbd82338346962120.zip |
Get rid of remaining clufter-qualified commands
(less name binding in favor of implied relations, the better)
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/_bootstart.py | 11 | ||||
-rw-r--r-- | tests/_bootstrap.py | 33 | ||||
-rw-r--r-- | tests/_common.py | 15 | ||||
-rw-r--r-- | tests/ccs2coroxml.py | 3 | ||||
-rw-r--r-- | tests/ccs2needle_xslt.py | 32 | ||||
-rw-r--r-- | tests/command.py | 29 | ||||
-rw-r--r-- | tests/command_context.py | 12 | ||||
-rw-r--r-- | tests/command_manager.py | 14 | ||||
-rw-r--r-- | tests/filter.py | 20 | ||||
-rw-r--r-- | tests/filter_manager.py | 28 | ||||
-rw-r--r-- | tests/format.py | 25 | ||||
-rw-r--r-- | tests/format_manager.py | 20 | ||||
-rw-r--r-- | tests/run_cmd.py | 18 | ||||
-rw-r--r-- | tests/utils.py | 10 | ||||
-rw-r--r-- | tests/utils_cib.py | 12 | ||||
-rw-r--r-- | tests/utils_xml.py | 14 |
16 files changed, 174 insertions, 122 deletions
diff --git a/tests/_bootstart.py b/tests/_bootstart.py new file mode 100644 index 0000000..55e1f0c --- /dev/null +++ b/tests/_bootstart.py @@ -0,0 +1,11 @@ +# -*- coding: UTF-8 -*- +# Copyright 2014 Red Hat, Inc. +# Part of clufter project +# Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt) +"""Bootstrap main runner""" +__author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" + + +if __name__ == '__main__': + from unittest import main + main() diff --git a/tests/_bootstrap.py b/tests/_bootstrap.py index ca92b4a..91d490f 100644 --- a/tests/_bootstrap.py +++ b/tests/_bootstrap.py @@ -1,19 +1,44 @@ # -*- coding: UTF-8 -*- -# Copyright 2013 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # Part of clufter project # Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt) """Bootstrap the environment for testing""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -from sys import path -from os.path import dirname, abspath +from sys import modules, path +from os.path import basename, dirname, abspath if __name__ != 'main_bootstrap': + # XXX recognize when this file executed directly and report + # if not run from main-bootstrap, verbose logging desired from os import environ import logging logging.basicConfig() logging.getLogger().setLevel(environ.get('LOGLEVEL', logging.DEBUG)) -path.insert(0, reduce(lambda x, y: dirname(x), xrange(3), abspath(__file__))) +# inject PYTHONPATH we are to use +root = reduce(lambda x, y: dirname(x), xrange(2), abspath(__file__)) +path.insert(0, dirname(root)) + +# set the correct __package__ for relative imports +__package__ = basename(root) +if __package__ not in modules: + modules[__package__] = __import__(__package__) + +# also normalize the __file__ +__file__ = abspath(__file__) + + +# XXX previous attempt to get unittest.main executed automagically at the end, +# which was failing likely because unittest uses Threading that register +# another atexit handler somehow interfering w/ its main started from here +#if __name__ == '__main__': +# def main() +# from atexit import register +# from unittest import main +# register(main) +# # hmm, see https://code.google.com/p/modwsgi/issues/detail?id=197 +# # https://github.com/GrahamDumpleton/mod_wsgi/commit/fdef274 +# register(lambda: __import__('dummy_threading')) diff --git a/tests/_common.py b/tests/_common.py index becea9a..5b63be5 100644 --- a/tests/_common.py +++ b/tests/_common.py @@ -1,21 +1,22 @@ # -*- coding: UTF-8 -*- -# Copyright 2013 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # Part of clufter project # Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt) """Common base for testing""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest -import _bootstrap # known W402, required +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -from clufter.format_manager import FormatManager -from clufter.filter_manager import FilterManager +from unittest import TestCase -class CommonFilterTestCase(unittest.TestCase): +from .filter_manager import FilterManager + + +class CommonFilterTestCase(TestCase): def setUp(self): - self.flt_mgr = FilterManager(FormatManager()) + self.flt_mgr = FilterManager.init_lookup() #def tearDown(self): # self.flt_mgr.registry.setup(True) # start from scratch diff --git a/tests/ccs2coroxml.py b/tests/ccs2coroxml.py index 815ff38..380a1a4 100644 --- a/tests/ccs2coroxml.py +++ b/tests/ccs2coroxml.py @@ -18,3 +18,6 @@ class Main(CommonFilterTestCase): out_obj = self.flt_mgr('ccs2needlexml', ('etree', out_obj('etree')), validator_specs={'':''}) print out_obj('bytestring') + + +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/ccs2needle_xslt.py b/tests/ccs2needle_xslt.py index d71b7e0..f11ac5e 100644 --- a/tests/ccs2needle_xslt.py +++ b/tests/ccs2needle_xslt.py @@ -5,35 +5,41 @@ """Testing destilling XSLT from the sparse tree-organized snippets""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) + + +from unittest import TestCase from os.path import dirname, join #from pprint import pprint from lxml import etree -import _bootstrap # known W402, required - -from clufter.filter import XMLFilter -from clufter.format import formats -formats = formats.plugins -from clufter.utils_prog import dirname_x +from .filter import XMLFilter +from .format_manager import FormatManager +from .utils_prog import dirname_x #WALK_DIR = join(dirname_x(__file__, 2), 'filters', 'cluster') WALK_DIR = join(dirname_x(__file__, 2), 'filters') -class Ccs2NeedleXsltViewOnly(unittest.TestCase): +class Ccs2NeedleXsltViewOnly(TestCase): + def setUp(self): + self.fmt_mgr = fmt_mgr = FormatManager() + self.formats = fmt_mgr.plugins + + def tearDown(self): + self.fmt_mgr.registry.setup(True) + def testXSLTTemplate2(self): + formats = self.formats flt = XMLFilter(formats) in_obj = formats['ccs']('file', join(dirname(__file__), 'filled.conf')) - r = flt.get_template(in_obj, symbol='ccs2needlexml', - root_dir=WALK_DIR) - + r = flt.get_template(in_obj, symbol='ccs2needlexml', root_dir=WALK_DIR) ret = r if isinstance(r, list) else [r] print "\n".join([etree.tostring(i, pretty_print=True) for i in ret]) assert not isinstance(r, list) -if __name__ == '__main__': - unittest.main() + +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/command.py b/tests/command.py index ed9d8cb..e83f4e0 100644 --- a/tests/command.py +++ b/tests/command.py @@ -5,31 +5,27 @@ """Testing command""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) + + +from unittest import TestCase from os.path import dirname, join from os import remove, stat #from pprint import pprint -import _bootstrap # known W402, required - -from clufter.command import Command, CommandError +from .command import Command, CommandError +from .filter_manager import FilterManager -from clufter.filters.ccs2ccsflat import ccs2ccsflat -from clufter.filters.ccsflat2pcs import ccsflat2pcs -from clufter.filters.ccs2coro import ccs2needlexml - -from clufter.format import formats +from .format import formats formats = formats.plugins -class ChainResolve(unittest.TestCase): +class ChainResolve(TestCase): def testShapeAndProtocolMatch(self): + filters = FilterManager.init_lookup('ccs2ccsflat', + 'ccsflat2pcs', + 'ccs2needlexml').plugins from tempfile import mktemp - filters = dict( - ccs2ccsflat=ccs2ccsflat(formats), - ccsflat2pcs=ccsflat2pcs(formats), - ccs2needlexml=ccs2needlexml(formats), - ) testfile = join(dirname(__file__), 'empty.conf') testoutput = mktemp(prefix='out', suffix='.conf', dir=join(dirname(__file__), 'tmp')) @@ -126,5 +122,4 @@ class ChainResolve(unittest.TestCase): continue -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/command_context.py b/tests/command_context.py index dcc9088..b8ac0c1 100644 --- a/tests/command_context.py +++ b/tests/command_context.py @@ -5,14 +5,15 @@ """Testing command context""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -import _bootstrap # known W402, required -from clufter.command_context import CommandContextBase +from unittest import TestCase +from .command_context import CommandContextBase -class TestCommandContextBase(unittest.TestCase): + +class TestCommandContextBase(TestCase): def testAnabasisConstructor(self): ccb = CommandContextBase({'a': {'b': {'c': {'d': {'e': 42}}}}}) e = ccb['a']['b']['c']['d'] @@ -57,5 +58,4 @@ class TestCommandContextBase(unittest.TestCase): self.assertTrue(ccb['a']['b'] == 43) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/command_manager.py b/tests/command_manager.py index f744112..d346cba 100644 --- a/tests/command_manager.py +++ b/tests/command_manager.py @@ -5,15 +5,16 @@ """Testing command manager""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -import _bootstrap # known W402, required -from clufter.command_manager import CommandManager -from clufter.commands.ccs2pcs import ccs2pcs_needle +from unittest import TestCase +from .command_manager import CommandManager +from .commands.ccs2pcs import ccs2pcs_needle -class CommandManagerTestCase(unittest.TestCase): + +class CommandManagerTestCase(TestCase): def setUp(self): self.cmd_mgr = CommandManager.init_lookup() @@ -31,5 +32,4 @@ class Default(CommandManagerTestCase): self.assertEqual(cls, type(commands[cls.name])) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/filter.py b/tests/filter.py index 00270a1..da36e20 100644 --- a/tests/filter.py +++ b/tests/filter.py @@ -1,22 +1,23 @@ # -*- coding: UTF-8 -*- -# Copyright 2013 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # Part of clufter project # Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt) """Testing filter""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) + + +from unittest import TestCase from os.path import dirname, join #from pprint import pprint from lxml import etree -import _bootstrap # known W402, required - -from clufter.format import formats +from .format import formats formats = formats.plugins -from clufter.formats.ccs import ccs -from clufter.filter import XMLFilter +from .formats.ccs import ccs +from .filter import XMLFilter WALK_DIR = join(dirname(__file__), 'XMLFormat-walk') @@ -36,7 +37,7 @@ def fnc(symbol, elem, children): return symbol, "element: " + elem.tag, children.values() -class XMLTraverse(unittest.TestCase): +class XMLTraverse(TestCase): def testDirectXSLT(self): flt = XMLFilter(formats) in_obj = ccs('file', join(dirname(__file__), 'filled.conf')) @@ -66,5 +67,4 @@ class XMLTraverse(unittest.TestCase): self.assertTrue(ret == RESULT_DIRECT_XSLT) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/filter_manager.py b/tests/filter_manager.py index f8f929d..85f9635 100644 --- a/tests/filter_manager.py +++ b/tests/filter_manager.py @@ -5,20 +5,21 @@ """Testing filter manager""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest -from os.path import dirname, join +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) + -import _bootstrap # known W402, required +from unittest import TestCase +from os.path import dirname, join -from clufter.format_manager import FormatManager -from clufter.format import formats +from .format_manager import FormatManager +from .format import formats formats = formats.plugins -from clufter.filter import Filter -from clufter.filter_manager import FilterManager -from clufter.utils import head_tail +from .filter import Filter +from .filter_manager import FilterManager +from .utils import head_tail -class FilterManagerTestCase(unittest.TestCase): +class FilterManagerTestCase(TestCase): def setUp(self): self.flt_mgr = FilterManager(FormatManager()) @@ -31,8 +32,8 @@ class Default(FilterManagerTestCase): def test_default(self): # NOTE imports has to be just there due to environment changed # by "starting from scratch" + plugin discovery elsewhere - from clufter.filters.ccs2ccsflat import ccs2ccsflat - from clufter.filters.ccsflat2pcs import ccsflat2pcs + from .filters.ccs2ccsflat import ccs2ccsflat + from .filters.ccsflat2pcs import ccsflat2pcs filters = self.flt_mgr.filters #print filters for cls in ccs2ccsflat, ccsflat2pcs: @@ -59,7 +60,7 @@ class CompositeFormatIO(FilterManagerTestCase): def setUp(self): @Filter.deco(('ccs', 'ccs'), ('ccs-flat', 'ccs-flat')) def double_ccs2ccsflat(flt_ctxt, in_objs, verify=False): - from clufter.filters.ccs2ccsflat import ccs2ccsflat + from .filters.ccs2ccsflat import ccs2ccsflat ccs2ccsflat = ccs2ccsflat(formats) outs = [] for in_obj in in_objs: @@ -90,5 +91,4 @@ class CompositeFormatIO(FilterManagerTestCase): self.assertEqual(results[0], f.read()) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/format.py b/tests/format.py index 33894a6..2dbc23e 100644 --- a/tests/format.py +++ b/tests/format.py @@ -1,24 +1,26 @@ # -*- coding: UTF-8 -*- -# Copyright 2013 Red Hat, Inc. +# Copyright 2014 Red Hat, Inc. # Part of clufter project # Licensed under GPLv2+ (a copy included | http://gnu.org/licenses/gpl-2.0.txt) """Testing format""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest -from lxml import etree +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) + + from os.path import dirname, join +from unittest import TestCase #from pprint import pprint -import _bootstrap # known W402, required +from lxml import etree -from clufter.format import FormatError -from clufter.formats.ccs import ccs -from clufter.formats.coro import coroxml_needle -from clufter.utils import head_tail +from .format import FormatError +from .formats.ccs import ccs +from .formats.coro import coroxml_needle +from .utils import head_tail -class XMLFormatWalkTestCase(unittest.TestCase): +class XMLFormatWalkTestCase(TestCase): walk_dir = join(dirname(__file__), 'XMLFormat-walk') result_walk_full = { 'cluster': ('cluster-full', { @@ -58,7 +60,7 @@ class XMLFormatWalkTestCase(unittest.TestCase): self.assertTrue(r == self.result_walk_sparse) -class XMLValidationTestCase(unittest.TestCase): +class XMLValidationTestCase(TestCase): coro_input_ok = join(dirname(__file__), 'coro_ok.xml') coro_input_fail = join(dirname(__file__), 'coro_fail.xml') @@ -91,5 +93,4 @@ class XMLValidationTestCase(unittest.TestCase): self.assertTrue(entries) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/format_manager.py b/tests/format_manager.py index 7a3d3b7..9478ccd 100644 --- a/tests/format_manager.py +++ b/tests/format_manager.py @@ -5,17 +5,18 @@ """Testing format manager""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -import _bootstrap # known W402, required -from clufter.format_manager import FormatManager -from clufter.formats.ccs import ccs -from clufter.formats.ccs import ccs_flat -from clufter.formats.pcs import pcs +from unittest import TestCase +from .format_manager import FormatManager +from .formats.ccs import ccs +from .formats.ccs import ccs_flat +from .formats.pcs import pcs -class FormatManagerTestCase(unittest.TestCase): + +class FormatManagerTestCase(TestCase): def setUp(self): self.fmt_mgr = FormatManager() @@ -37,9 +38,9 @@ class Default(FormatManagerTestCase): class Injection(FormatManagerTestCase): - formats = {'frobniccs': ccs} def setUp(self): + self.formats = {'frobniccs': ccs} self.fmt_mgr = FormatManager(paths=None, plugins=self.formats) def test_injection(self): @@ -51,5 +52,4 @@ class Injection(FormatManagerTestCase): self.assertEqual(fmt_cls, formats[fmt_id]) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/run_cmd.py b/tests/run_cmd.py index 716609e..7e701b5 100644 --- a/tests/run_cmd.py +++ b/tests/run_cmd.py @@ -5,16 +5,17 @@ """Testing direct command run (e.g., when clufter used as a library)""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) + + +from unittest import TestCase from os.path import dirname, exists, join #from os import unlink -import _bootstrap - -from clufter.command_manager import CommandManager +from .command_manager import CommandManager -class Main(unittest.TestCase): +class Main(TestCase): #def testCcs2PcsNeedle(self): # testfile = join(dirname(__file__), 'filled.conf') # testcib = join(dirname(__file__), '.testcib.xml') @@ -42,7 +43,7 @@ class Main(unittest.TestCase): def testCcs2PcsNeedleBetter(self): testfile = join(dirname(__file__), 'filled.conf') - from clufter.formats.simpleconfig import simpleconfig + from .formats.simpleconfig import simpleconfig #from clufter.protocol import protocols #protocols = protocols.plugins @@ -67,7 +68,8 @@ class Main(unittest.TestCase): self.assertFalse(cmd(clufter_args)) # just the existence of non-null strings is enough for now... map(lambda fspec: self.assertTrue(fspec['passout']), outputs.values()) + #from pprint import pprint + #pprint(outputs['coro']['passout']) -if __name__ == '__main__': - unittest.main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/utils.py b/tests/utils.py index d166ea0..cb14208 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -5,11 +5,12 @@ """Testing utils module""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -from unittest import TestCase, main +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -import _bootstrap # known W402, required -from clufter.utils import func_defaults_varnames +from unittest import TestCase + +from .utils import func_defaults_varnames class FuncDefaultsVarnames(TestCase): @@ -39,5 +40,4 @@ class FuncDefaultsVarnames(TestCase): self.assertEqual(len(varnames), 2) -if __name__ == '__main__': - main() +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/utils_cib.py b/tests/utils_cib.py index 9052dd1..d739a66 100644 --- a/tests/utils_cib.py +++ b/tests/utils_cib.py @@ -5,13 +5,14 @@ """Testing CIB helpers""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -import _bootstrap # known W402, required -from clufter.utils_cib import ResourceSpec +from unittest import TestCase -class TestResourceSpec(unittest.TestCase): +from .utils_cib import ResourceSpec + +class TestResourceSpec(TestCase): def test_xsl_attrs_ocf(self): rs = ResourceSpec('ocf:heartbeat:Filesystem') self.assertTrue(rs.res_class == 'ocf') @@ -22,3 +23,6 @@ class TestResourceSpec(unittest.TestCase): rs = ResourceSpec('systemd:smb') self.assertTrue(rs.res_class == 'systemd') self.assertTrue(rs.res_type == 'smb') + + +execfile(op.join(op.dirname(__file__), '_bootstart.py')) diff --git a/tests/utils_xml.py b/tests/utils_xml.py index 525e4de..ab36c57 100644 --- a/tests/utils_xml.py +++ b/tests/utils_xml.py @@ -5,18 +5,19 @@ """Testing XML helpers""" __author__ = "Jan Pokorný <jpokorny @at@ Red Hat .dot. com>" -import unittest +import os.path as op; execfile(op.join(op.dirname(__file__), '_bootstrap.py')) -import _bootstrap # known W402, required + +from unittest import TestCase from lxml import etree from os.path import dirname, join -from clufter.utils_xml import rng_pivot -from clufter.utils_prog import dirname_x +from .utils_xml import rng_pivot +from .utils_prog import dirname_x -class TestRngPivot(unittest.TestCase): +class TestRngPivot(TestCase): def test_rng_pivot(self): #p = join(dirname_x(__file__, 2), 'formats', 'corosync', 'corosync.rng') p = join(dirname(__file__), 'corosync.rng') @@ -31,3 +32,6 @@ class TestRngPivot(unittest.TestCase): with open(p) as f: expected = f.read() self.assertTrue(etree.tostring(et) == expected) + + +execfile(op.join(op.dirname(__file__), '_bootstart.py')) |