summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert JW Regeer <bertjw@regeer.org>2013-09-04 22:31:04 -0600
committerBert JW Regeer <bertjw@regeer.org>2013-09-04 22:31:04 -0600
commit1eb618a1cefbb95a5bf656b721ac82e50eb3beae (patch)
treebcdb1946f1f59c78aa683e876453a9e12bee01a9
parentb4755a79f7318a9100714c1fdabbc2cc57c016b4 (diff)
downloadpyramid-1eb618a1cefbb95a5bf656b721ac82e50eb3beae.tar.gz
pyramid-1eb618a1cefbb95a5bf656b721ac82e50eb3beae.tar.bz2
pyramid-1eb618a1cefbb95a5bf656b721ac82e50eb3beae.zip
Remove traces of Chameleon from tests/fixers
-rw-r--r--pyramid/fixers/fix_bfg_imports.py220
-rw-r--r--pyramid/tests/test_chameleon_text.py145
-rw-r--r--pyramid/tests/test_chameleon_zpt.py175
3 files changed, 0 insertions, 540 deletions
diff --git a/pyramid/fixers/fix_bfg_imports.py b/pyramid/fixers/fix_bfg_imports.py
deleted file mode 100644
index 0046aad30..000000000
--- a/pyramid/fixers/fix_bfg_imports.py
+++ /dev/null
@@ -1,220 +0,0 @@
-import os
-import re
-import sys
-
-from lib2to3.refactor import get_fixers_from_package
-from lib2to3.refactor import RefactoringTool
-from lib2to3.fixer_util import Name
-from lib2to3.fixer_util import attr_chain
-from lib2to3 import fixer_base
-
-MAPPING = {'repoze.bfg':'pyramid'}
-
-MODULE_NAMES = (
- 'compat',
- 'configuration',
- 'authentication',
- 'authorization',
- 'chameleon_text',
- 'chameleon_zpt',
- 'decorator',
- 'encode',
- 'events',
- 'exceptions',
- 'i18n',
- 'includes',
- 'interfaces',
- 'location',
- 'log',
- 'paster',
- 'path',
- 'registry',
- 'renderers',
- 'request',
- 'resource',
- 'router',
- 'scripting',
- 'security',
- 'settings',
- 'static',
- 'testing',
- 'tests',
- 'tests.test_configuration',
- 'tests.ccbugapp',
- 'tests.exceptionviewapp',
- 'tests.exceptionviewapp.models',
- 'tests.fixtureapp',
- 'tests.fixtureapp.models',
- 'tests.grokkedapp',
- 'tests.hybridapp',
- 'tests.localeapp',
- 'tests.restbugapp',
- 'tests.routesapp',
- 'threadlocal',
- 'traversal',
- 'urldispatch',
- 'url',
- 'view',
- 'wsgi',
- 'zcml',
- )
-
-for name in MODULE_NAMES:
- frm = 'repoze.bfg.' + name
- to = 'pyramid.' + name
- MAPPING[frm] = to
-
-def alternates(members):
- return "(" + "|".join(map(str, members)) + ")"
-
-def build_pattern(mapping=MAPPING):
- mod_list = []
-
- for key in mapping:
- splitted = key.split('.')
- joined = " '.' ".join(["'%s'" %s for s in splitted])
- mod_list.append(joined)
-
- mod_list = ' | '.join(
- ['module_name=dotted_name< %s >' %s for s in mod_list])
-
- yield """name_import=import_name< 'import' ((%s) |
- multiple_imports=dotted_as_names< any* (%s) any* >) >
- """ % (mod_list, mod_list)
- yield """import_from< 'from' (%s) 'import' ['(']
- ( any | import_as_name< any 'as' any > |
- import_as_names< any* >) [')'] >
- """ % mod_list
- yield """import_name< 'import' (dotted_as_name< (%s) 'as' any > |
- multiple_imports=dotted_as_names<
- any* dotted_as_name< (%s) 'as' any > any* >) >
- """ % (mod_list, mod_list)
-
- # Find usages of module members in code e.g. ``repoze.bfg`` or
- # ``repoze.bfg.configuration``
- # 'repoze' trailer< '.' 'bfg' > trailer< '.' 'configuration' >
- bare_names = []
- for key in mapping:
- splitted = key.split('.')
- tmp = ["'%s'" % splitted[0]]
- for thing in splitted[1:]:
- tmp.append(" trailer< '.' '%s' > " % thing)
- bare_name = ''.join(tmp)
- bare_names.append(bare_name)
-
- names = alternates(bare_names)
- yield "power< bare_with_attr=%s >" % names
-
-class FixBfgImports(fixer_base.BaseFix):
-
- mapping = MAPPING
- run_order = 8
-
- def build_pattern(self):
- pattern = "|".join(build_pattern(self.mapping))
- return pattern
-
- def compile_pattern(self):
- # We override this, so MAPPING can be pragmatically altered and the
- # changes will be reflected in PATTERN.
- self.PATTERN = self.build_pattern()
- super(FixBfgImports, self).compile_pattern()
-
- # Don't match the node if it's within another match.
- def match(self, node):
- match = super(FixBfgImports, self).match
- results = match(node)
- if results:
- # Module usage could be in the trailer of an attribute lookup, so we
- # might have nested matches when "bare_with_attr" is present.
- if "bare_with_attr" not in results and \
- any(match(obj) for obj in attr_chain(node, "parent")):
- return False
- return results
- return False
-
- def start_tree(self, tree, filename):
- super(FixBfgImports, self).start_tree(tree, filename)
- self.replace = {}
-
- def transform(self, node, results):
- # Mostly copied from fix_imports.py
- import_mod = results.get("module_name")
- if import_mod:
- try:
- mod_name = import_mod.value
- except AttributeError:
- # XXX: A hack to remove whitespace prefixes and suffixes
- mod_name = str(import_mod).strip()
- new_name = self.mapping[mod_name]
- import_mod.replace(Name(new_name, prefix=import_mod.prefix))
- if "name_import" in results:
- # If it's not a "from x import x, y" or "import x as y" import,
- # marked its usage to be replaced.
- self.replace[mod_name] = new_name
- if "multiple_imports" in results:
- # This is a nasty hack to fix multiple imports on a line (e.g.,
- # "import StringIO, urlparse"). The problem is that I can't
- # figure out an easy way to make a pattern recognize the keys of
- # MAPPING randomly sprinkled in an import statement.
- results = self.match(node)
- if results:
- self.transform(node, results)
- else:
- # Replace usage of the module.
- bare_name_text = ''.join(map(str,results['bare_with_attr'])).strip()
- new_name = self.replace.get(bare_name_text)
- bare_name = results["bare_with_attr"][0]
-
- if new_name:
- node.replace(Name(new_name, prefix=bare_name.prefix))
-
-MODULE_ALTERNATIVES = []
-for name in MODULE_NAMES:
- MODULE_ALTERNATIVES.append(r'\.' + re.escape(name)+r'[\w\.]*?')
-
-MODULE_ALTERNATIVES = '|'.join(MODULE_ALTERNATIVES)
-
-BFG_NS_RE = r'xmlns\s*?=\s*?[\'\"]http://namespaces\.repoze\.org/bfg[\'\"]'
-BFG_IN_ATTR = r'(repoze\.bfg)(%s)' % MODULE_ALTERNATIVES
-BFG_INCLUDE_IN_ATTR = r'repoze\.bfg\.includes'
-ATTR = re.compile(BFG_IN_ATTR, re.MULTILINE)
-INCLUDE_ATTR = re.compile(BFG_INCLUDE_IN_ATTR, re.MULTILINE)
-NS = re.compile(BFG_NS_RE, re.MULTILINE)
-
-def replace(match):
- return 'pyramid%s' % match.group(2)
-
-def fix_zcml(path):
- for root, dirs, files in os.walk(path):
- for file in files:
- if file.endswith('.zcml'):
- absfile = os.path.join(root, file)
- f = open(absfile, 'rb')
- text = f.read()
- f.close()
- newt = NS.sub('xmlns="http://pylonshq.com/pyramid"', text)
- newt = INCLUDE_ATTR.sub('pyramid_zcml', newt)
- newt = ATTR.sub(replace, newt)
- if text != newt:
- newf = open(absfile, 'wb')
- newf.write(newt)
- newf.flush()
- newf.close()
-
- for dir in dirs:
- if dir.startswith('.'):
- dirs.remove(dir)
-
-def main(argv=None):
- if argv is None:
- argv = sys.argv
- path = argv[1]
- fixer_names = get_fixers_from_package('pyramid.fixers')
- tool = RefactoringTool(fixer_names)
- tool.refactor([path], write=True)
- fix_zcml(path)
-
-if __name__ == '__main__':
- main()
-
diff --git a/pyramid/tests/test_chameleon_text.py b/pyramid/tests/test_chameleon_text.py
deleted file mode 100644
index d9f20f241..000000000
--- a/pyramid/tests/test_chameleon_text.py
+++ /dev/null
@@ -1,145 +0,0 @@
-import sys
-import unittest
-
-from pyramid.compat import binary_type
-from pyramid import testing
-
-class Base(object):
- def setUp(self):
- self.config = testing.setUp()
-
- def tearDown(self):
- testing.tearDown()
-
- def _getTemplatePath(self, name):
- import os
- here = os.path.abspath(os.path.dirname(__file__))
- return os.path.join(here, 'fixtures', name)
-
-class Test_renderer_factory(Base, unittest.TestCase):
- def _callFUT(self, info):
- from pyramid.chameleon_text import renderer_factory
- return renderer_factory(info)
-
- def test_it(self):
- # this test is way too functional
- from pyramid.chameleon_text import TextTemplateRenderer
- info = DummyInfo()
- result = self._callFUT(info)
- self.assertEqual(result.__class__, TextTemplateRenderer)
-
-class TextTemplateRendererTests(Base, unittest.TestCase):
- def _getTargetClass(self):
- from pyramid.chameleon_text import TextTemplateRenderer
- return TextTemplateRenderer
-
- def _makeOne(self, *arg, **kw):
- klass = self._getTargetClass()
- return klass(*arg, **kw)
-
- def test_instance_implements_ITemplate(self):
- from zope.interface.verify import verifyObject
- from pyramid.interfaces import ITemplateRenderer
- path = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- verifyObject(ITemplateRenderer, self._makeOne(path, lookup))
-
- def test_class_implements_ITemplate(self):
- from zope.interface.verify import verifyClass
- from pyramid.interfaces import ITemplateRenderer
- verifyClass(ITemplateRenderer, self._getTargetClass())
-
- def test_template_reified(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template, instance.__dict__['template'])
-
- def test_template_with_ichameleon_translate(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.translate, lookup.translate)
-
- def test_template_with_debug_templates(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- lookup.debug = True
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.debug, True)
-
- def test_template_with_reload_templates(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- lookup.auto_reload = True
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.auto_reload, True)
-
- def test_template_without_reload_templates(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- lookup.auto_reload = False
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.auto_reload, False)
-
- def test_call(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- result = instance({}, {})
- self.assertTrue(isinstance(result, binary_type))
- self.assertEqual(result, b'Hello.\n')
-
- def test_call_with_nondict_value(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- self.assertRaises(ValueError, instance, None, {})
-
- def test_call_nonminimal(self):
- nonminimal = self._getTemplatePath('nonminimal.txt')
- lookup = DummyLookup()
- instance = self._makeOne(nonminimal, lookup)
- result = instance({'name':'Chris'}, {})
- self.assertTrue(isinstance(result, binary_type))
- self.assertEqual(result, b'Hello, Chris!\n')
-
- def test_implementation(self):
- minimal = self._getTemplatePath('minimal.txt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- result = instance.implementation()()
- self.assertTrue(isinstance(result, binary_type))
- self.assertEqual(result, b'Hello.\n')
-
-class DummyLookup(object):
- auto_reload=True
- debug = True
- def translate(self, msg): pass
-
-class DummyRegistry(object):
- def queryUtility(self, iface, name):
- self.queried = iface, name
- return None
-
- def registerUtility(self, impl, iface, name):
- self.registered = impl, iface, name
-
-class DummyInfo(object):
- def __init__(self):
- self.registry = DummyRegistry()
- self.type = '.pt'
- self.name = 'fixtures/minimal.pt'
- self.package = sys.modules[__name__]
- self.settings = {}
-
diff --git a/pyramid/tests/test_chameleon_zpt.py b/pyramid/tests/test_chameleon_zpt.py
deleted file mode 100644
index d7ca94298..000000000
--- a/pyramid/tests/test_chameleon_zpt.py
+++ /dev/null
@@ -1,175 +0,0 @@
-import sys
-import unittest
-
-from pyramid import testing
-from pyramid.compat import text_type
-
-class Base(object):
- def setUp(self):
- self.config = testing.setUp()
-
- def tearDown(self):
- testing.tearDown()
-
- def _getTemplatePath(self, name):
- import os
- here = os.path.abspath(os.path.dirname(__file__))
- return os.path.join(here, 'fixtures', name)
-
-class Test_renderer_factory(Base, unittest.TestCase):
- def _callFUT(self, info):
- from pyramid.chameleon_zpt import renderer_factory
- return renderer_factory(info)
-
- def test_it(self):
- # this test is way too functional
- from pyramid.chameleon_zpt import ZPTTemplateRenderer
- info = DummyInfo()
- result = self._callFUT(info)
- self.assertEqual(result.__class__, ZPTTemplateRenderer)
-
-class ZPTTemplateRendererTests(Base, unittest.TestCase):
- def _getTargetClass(self):
- from pyramid.chameleon_zpt import ZPTTemplateRenderer
- return ZPTTemplateRenderer
-
- def _makeOne(self, *arg, **kw):
- klass = self._getTargetClass()
- return klass(*arg, **kw)
-
- def test_instance_implements_ITemplate(self):
- from zope.interface.verify import verifyObject
- from pyramid.interfaces import ITemplateRenderer
- path = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- verifyObject(ITemplateRenderer, self._makeOne(path, lookup))
-
- def test_class_implements_ITemplate(self):
- from zope.interface.verify import verifyClass
- from pyramid.interfaces import ITemplateRenderer
- verifyClass(ITemplateRenderer, self._getTargetClass())
-
- def test_call(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- result = instance({}, {})
- self.assertTrue(isinstance(result, text_type))
- self.assertEqual(result.rstrip('\n'),
- '<div xmlns="http://www.w3.org/1999/xhtml">\n</div>')
-
- def test_template_reified(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template, instance.__dict__['template'])
-
- def test_template_with_ichameleon_translate(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.translate, lookup.translate)
-
- def test_template_with_debug_templates(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- lookup.debug = True
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.debug, True)
-
- def test_template_without_debug_templates(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- lookup.debug = False
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.debug, False)
-
- def test_template_with_reload_templates(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- lookup.auto_reload = True
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.auto_reload, True)
-
- def test_template_without_reload_templates(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- lookup.auto_reload = False
- instance = self._makeOne(minimal, lookup)
- self.assertFalse('template' in instance.__dict__)
- template = instance.template
- self.assertEqual(template.auto_reload, False)
-
- def test_call_with_nondict_value(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- self.assertRaises(ValueError, instance, None, {})
-
- def test_implementation(self):
- minimal = self._getTemplatePath('minimal.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- result = instance.implementation()()
- self.assertTrue(isinstance(result, text_type))
- self.assertEqual(result.rstrip('\n'),
- '<div xmlns="http://www.w3.org/1999/xhtml">\n</div>')
-
- def test_macro_supplied(self):
- minimal = self._getTemplatePath('withmacro.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup, macro='foo')
- result = instance.implementation()()
- self.assertEqual(result, '\n Hello!\n')
-
- def test_macro_notsupplied(self):
- minimal = self._getTemplatePath('withmacro.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup)
- result = instance.implementation()()
- self.assertEqual(result,
- '<html>\nOutside macro\n\n Hello!\n\n</html>\n\n')
-
- def test_macro_template_reload(self):
- minimal = self._getTemplatePath('withmacro.pt')
- lookup = DummyLookup()
- instance = self._makeOne(minimal, lookup, macro='foo')
- result = instance.implementation()()
- self.assertEqual(result, '\n Hello!\n')
- instance.template.cook(
- '<html>\nOutside macro\n\n Hello!\n\n</html>\n\n'
- )
- result = instance.implementation()()
- self.assertEqual(result, '\n Hello!\n')
-
-class DummyLookup(object):
- auto_reload=True
- debug = True
- def translate(self, msg): pass
-
-class DummyRegistry(object):
- def queryUtility(self, iface, name):
- self.queried = iface, name
- return None
-
- def registerUtility(self, impl, iface, name):
- self.registered = impl, iface, name
-
-class DummyInfo(object):
- def __init__(self):
- self.registry = DummyRegistry()
- self.type = '.pt'
- self.name = 'fixtures/minimal.pt'
- self.package = sys.modules[__name__]
- self.settings = {}
-