Esempio n. 1
0
 def test_w_testing_passed(self):
     import os
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests import samplepackage
     from zope.configuration.tests.samplepackage import foo
     def _assertTestingTrue(func):
         def _wrapper(*args, **kw):
             assert(kw['testing'])
             return func(*args, **kw)
         return _wrapper
     fqn = _packageFile(samplepackage, 'configure.zcml')
     context = xmlconfig._getContext()
     context.execute_actions = _assertTestingTrue(context.execute_actions)
     with _Monkey(xmlconfig,
                     processxmlfile=_assertTestingTrue(
                                             xmlconfig.processxmlfile)):
         self._callFUT(open(fqn), True)
     self.assertEqual(len(foo.data), 1)
     data = foo.data.pop(0)
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertTrue(
         data.info.file.endswith(
             os.path.normpath('tests/samplepackage/configure.zcml')))
     self.assertEqual(data.info.line, 12)
     self.assertEqual(data.info.column, 2)
     self.assertEqual(data.info.eline, 12)
     self.assertEqual(data.info.ecolumn, 29)
Esempio n. 2
0
    def test_w_testing_passed(self):
        import os
        from zope.configuration import xmlconfig
        from zope.configuration._compat import b
        from zope.configuration.tests import samplepackage
        from zope.configuration.tests.samplepackage import foo

        def _assertTestingTrue(func):
            def _wrapper(*args, **kw):
                assert (kw['testing'])
                return func(*args, **kw)

            return _wrapper

        fqn = _packageFile(samplepackage, 'configure.zcml')
        context = xmlconfig._getContext()
        context.execute_actions = _assertTestingTrue(context.execute_actions)
        with _Monkey(xmlconfig,
                     processxmlfile=_assertTestingTrue(
                         xmlconfig.processxmlfile)):
            self._callFUT(open(fqn), True)
        self.assertEqual(len(foo.data), 1)
        data = foo.data.pop(0)
        self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
        self.assertTrue(
            data.info.file.endswith(
                os.path.normpath('tests/samplepackage/configure.zcml')))
        self.assertEqual(data.info.line, 12)
        self.assertEqual(data.info.column, 2)
        self.assertEqual(data.info.eline, 12)
        self.assertEqual(data.info.ecolumn, 29)
Esempio n. 3
0
 def test__validate_w_value_type(self):
     from zope.schema import Text
     from zope.schema.interfaces import WrongType
     from zope.configuration._compat import u
     from zope.configuration._compat import b
     go = self._makeOne(value_type=Text())
     go.validate(u(''))
     for value in [0, 0.0, (), [], set(), frozenset(), b('')]:
         self.assertRaises(WrongType, go._validate, value)
Esempio n. 4
0
 def test__validate_w_value_type(self):
     from zope.schema import Text
     from zope.schema.interfaces import WrongType
     from zope.configuration._compat import u
     from zope.configuration._compat import b
     go = self._makeOne(value_type=Text())
     go.validate(u(''))
     for value in [0, 0.0, (), [], set(), frozenset(), b('')]:
         self.assertRaises(WrongType, go._validate, value)
Esempio n. 5
0
 def test_wo_execute_wo_context(self):
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     context = self._callFUT(xml, execute=False)
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 6
0
 def test_wo_execute_wo_context(self):
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     context = self._callFUT(xml, execute=False)
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 7
0
 def test_wo_execute_wo_context_wo_package(self):
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         context = self._callFUT(file_name, execute=False)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % file_name, (), {}))
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 8
0
 def test_w_files_passed_and_package(self):
     from zope.configuration import xmlconfig
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests import samplepackage
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     before_stack = context.stack[:]
     fqn1 = _packageFile(samplepackage, 'baz1.zcml')
     fqn2 = _packageFile(samplepackage, 'baz2.zcml')
     fqn3 = _packageFile(samplepackage, 'baz3.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         self._callFUT(context, package=samplepackage, files='baz*.zcml')
     self.assertEqual(len(logger.debugs), 3)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn1, (), {}))
     self.assertEqual(logger.debugs[1], ('include %s' % fqn2, (), {}))
     self.assertEqual(logger.debugs[2], ('include %s' % fqn3, (), {}))
     self.assertEqual(len(context.actions), 2)
     action = context.actions[0]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn2,))
     self.assertIsInstance(action['args'][0], foo.stuff)
     self.assertEqual(action['args'][0].args, (('x', b('foo')), ('y', 2)))
     action = context.actions[1]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn3,))
     self.assertIsInstance(action['args'][0], foo.stuff)
     self.assertEqual(action['args'][0].args, (('x', b('foo')), ('y', 3)))
     self.assertEqual(context.stack, before_stack)
     self.assertEqual(len(context._seen_files), 3)
     self.assertIn(fqn1, context._seen_files)
     self.assertIn(fqn2, context._seen_files)
     self.assertIn(fqn3, context._seen_files)
Esempio n. 9
0
 def test_wo_execute_wo_context_wo_package(self):
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         context = self._callFUT(file_name, execute=False)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % file_name, (), {}))
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 10
0
 def test_w_files_passed_and_package(self):
     from zope.configuration import xmlconfig
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests import samplepackage
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     before_stack = context.stack[:]
     fqn1 = _packageFile(samplepackage, 'baz1.zcml')
     fqn2 = _packageFile(samplepackage, 'baz2.zcml')
     fqn3 = _packageFile(samplepackage, 'baz3.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         self._callFUT(context, package=samplepackage, files='baz*.zcml')
     self.assertEqual(len(logger.debugs), 3)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn1, (), {}))
     self.assertEqual(logger.debugs[1], ('include %s' % fqn2, (), {}))
     self.assertEqual(logger.debugs[2], ('include %s' % fqn3, (), {}))
     self.assertEqual(len(context.actions), 2)
     action = context.actions[0]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn2, ))
     self.assertIsInstance(action['args'][0], foo.stuff)
     self.assertEqual(action['args'][0].args, (('x', b('foo')), ('y', 2)))
     action = context.actions[1]
     self.assertEqual(action['callable'], foo.data.append)
     self.assertEqual(action['includepath'], (fqn3, ))
     self.assertIsInstance(action['args'][0], foo.stuff)
     self.assertEqual(action['args'][0].args, (('x', b('foo')), ('y', 3)))
     self.assertEqual(context.stack, before_stack)
     self.assertEqual(len(context._seen_files), 3)
     self.assertIn(fqn1, context._seen_files)
     self.assertIn(fqn2, context._seen_files)
     self.assertIn(fqn3, context._seen_files)
Esempio n. 11
0
 def test_w_execute(self):
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     context = self._callFUT(xml)
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertTrue(data.info.file, '<string>')
     self.assertEqual(data.info.line, 12)
     self.assertEqual(data.info.column, 2)
     self.assertEqual(data.info.eline, 12)
     self.assertEqual(data.info.ecolumn, 29)
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
Esempio n. 12
0
 def test_w_execute(self):
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     context = self._callFUT(xml)
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertTrue(data.info.file, '<string>')
     self.assertEqual(data.info.line, 12)
     self.assertEqual(data.info.column, 2)
     self.assertEqual(data.info.eline, 12)
     self.assertEqual(data.info.ecolumn, 29)
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
Esempio n. 13
0
 def test_ctor_w_module(self):
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     from zope.configuration.tests import samplepackage
     fqn = _packageFile(samplepackage, 'configure.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         xc = self._makeOne("configure.zcml", samplepackage)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn, (), {}))
     self.assertEqual(len(foo.data), 0)  # no execut_actions
     self.assertEqual(len(xc.context.actions), 1)
     action = xc.context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 14
0
 def test_ctor_w_module(self):
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     from zope.configuration.tests import samplepackage
     fqn = _packageFile(samplepackage, 'configure.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         xc = self._makeOne("configure.zcml", samplepackage)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn, (), {}))
     self.assertEqual(len(foo.data), 0) # no execut_actions
     self.assertEqual(len(xc.context.actions), 1)
     action = xc.context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 15
0
 def test_wo_execute_w_context(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     ret = self._callFUT(xml, context=context, execute=False)
     self.assertTrue(ret is context)
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 16
0
 def test_wo_execute_w_context(self):
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     file_name = path("samplepackage", "configure.zcml")
     with open(file_name) as f:
         xml = f.read()
     ret = self._callFUT(xml, context=context, execute=False)
     self.assertTrue(ret is context)
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 17
0
 def test_ctor_w_global_context_missing(self):
     import os
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     here = os.path.dirname(__file__)
     path = os.path.join(here, "samplepackage", "configure.zcml")
     logger = LoggerStub()
     xmlconfig._context = None
     with _Monkey(xmlconfig, logger=logger):
         xc = self._makeOne(path)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % path, (), {}))
     self.assertEqual(len(foo.data), 0)  # no execut_actions
     self.assertEqual(len(xc.context.actions), 1)
     action = xc.context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 18
0
 def test_ctor_w_global_context_missing(self):
     import os
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     here = os.path.dirname(__file__)
     path = os.path.join(here, "samplepackage", "configure.zcml")
     logger = LoggerStub()
     xmlconfig._context = None
     with _Monkey(xmlconfig, logger=logger):
         xc = self._makeOne(path)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % path, (), {}))
     self.assertEqual(len(foo.data), 0) # no execut_actions
     self.assertEqual(len(xc.context.actions), 1)
     action = xc.context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 19
0
 def test_w_valid_xml_fp(self):
     # Integration test, really
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file = open(path("samplepackage", "configure.zcml"))
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     self._callFUT(file, context)
     self.assertEqual(foo.data, [])
     context.execute_actions()
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertEqual(clean_info_path(repr(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
     self.assertEqual(clean_info_path(str(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
             + '    <test:foo x="blah" y="0" />')
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
Esempio n. 20
0
 def test_w_valid_xml_fp(self):
     # Integration test, really
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file = open(path("samplepackage", "configure.zcml"))
     context = ConfigurationMachine()
     registerCommonDirectives(context)
     self._callFUT(file, context)
     self.assertEqual(foo.data, [])
     context.execute_actions()
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertEqual(clean_info_path(repr(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
     self.assertEqual(clean_info_path(str(data.info)),
             'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
             + '    <test:foo x="blah" y="0" />')
     self.assertEqual(data.package, None)
     self.assertEqual(data.basepath, None)
Esempio n. 21
0
 def test_w_execute(self):
     import os
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests.samplepackage import foo
     file_name = path("samplepackage", "configure.zcml")
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         context = self._callFUT(file_name)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % file_name, (), {}))
     data = foo.data.pop()
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertTrue(data.info.file.endswith(
                     os.path.normpath('tests/samplepackage/configure.zcml')))
     self.assertEqual(data.info.line, 12)
     self.assertEqual(data.info.column, 2)
     self.assertEqual(data.info.eline, 12)
     self.assertEqual(data.info.ecolumn, 29)
     self.assertEqual(data.package, None)
     self.assertTrue(data.basepath.endswith(
                     os.path.normpath('tests/samplepackage')))
Esempio n. 22
0
 def test_wo_execute_w_context(self):
     from zope.configuration import xmlconfig
     from zope.configuration.config import ConfigurationMachine
     from zope.configuration.xmlconfig import registerCommonDirectives
     from zope.configuration._compat import b
     from zope.configuration.tests import samplepackage
     from zope.configuration.tests.samplepackage import foo
     context = ConfigurationMachine()
     context.package = samplepackage
     registerCommonDirectives(context)
     file_name = path("samplepackage", "configure.zcml")
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         ret = self._callFUT('configure.zcml', context=context,
                             execute=False)
     self.assertTrue(ret is context)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % file_name, (), {}))
     self.assertEqual(len(foo.data), 0)
     self.assertEqual(len(context.actions), 1)
     action = context.actions[0]
     self.assertEqual(action['discriminator'], (('x', b('blah')), ('y', 0)))
     self.assertEqual(action['callable'], foo.data.append)
Esempio n. 23
0
 def test___call__(self):
     import os
     from zope.configuration import xmlconfig
     from zope.configuration._compat import b
     from zope.configuration.tests import samplepackage
     from zope.configuration.tests.samplepackage import foo
     fqn = _packageFile(samplepackage, 'configure.zcml')
     logger = LoggerStub()
     with _Monkey(xmlconfig, logger=logger):
         xc = self._makeOne(fqn)
     self.assertEqual(len(logger.debugs), 1)
     self.assertEqual(logger.debugs[0], ('include %s' % fqn, (), {}))
     self.assertEqual(len(foo.data), 0)
     xc() # call to process the actions
     self.assertEqual(len(foo.data), 1)
     data = foo.data.pop(0)
     self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
     self.assertTrue(data.info.file.endswith(
                     os.path.normpath('tests/samplepackage/configure.zcml')))
     self.assertEqual(data.info.line, 12)
     self.assertEqual(data.info.column, 2)
     self.assertEqual(data.info.eline, 12)
     self.assertEqual(data.info.ecolumn, 29)
Esempio n. 24
0
 def test__validate_wo_value_type(self):
     from zope.configuration._compat import u
     from zope.configuration._compat import b
     go = self._makeOne(value_type=None)
     for value in [0, 0.0, (), [], set(), frozenset(), u(''), b('')]:
         go._validate(value) #noraise
Esempio n. 25
0
 def test__validate_wo_value_type(self):
     from zope.configuration._compat import u
     from zope.configuration._compat import b
     go = self._makeOne(value_type=None)
     for value in [0, 0.0, (), [], set(), frozenset(), u(''), b('')]:
         go._validate(value) #noraise