From 4a4b9f1e66250d328f57ea2e09d9c2ed77c413e4 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 6 Nov 2012 17:42:17 -0800 Subject: [PATCH] rename to player --- README.rst | 24 ++++----- {pyramid_layer => player}/__init__.py | 32 +++++------ {pyramid_layer => player}/formatter.py | 2 +- {pyramid_layer => player}/layer.py | 6 +-- {pyramid_layer => player}/layout.py | 16 +++--- {pyramid_layer => player}/message.py | 2 +- {pyramid_layer => player}/renderer.py | 2 +- {pyramid_layer => player}/script.py | 0 .../templates/message/error.pt | 0 .../templates/message/info.pt | 0 .../templates/message/success.pt | 0 .../templates/message/warning.pt | 0 {pyramid_layer => player}/tests/base.py | 31 +++++------ .../tests/bundle/dir1/view.pt | 0 .../tests/dir1/actions.pt | 0 {pyramid_layer => player}/tests/dir1/view.pt | 0 .../tests/message/custom.pt | 0 .../tests/test-layout-html.pt | 0 .../tests/test-layout.pt | 0 .../tests/test_custom.py | 8 +-- .../tests/test_formatter.py | 12 ++--- {pyramid_layer => player}/tests/test_layer.py | 40 +++++++------- .../tests/test_layout.py | 54 +++++++++---------- .../tests/test_message.py | 14 ++--- {pyramid_layer => player}/tests/test_order.py | 10 ++-- .../tests/test_renderer.py | 33 ++++-------- .../tests/test_script.py | 52 +++++++++--------- setup.cfg | 2 +- setup.py | 8 +-- 29 files changed, 163 insertions(+), 185 deletions(-) rename {pyramid_layer => player}/__init__.py (70%) rename {pyramid_layer => player}/formatter.py (97%) rename {pyramid_layer => player}/layer.py (95%) rename {pyramid_layer => player}/layout.py (95%) rename {pyramid_layer => player}/message.py (94%) rename {pyramid_layer => player}/renderer.py (98%) rename {pyramid_layer => player}/script.py (100%) rename {pyramid_layer => player}/templates/message/error.pt (100%) rename {pyramid_layer => player}/templates/message/info.pt (100%) rename {pyramid_layer => player}/templates/message/success.pt (100%) rename {pyramid_layer => player}/templates/message/warning.pt (100%) rename {pyramid_layer => player}/tests/base.py (64%) rename {pyramid_layer => player}/tests/bundle/dir1/view.pt (100%) rename {pyramid_layer => player}/tests/dir1/actions.pt (100%) rename {pyramid_layer => player}/tests/dir1/view.pt (100%) rename {pyramid_layer => player}/tests/message/custom.pt (100%) rename {pyramid_layer => player}/tests/test-layout-html.pt (100%) rename {pyramid_layer => player}/tests/test-layout.pt (100%) rename {pyramid_layer => player}/tests/test_custom.py (74%) rename {pyramid_layer => player}/tests/test_formatter.py (86%) rename {pyramid_layer => player}/tests/test_layer.py (76%) rename {pyramid_layer => player}/tests/test_layout.py (85%) rename {pyramid_layer => player}/tests/test_message.py (88%) rename {pyramid_layer => player}/tests/test_order.py (75%) rename {pyramid_layer => player}/tests/test_renderer.py (69%) rename {pyramid_layer => player}/tests/test_script.py (64%) diff --git a/README.rst b/README.rst index a6f68be..36100ee 100644 --- a/README.rst +++ b/README.rst @@ -1,12 +1,12 @@ -pyramid_layer -============= +player +====== -.. image :: https://secure.travis-ci.org/fafhrd91/pyramid_layer.png - :target: https://secure.travis-ci.org/fafhrd91/pyramid_layer +.. image :: https://secure.travis-ci.org/fafhrd91/player.png + :target: https://secure.travis-ci.org/fafhrd91/player -pyramid_layer allows to address templates with two parameters, +player allows to address templates with two parameters, category and name. Also it is possible to use set of directories -for each layer, in that case `pyramid_layer` searches templates +for each layer, in that case `player` searches templates in each directory. It allows to override templates without changing code. For example form library can define layer `field`:: @@ -34,7 +34,7 @@ Layer can to be defined with `add_layer` config directive: .. code-block:: python >> config = Configurator() - .. config.include('pyramid_layer') + .. config.include('player') .. .. config.add_layer('form', path='./path_to_form_dirctory/form/') @@ -64,7 +64,7 @@ or : It is possible to run python code before rendering template. -There are `add_tmpl_filter` directive and `pyramid_layer.tmpl_filter` +There are `add_tmpl_filter` directive and `player.tmpl_filter` decorator: .. code-block:: python @@ -78,9 +78,9 @@ or: .. code-block:: python - >> import pyramid_layer + >> import player - >> @pyramid_layer.tmpl_filter('form:actions', name='custom') + >> @player.tmpl_filter('form:actions', name='custom') .. def form_actions(context, request): .. return {'url': ...} @@ -122,7 +122,7 @@ and :: Request method -------------- -`pyramid_layer` also provides request method `render_tmpl`. It acccepts +`player` also provides request method `render_tmpl`. It acccepts path:: .. ${structure: request.render_tmpl('form:actions') @@ -139,4 +139,4 @@ player License ------- -pyramid_layer is offered under the BSD license. +player is offered under the BSD license. diff --git a/pyramid_layer/__init__.py b/player/__init__.py similarity index 70% rename from pyramid_layer/__init__.py rename to player/__init__.py index 35be44a..12be15a 100644 --- a/pyramid_layer/__init__.py +++ b/player/__init__.py @@ -1,13 +1,13 @@ -# pyramid_layer public api +# player public api __all__ = ['tmpl_filter', 'wrap_layout', 'add_message', 'render', 'RendererNotFound', 'includeme'] -from pyramid_layer.layer import tmpl_filter -from pyramid_layer.layout import wrap_layout -from pyramid_layer.renderer import render -from pyramid_layer.renderer import RendererNotFound -from pyramid_layer.message import add_message +from player.layer import tmpl_filter +from player.layout import wrap_layout +from player.renderer import render +from player.renderer import RendererNotFound +from player.message import add_message def includeme(cfg): @@ -16,10 +16,10 @@ def includeme(cfg): from pyramid.settings import aslist from pyramid.exceptions import ConfigurationError - from pyramid_layer.renderer import lt_renderer_factory - from pyramid_layer.layer import add_layer, add_layers, change_layers_order - from pyramid_layer.layer import add_tmpl_filter - from pyramid_layer.layout import add_layout, set_layout_data + from player.renderer import lt_renderer_factory + from player.layer import add_layer, add_layers, change_layers_order + from player.layer import add_tmpl_filter + from player.layout import add_layout, set_layout_data # config directives cfg.add_directive('add_layer', add_layer) @@ -47,7 +47,7 @@ def includeme(cfg): if order: cfg.action( - 'pyramid_layer.order', + 'player.order', change_layers_order, (cfg, order), order=999999+1) # global custom layer @@ -60,21 +60,21 @@ def includeme(cfg): "Directory is required for layer.custom setting: %s"%custom) cfg.action( - 'pyramid_layer.custom', + 'player.custom', add_layers, (cfg, 'layer_custom', custom), order=999999+2) # formatters - from pyramid_layer import formatter + from player import formatter cfg.add_directive('add_formatter', formatter.add_formatter) cfg.add_request_method(formatter.formatters, 'fmt', True, True) # messages layer and request helpers - from pyramid_layer.message import render_messages + from player.message import render_messages - cfg.add_layer('message', path='pyramid_layer:templates/message/') + cfg.add_layer('message', path='player:templates/message/') cfg.add_request_method(add_message, 'add_message') cfg.add_request_method(render_messages, 'render_messages') # scan - cfg.scan('pyramid_layer') + cfg.scan('player') diff --git a/pyramid_layer/formatter.py b/player/formatter.py similarity index 97% rename from pyramid_layer/formatter.py rename to player/formatter.py index 726c8c3..cf4d7c7 100644 --- a/pyramid_layer/formatter.py +++ b/player/formatter.py @@ -1,7 +1,7 @@ """ formatters """ from pyramid.registry import Introspectable -ID_FORMATTER = 'pyramid_layer:formatter' +ID_FORMATTER = 'player:formatter' def add_formatter(cfg, name, callable): diff --git a/pyramid_layer/layer.py b/player/layer.py similarity index 95% rename from pyramid_layer/layer.py rename to player/layer.py index 1669ddc..2d0c5bb 100644 --- a/pyramid_layer/layer.py +++ b/player/layer.py @@ -7,9 +7,9 @@ from pyramid.interfaces import IViewMapperFactory from pyramid.config.views import DefaultViewMapper -log = logging.getLogger('pyramid_layer') +log = logging.getLogger('player') -ID_LAYER = 'pyramid_layer:layer' +ID_LAYER = 'player:layer' def add_layer(cfg, layer, name='', path='', description=''): @@ -98,7 +98,7 @@ def callback(context, name, ob): add_tmpl_filter( cfg, self.template, ob, self.name, self.description) - info = venusian.attach(wrapped, callback, category='pyramid_layer') + info = venusian.attach(wrapped, callback, category='player') return wrapped diff --git a/pyramid_layer/layout.py b/player/layout.py similarity index 95% rename from pyramid_layer/layout.py rename to player/layout.py index 56d7271..d2731ff 100644 --- a/pyramid_layer/layout.py +++ b/player/layout.py @@ -21,9 +21,9 @@ from ordereddict import OrderedDict -log = logging.getLogger('pyramid_layer') +log = logging.getLogger('player') -LAYOUT_ID = 'pyramid_layer:layout' +LAYOUT_ID = 'player:layout' LayoutInfo = namedtuple( 'LayoutInfo', 'name layout view original renderer intr') @@ -114,7 +114,7 @@ class PageLayout(object): config.add_layout('page', parent='page', renderer='my_package:template/page.pt') - To use layout with pyramid view use ``wrapper=pyramid_layer.wrap_layout()`` + To use layout with pyramid view use ``wrapper=player.wrap_layout()`` Example: @@ -122,11 +122,11 @@ class PageLayout(object): config.add_view(' index.html', - wrapper=pyramid_layer.wrap_layout(), + wrapper=player.wrap_layout(), renderer = '...') in this example '' layout is beeing used. You can specify specific layout - name for pyramid view ``pyramid_layer.wrap_layout('page')`` + name for pyramid view ``player.wrap_layout('page')`` """ (scope, module, @@ -137,7 +137,7 @@ class PageLayout(object): discr = (LAYOUT_ID, name, context, route_name) - intr = Introspectable(LAYOUT_ID, discr, name, 'pyramid_layer_layout') + intr = Introspectable(LAYOUT_ID, discr, name, 'player_layout') intr['name'] = name intr['context'] = context @@ -296,13 +296,13 @@ def wrap_layout(layout=''): .. code-block:: python config = Configurator() - config.include('pyramid_layer') + config.include('player') config.add_layout('page') config.add_view( 'index.html', - wrapper=pyramid_layer.wrap_layout()) + wrapper=player.wrap_layout()) """ lname = '#layout-{0}'.format(layout) diff --git a/pyramid_layer/message.py b/player/message.py similarity index 94% rename from pyramid_layer/message.py rename to player/message.py index 5ce0bd6..919b746 100644 --- a/pyramid_layer/message.py +++ b/player/message.py @@ -1,6 +1,6 @@ """ simple messages """ from pyramid.compat import escape -from pyramid_layer import render, tmpl_filter +from player import render, tmpl_filter def add_message(request, msg, type='info'): diff --git a/pyramid_layer/renderer.py b/player/renderer.py similarity index 98% rename from pyramid_layer/renderer.py rename to player/renderer.py index 4a0f875..5fb85a0 100644 --- a/pyramid_layer/renderer.py +++ b/player/renderer.py @@ -4,7 +4,7 @@ from .layer import ID_LAYER -ID_TEMPLATE = 'pyramid_layer:template' +ID_TEMPLATE = 'player:template' class RendererNotFound(ValueError): diff --git a/pyramid_layer/script.py b/player/script.py similarity index 100% rename from pyramid_layer/script.py rename to player/script.py diff --git a/pyramid_layer/templates/message/error.pt b/player/templates/message/error.pt similarity index 100% rename from pyramid_layer/templates/message/error.pt rename to player/templates/message/error.pt diff --git a/pyramid_layer/templates/message/info.pt b/player/templates/message/info.pt similarity index 100% rename from pyramid_layer/templates/message/info.pt rename to player/templates/message/info.pt diff --git a/pyramid_layer/templates/message/success.pt b/player/templates/message/success.pt similarity index 100% rename from pyramid_layer/templates/message/success.pt rename to player/templates/message/success.pt diff --git a/pyramid_layer/templates/message/warning.pt b/player/templates/message/warning.pt similarity index 100% rename from pyramid_layer/templates/message/warning.pt rename to player/templates/message/warning.pt diff --git a/pyramid_layer/tests/base.py b/player/tests/base.py similarity index 64% rename from pyramid_layer/tests/base.py rename to player/tests/base.py index 3a87eba..0b7177c 100644 --- a/pyramid_layer/tests/base.py +++ b/player/tests/base.py @@ -27,39 +27,32 @@ def setUp(self): def make_request(self, registry=None, environ=None, request_iface=IRequest, **kwargs): + if registry is None: + registry = self.registry if environ is None: environ=self._environ request = testing.DummyRequest(environ=dict(environ), **kwargs) request.request_iface = IRequest - if registry is None: - registry = self.registry - if registry is not None: - request.registry = registry - request._set_extensions(registry.getUtility(IRequestExtensions)) - + request.registry = registry + request._set_extensions(registry.getUtility(IRequestExtensions)) return request - def init_extensions(self): + def init_extensions(self, registry): from pyramid.config.factories import _RequestExtensions - exts = self.registry.queryUtility(IRequestExtensions) + exts = registry.queryUtility(IRequestExtensions) if exts is None: exts = _RequestExtensions() - self.registry.registerUtility(exts, IRequestExtensions) + registry.registerUtility(exts, IRequestExtensions) def init_pyramid(self): - self.request = request = self.make_request() self.config = testing.setUp( - request=request, - settings=self._settings, - autocommit=self._auto_include) + settings=self._settings, autocommit=self._auto_include) + self.init_extensions(self.config.registry) self.config.get_routes_mapper() self.registry = self.config.registry - self.init_extensions() - - self.request.registry = self.registry - self.request._set_extensions( - self.registry.getUtility(IRequestExtensions)) if self._include: - self.config.include('pyramid_layer') + self.config.include('player') + + self.request = self.make_request() diff --git a/pyramid_layer/tests/bundle/dir1/view.pt b/player/tests/bundle/dir1/view.pt similarity index 100% rename from pyramid_layer/tests/bundle/dir1/view.pt rename to player/tests/bundle/dir1/view.pt diff --git a/pyramid_layer/tests/dir1/actions.pt b/player/tests/dir1/actions.pt similarity index 100% rename from pyramid_layer/tests/dir1/actions.pt rename to player/tests/dir1/actions.pt diff --git a/pyramid_layer/tests/dir1/view.pt b/player/tests/dir1/view.pt similarity index 100% rename from pyramid_layer/tests/dir1/view.pt rename to player/tests/dir1/view.pt diff --git a/pyramid_layer/tests/message/custom.pt b/player/tests/message/custom.pt similarity index 100% rename from pyramid_layer/tests/message/custom.pt rename to player/tests/message/custom.pt diff --git a/pyramid_layer/tests/test-layout-html.pt b/player/tests/test-layout-html.pt similarity index 100% rename from pyramid_layer/tests/test-layout-html.pt rename to player/tests/test-layout-html.pt diff --git a/pyramid_layer/tests/test-layout.pt b/player/tests/test-layout.pt similarity index 100% rename from pyramid_layer/tests/test-layout.pt rename to player/tests/test-layout.pt diff --git a/pyramid_layer/tests/test_custom.py b/player/tests/test_custom.py similarity index 74% rename from pyramid_layer/tests/test_custom.py rename to player/tests/test_custom.py index ea42aaa..dcc9025 100644 --- a/pyramid_layer/tests/test_custom.py +++ b/player/tests/test_custom.py @@ -1,5 +1,5 @@ from pyramid.exceptions import ConfigurationError -from pyramid_layer.layer import ID_LAYER +from player.layer import ID_LAYER from base import BaseTestCase @@ -11,17 +11,17 @@ class TestSettingsError(BaseTestCase): def test_custom(self): self.assertRaises( - ConfigurationError, self.config.include, 'pyramid_layer') + ConfigurationError, self.config.include, 'player') class TestSettingsCustom(BaseTestCase): _auto_include = False - _settings = {'layer.custom': 'pyramid_layer:tests/bundle/'} + _settings = {'layer.custom': 'player:tests/bundle/'} def test_custom_dir(self): self.config.add_layer( - 'dir1', path='pyramid_layer:tests/dir1/') + 'dir1', path='player:tests/dir1/') self.config.commit() storage = self.registry.get(ID_LAYER) diff --git a/pyramid_layer/tests/test_formatter.py b/player/tests/test_formatter.py similarity index 86% rename from pyramid_layer/tests/test_formatter.py rename to player/tests/test_formatter.py index a8b1548..2171edc 100644 --- a/pyramid_layer/tests/test_formatter.py +++ b/player/tests/test_formatter.py @@ -23,11 +23,9 @@ def simple(request, v): self.config.add_formatter('simple', simple) - request = self.make_request() - - simple = request.fmt['simple'] - self.assertIs(simple, request.fmt['simple']) - self.assertIs(request.fmt['simple'], request.fmt.simple) + simple = self.request.fmt['simple'] + self.assertIs(simple, self.request.fmt['simple']) + self.assertIs(self.request.fmt['simple'], self.request.fmt.simple) request = self.make_request() self.assertIsNot(simple, request.fmt.simple) @@ -47,7 +45,7 @@ def simple2(v): """ """ config = Configurator() - config.include('ptahform') + config.include('player') config.add_formatter('test', simple1) config.add_formatter('test', simple2) @@ -60,7 +58,7 @@ def simple(v): self.config.add_formatter('simple', simple) - from pyramid_layer.formatter import ID_FORMATTER + from player.formatter import ID_FORMATTER discr = (ID_FORMATTER, 'simple') intr = self.config.introspector.get(ID_FORMATTER, discr) diff --git a/pyramid_layer/tests/test_layer.py b/player/tests/test_layer.py similarity index 76% rename from pyramid_layer/tests/test_layer.py rename to player/tests/test_layer.py index 92dfc89..68a5d2d 100644 --- a/pyramid_layer/tests/test_layer.py +++ b/player/tests/test_layer.py @@ -13,7 +13,7 @@ def test_layer_directive(self): self.assertFalse(hasattr(self.config, 'add_layer')) self.assertFalse(hasattr(self.config, 'add_layers')) self.assertFalse(hasattr(self.config, 'add_tmpl_filter')) - self.config.include('pyramid_layer') + self.config.include('player') self.assertTrue(hasattr(self.config, 'add_layer')) self.assertTrue(hasattr(self.config, 'add_layers')) @@ -25,10 +25,10 @@ class TestLayer(BaseTestCase): _auto_include = False def test_layer_registration(self): - from pyramid_layer.layer import ID_LAYER + from player.layer import ID_LAYER self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') self.config.commit() data = self.registry.get(ID_LAYER) @@ -36,21 +36,21 @@ def test_layer_registration(self): self.assertEqual(len(data['test']), 1) self.assertEqual(data['test'][0]['name'], '') self.assertTrue(data['test'][0]['path'].endswith( - 'pyramid_layer/tests/dir1/')) + 'player/tests/dir1/')) def test_layer_path_required(self): self.assertRaises( ConfigurationError, self.config.add_layer, 'test') def test_multple_layer_registration(self): - from pyramid_layer.layer import ID_LAYER + from player.layer import ID_LAYER self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') self.config.commit() self.config.add_layer( - 'test', 'custom', path='pyramid_layer:tests/bundle/dir1/') + 'test', 'custom', path='player:tests/bundle/dir1/') self.config.commit() data = self.registry.get(ID_LAYER) @@ -58,16 +58,16 @@ def test_multple_layer_registration(self): self.assertEqual(len(data['test']), 2) self.assertEqual(data['test'][0]['name'], 'custom') self.assertTrue(data['test'][0]['path'].endswith( - 'pyramid_layer/tests/bundle/dir1/')) + 'player/tests/bundle/dir1/')) self.assertEqual(data['test'][1]['name'], '') self.assertTrue(data['test'][1]['path'].endswith( - 'pyramid_layer/tests/dir1/')) + 'player/tests/dir1/')) def test_register_layers(self): - from pyramid_layer.layer import ID_LAYER + from player.layer import ID_LAYER self.config.add_layers( - 'custom', path='pyramid_layer:tests/bundle/') + 'custom', path='player:tests/bundle/') self.config.commit() data = self.registry.get(ID_LAYER) @@ -75,15 +75,15 @@ def test_register_layers(self): self.assertEqual(len(data['dir1']), 1) self.assertEqual(data['dir1'][0]['name'], 'custom') self.assertTrue(data['dir1'][0]['path'].endswith( - 'pyramid_layer/tests/bundle/dir1')) + 'player/tests/bundle/dir1')) def test_reg_conflict(self): self.config.commit() self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') self.config.add_layer( - 'test', path='pyramid_layer:tests/bundle/dir1/') + 'test', path='player:tests/bundle/dir1/') self.assertRaises( ConfigurationConflictError, self.config.commit) @@ -99,11 +99,11 @@ def _filter(context, request): ConfigurationError, self.config.add_tmpl_filter, 'test:view', _filter) - @mock.patch('pyramid_layer.layer.venusian') + @mock.patch('player.layer.venusian') def test_add_tmpl_filter_deco_err(self, m_venusian): - import pyramid_layer + import player - @pyramid_layer.tmpl_filter('test:view') + @player.tmpl_filter('test:view') def _filter(context, request): return {} @@ -116,12 +116,12 @@ def _filter(context, request): ConfigurationError, cb, m_venusian, 't', _filter) def test_add_tmpl_filter(self): - from pyramid_layer.layer import ID_LAYER + from player.layer import ID_LAYER self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') self.config.add_layer( - 'test', 'custom', path='pyramid_layer:tests/bundle/dir1/') + 'test', 'custom', path='player:tests/bundle/dir1/') def _filter(context, request): return {} diff --git a/pyramid_layer/tests/test_layout.py b/player/tests/test_layout.py similarity index 85% rename from pyramid_layer/tests/test_layout.py rename to player/tests/test_layout.py index 6d33400..450040f 100644 --- a/pyramid_layer/tests/test_layout.py +++ b/player/tests/test_layout.py @@ -24,7 +24,7 @@ def tearDown(self): shutil.rmtree(self.dir) def test_layout_register_simple(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout self.config.add_layout('test') @@ -34,7 +34,7 @@ def test_layout_register_simple(self): self.assertIs(layout.original, None) def test_layout_register_custom_class(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout class MyLayout(object): pass @@ -45,7 +45,7 @@ class MyLayout(object): self.assertIs(layout.original, MyLayout) def test_layout_simple_declarative(self): - from pyramid_layer.layout import LayoutRenderer + from player.layout import LayoutRenderer class Layout(View): def __call__(self): @@ -53,7 +53,7 @@ def __call__(self): self.config.add_layout( 'test', context=Context, - renderer='pyramid_layer:tests/test-layout-html.pt') + renderer='player:tests/test-layout-html.pt') renderer = LayoutRenderer('test') self.request.wrapped_body = 'View: test' @@ -64,10 +64,10 @@ def __call__(self): def test_layout_pyramid_declarative(self): from pyramid.config import Configurator - from pyramid_layer.layout import ILayout + from player.layout import ILayout config = Configurator(autocommit=True) - config.include('pyramid_layer') + config.include('player') config.commit() class Layout(View): @@ -82,20 +82,20 @@ def __call__(self): self.assertIs(layout_factory.original, Layout) def test_layout_simple_notfound(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout v = View(Context(Context()), self.request) layout, context = query_layout(object(), v.context, self.request,'test') self.assertTrue(layout is None) def test_layout_simple_chain_multi_level(self): - from pyramid_layer.layout import LayoutRenderer + from player.layout import LayoutRenderer self.config.add_layout( - 'test', parent='.', renderer='pyramid_layer:tests/test-layout.pt') + 'test', parent='.', renderer='player:tests/test-layout.pt') self.config.add_layout( '', context=Root, parent=None, - renderer='pyramid_layer:tests/test-layout-html.pt') + renderer='player:tests/test-layout-html.pt') root = Root() context = Context(root) @@ -108,14 +108,14 @@ def test_layout_simple_chain_multi_level(self): self.assertIn('
View: test
\n', text_(res)) def test_layout_chain_same_layer_id_on_different_levels(self): - from pyramid_layer.layout import LayoutRenderer + from player.layout import LayoutRenderer self.config.add_layout( '', context=Context, parent='.', - renderer='pyramid_layer:tests/test-layout.pt') + renderer='player:tests/test-layout.pt') self.config.add_layout( '', context=Root, parent=None, - renderer='pyramid_layer:tests/test-layout-html.pt') + renderer='player:tests/test-layout-html.pt') root = Root() context1 = Context2(root) @@ -130,12 +130,12 @@ def test_layout_chain_same_layer_id_on_different_levels(self): def test_layout_chain_parent_notfound(self): self.config.add_layout('', context=Context, parent='page', - renderer='pyramid_layer:tests/test-layout.pt') + renderer='player:tests/test-layout.pt') root = Root() context = Context(root) - from pyramid_layer.layout import LayoutRenderer + from player.layout import LayoutRenderer renderer = LayoutRenderer('') self.request.wrapped_body = 'View: test' self.request.wrapped_response = self.request.response @@ -144,7 +144,7 @@ def test_layout_chain_parent_notfound(self): self.assertTrue('
View: test
' in text_(res)) def test_layout_for_route(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout self.config.add_route('test-route', '/test/', use_global_views=False) self.config.add_layout( @@ -161,7 +161,7 @@ def test_layout_for_route(self): self.assertIsNotNone(layout) def test_layout_for_route_global_views(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout self.config.add_route('test-route', '/test/', use_global_views=False) self.config.add_layout('test', use_global_views=True) @@ -174,7 +174,7 @@ def test_layout_for_route_global_views(self): self.assertIsNotNone(layout) def test_layout_root(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout class Root1(object): pass @@ -221,7 +221,7 @@ class Context3(object): context2.__parent__ = context1 context3.__parent__ = context2 - from pyramid_layer.layout import query_layout_chain + from player.layout import query_layout_chain chain = query_layout_chain(root, context1, self.request, 'l1') self.assertEqual(len(chain), 1) @@ -240,13 +240,13 @@ class Context3(object): self.assertIs(chain[1][0].original, Layout2) self.assertIs(chain[2][0].original, Layout1) - @mock.patch('pyramid_layer.layout.venusian') + @mock.patch('player.layout.venusian') def test_wrap_layout(self, m_ven): - from pyramid_layer.layout import wrap_layout, LayoutRenderer + from player.layout import wrap_layout, LayoutRenderer mod = Context() - mod.__name__ = 'pyramid_layer' - mod.__file__ = 'pyramid_layer' + mod.__name__ = 'player' + mod.__file__ = 'player' m_ven.getFrameInfo.return_value = ('1',mod,'3','4','5') lname = wrap_layout('page') @@ -270,7 +270,7 @@ def test_wrap_layout(self, m_ven): self.assertIs(renderer, renderer2) def test_layout_renderer_layout_info(self): - from pyramid_layer.layout import query_layout, LayoutRenderer + from player.layout import query_layout, LayoutRenderer self.config.add_layout('test') self.config.add_layout('test2', view=View) @@ -287,7 +287,7 @@ def test_layout_renderer_layout_info(self): self.assertIn('"layout-factory": "test_layout.View"', res) def test_query_layout_no_request_iface(self): - from pyramid_layer.layout import query_layout + from player.layout import query_layout self.config.add_layout('test') l1 = query_layout(Root(), Context(), self.request, 'test')[0] @@ -296,9 +296,9 @@ def test_query_layout_no_request_iface(self): l2 = query_layout(Root(), Context(), self.request, 'test')[0] self.assertIs(l1, l2) - @mock.patch('pyramid_layer.layout.query_layout') + @mock.patch('player.layout.query_layout') def test_query_layout_chain(self, m): - from pyramid_layer.layout import query_layout_chain + from player.layout import query_layout_chain m.return_value = (None, None) chain = query_layout_chain(Root(), Context(), self.request) diff --git a/pyramid_layer/tests/test_message.py b/player/tests/test_message.py similarity index 88% rename from pyramid_layer/tests/test_message.py rename to player/tests/test_message.py index 6983c9f..0018ad5 100644 --- a/pyramid_layer/tests/test_message.py +++ b/player/tests/test_message.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -""" Unit tests for L{pyramid_layer.message} """ +""" Unit tests for L{player.message} """ from pyramid.compat import text_ from base import BaseTestCase -from pyramid_layer.message import add_message -from pyramid_layer.message import render_messages +from player.message import add_message +from player.message import render_messages class TestStatusMessages(BaseTestCase): @@ -39,7 +39,7 @@ def test_messages_error_msg(self): def test_messages_custom_msg(self): self.config.add_layer( - 'message', 'test', path='pyramid_layer:tests/message/') + 'message', 'test', path='player:tests/message/') add_message(self.request, 'message', 'custom') self.assertEqual( @@ -48,7 +48,7 @@ def test_messages_custom_msg(self): def test_messages_custom_msg_different_type(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/message/') + 'test', path='player:tests/message/') add_message(self.request, 'message', 'test:custom') self.assertEqual( @@ -57,7 +57,7 @@ def test_messages_custom_msg_different_type(self): def test_messages_render_message_with_error(self): self.config.add_layer( - 'message', 'test', path='pyramid_layer:tests/messages/') + 'message', 'test', path='player:tests/messages/') def customMessage(context, request): raise ValueError() @@ -78,7 +78,7 @@ def test_messages_render(self): self.assertEqual(msg, '') def test_messages_unknown_type(self): - from pyramid_layer import RendererNotFound + from player import RendererNotFound self.assertRaises( RendererNotFound, diff --git a/pyramid_layer/tests/test_order.py b/player/tests/test_order.py similarity index 75% rename from pyramid_layer/tests/test_order.py rename to player/tests/test_order.py index 3e43085..030edba 100644 --- a/pyramid_layer/tests/test_order.py +++ b/player/tests/test_order.py @@ -1,4 +1,4 @@ -from pyramid_layer.layer import ID_LAYER +from player.layer import ID_LAYER from base import BaseTestCase @@ -10,9 +10,9 @@ class TestOrder(BaseTestCase): def test_custom_dir(self): self.config.add_layer( - 'test', 'l1', path='pyramid_layer:tests/dir1/') + 'test', 'l1', path='player:tests/dir1/') self.config.add_layer( - 'test', 'l2', path='pyramid_layer:tests/bundle/dir1/') + 'test', 'l2', path='player:tests/bundle/dir1/') self.config.commit() storage = self.registry.get(ID_LAYER) @@ -29,9 +29,9 @@ class TestOrderUnknown(BaseTestCase): def test_custom_dir(self): self.config.add_layer( - 'test', 'l1', path='pyramid_layer:tests/dir1/') + 'test', 'l1', path='player:tests/dir1/') self.config.add_layer( - 'test', 'l2', path='pyramid_layer:tests/bundle/dir1/') + 'test', 'l2', path='player:tests/bundle/dir1/') self.config.commit() storage = self.registry.get(ID_LAYER) diff --git a/pyramid_layer/tests/test_renderer.py b/player/tests/test_renderer.py similarity index 69% rename from pyramid_layer/tests/test_renderer.py rename to player/tests/test_renderer.py index c36b825..af10bcf 100644 --- a/pyramid_layer/tests/test_renderer.py +++ b/player/tests/test_renderer.py @@ -3,29 +3,16 @@ class TestRequestRenderers(BaseTestCase): - def setUp(self): - super(TestRequestRenderers, self).setUp() - - self.cfg = self.registry.settings - - from pyramid.interfaces import IRequestExtensions - extensions = self.registry.getUtility(IRequestExtensions) - self.request._set_extensions(extensions) - - def make_request(self): - from pyramid.request import Request - return Request(environ=self._environ) - def test_render_tmpl(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') text = self.request.render_tmpl('test:view', object()).strip() self.assertEqual(text, '

Test

') def test_render_tmpl_with_filter(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') _calls = [] def _filter(context, request): @@ -42,7 +29,7 @@ def _filter(context, request): def test_render_tmpl_ext(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') text = self.request.render_tmpl('test:view.lt', object()).strip() self.assertEqual(text, '

Test

') @@ -52,24 +39,24 @@ def test_render_tmpl_unknown(self): ValueError, self.request.render_tmpl, 'test:view') self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') self.assertRaises( ValueError, self.request.render_tmpl, 'test:view2') def test_render_tmpl_customize(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') self.config.add_layer( - 'test', 'custom', path='pyramid_layer:tests/bundle/dir1/') + 'test', 'custom', path='player:tests/bundle/dir1/') text = self.request.render_tmpl('test:view', object()).strip() self.assertEqual(text, '

Test

') def test_template(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') - from pyramid_layer.renderer import template + from player.renderer import template tmpl = template('test:view') text = tmpl(self.request, object()) @@ -77,7 +64,7 @@ def test_template(self): def test_pyramid_renderer(self): self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') from pyramid.renderers import render @@ -89,7 +76,7 @@ def test_pyramid_renderer_no_templates(self): Raise ValueError if template can't be found. """ self.config.add_layer( - 'test', path='pyramid_layer:tests/dir1/') + 'test', path='player:tests/dir1/') from pyramid.renderers import render diff --git a/pyramid_layer/tests/test_script.py b/player/tests/test_script.py similarity index 64% rename from pyramid_layer/tests/test_script.py rename to player/tests/test_script.py index bb19ec0..7400813 100644 --- a/pyramid_layer/tests/test_script.py +++ b/player/tests/test_script.py @@ -1,8 +1,8 @@ import mock import sys from pyramid.compat import NativeIO -from pyramid_layer import script as layer -from pyramid_layer.layer import ID_LAYER +from player import script as layer +from player.layer import ID_LAYER from base import BaseTestCase @@ -19,38 +19,38 @@ def tearDown(self): sys.stdout = self.stdout super(TestPlayerCommand, self).tearDown() - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_no_params(self, m_bs): m_bs.return_value = {'registry': self.registry} - sys.argv[:] = ['player', 'pyramid_layer.ini'] + sys.argv[:] = ['player', 'player.ini'] layer.main() val = self.out.getvalue() self.assertIn('[-h] [-l] [-lt] config [asset [asset ...]]', val) - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_list_categories_no_layers(self, m_bs): m_bs.return_value = {'registry': self.registry} self.registry[ID_LAYER] = {} - sys.argv[:] = ['player', '-l', 'pyramid_layer.ini'] + sys.argv[:] = ['player', '-l', 'player.ini'] layer.main() val = self.out.getvalue() self.assertIn('No layers are found.', val) - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_list_categories(self, m_bs): m_bs.return_value = {'registry': self.registry} self.config.add_layer( - 'test1', path='pyramid_layer:tests/dir1/') + 'test1', path='player:tests/dir1/') self.config.add_layer( - 'test2', path='pyramid_layer:tests/bundle/') + 'test2', path='player:tests/bundle/') - sys.argv[:] = ['player', '-l', 'pyramid_layer.ini'] + sys.argv[:] = ['player', '-l', 'player.ini'] layer.main() @@ -58,15 +58,15 @@ def test_list_categories(self, m_bs): self.assertIn('* Layer: test1', val) self.assertIn('* Layer: test2', val) - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_list_categories_limit(self, m_bs): m_bs.return_value = {'registry': self.registry} self.config.add_layer( - 'test1', path='pyramid_layer:tests/dir1/') + 'test1', path='player:tests/dir1/') self.config.add_layer( - 'test2', path='pyramid_layer:tests/bundle/') + 'test2', path='player:tests/bundle/') - sys.argv[:] = ['player', '-l', 'pyramid_layer.ini', 'test2'] + sys.argv[:] = ['player', '-l', 'player.ini', 'test2'] layer.main() @@ -74,53 +74,53 @@ def test_list_categories_limit(self, m_bs): self.assertNotIn('* Layer: test1', val) self.assertIn('* Layer: test2', val) - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_list_templates(self, m_bs): m_bs.return_value = {'registry': self.registry} self.config.add_layer( - 'test1', path='pyramid_layer:tests/dir1/') + 'test1', path='player:tests/dir1/') self.config.add_layer( - 'test2', path='pyramid_layer:tests/bundle/') + 'test2', path='player:tests/bundle/') def test(): pass self.config.add_tmpl_filter( 'test1:actions', test) - sys.argv[:] = ['player', '-lt', 'pyramid_layer.ini'] + sys.argv[:] = ['player', '-lt', 'player.ini'] layer.main() val = self.out.getvalue() self.assertIn('* Layer: test1', val) - self.assertIn('pyramid_layer:tests/dir1/', val) + self.assertIn('player:tests/dir1/', val) self.assertIn('actions: .pt (test_script.py: test)', val) self.assertIn('* Layer: test2', val) - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_list_templates_limit(self, m_bs): m_bs.return_value = {'registry': self.registry} self.config.add_layer( - 'test1', path='pyramid_layer:tests/dir1/') + 'test1', path='player:tests/dir1/') self.config.add_layer( - 'test2', path='pyramid_layer:tests/bundle/') + 'test2', path='player:tests/bundle/') - sys.argv[:] = ['player', '-lt', 'pyramid_layer.ini', 'test1'] + sys.argv[:] = ['player', '-lt', 'player.ini', 'test1'] layer.main() val = self.out.getvalue() self.assertIn('* Layer: test1', val) - self.assertIn('pyramid_layer:tests/dir1/', val) + self.assertIn('player:tests/dir1/', val) self.assertIn('actions: .pt', val) self.assertNotIn('* Layer: test2', val) - @mock.patch('pyramid_layer.script.bootstrap') + @mock.patch('player.script.bootstrap') def test_list_templates_no_layers(self, m_bs): m_bs.return_value = {'registry': self.registry} self.registry[ID_LAYER] = {} - sys.argv[:] = ['player', '-lt', 'pyramid_layer.ini'] + sys.argv[:] = ['player', '-lt', 'player.ini'] layer.main() diff --git a/setup.cfg b/setup.cfg index 196a0e0..989b021 100644 --- a/setup.cfg +++ b/setup.cfg @@ -5,5 +5,5 @@ zip_ok = false match=^test where= nocapture=1 -cover-package=pyramid_layer +cover-package=player cover-erase=1 diff --git a/setup.py b/setup.py index f8dcaa4..16e7d17 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ import sys from setuptools import setup, find_packages -version='0.2' +version='0.3' install_requires = ['setuptools', 'pyramid >= 1.4.0a3', @@ -20,7 +20,7 @@ def read(f): return open(os.path.join(os.path.dirname(__file__), f)).read().strip() -setup(name='pyramid_layer', +setup(name='player', version=version, description=('Pyramid view layers'), long_description='\n\n'.join((read('README.rst'), read('CHANGES.txt'))), @@ -38,7 +38,7 @@ def read(f): 'Topic :: Internet :: WWW/HTTP :: WSGI'], author='Nikolay Kim', author_email='fafhrd91@gmail.com', - url='https://github.com/fafhrd91/pyramid_layer/', + url='https://github.com/fafhrd91/player/', license='BSD', packages=find_packages(), install_requires = install_requires, @@ -48,7 +48,7 @@ def read(f): zip_safe = False, entry_points = { 'console_scripts': [ - 'player = pyramid_layer.script:main', + 'player = player.script:main', ], }, )