Commit 000ea39c authored by Michael Fladischer's avatar Michael Fladischer

Import django-classy-tags_0.8.0.orig.tar.gz

parent e48f21fa
language: python
python:
- 2.6
- 2.7
- 3.3
- 3.4
......@@ -13,6 +12,7 @@ env:
- DJANGO='django>=1.7,<1.8'
- DJANGO='django>=1.8,<1.9'
- DJANGO='django>=1.9,<1.10'
- DJANGO='django>=1.10,<1.11'
sudo: false
install:
- pip install $DJANGO
......@@ -20,18 +20,14 @@ script:
- python runtests.py
matrix:
exclude:
- python: 2.6
env: DJANGO='django>=1.7,<1.8'
- python: 2.6
env: DJANGO='django>=1.8,<1.9'
- python: 2.6
env: DJANGO='django>=1.9,<1.10'
- python: 3.3
env: DJANGO='django>=1.3,<1.4'
- python: 3.3
env: DJANGO='django>=1.4,<1.5'
- python: 3.3
env: DJANGO='django>=1.9,<1.10'
- python: 3.3
env: DJANGO='django>=1.10,<1.11'
- python: 3.4
env: DJANGO='django>=1.3,<1.4'
- python: 3.4
......
......@@ -3,7 +3,7 @@ django-classy-tags
==================
Please refer to the documentation in the docs/ directory for help. For a HTML
rendered version of it please see `here <http://django-classy-tags.rtfd.org>`_.
rendered version of it please see `here <https://django-classy-tags.readthedocs.io>`_.
.. image:: https://travis-ci.org/ojii/django-classy-tags.svg?branch=master
:target: https://travis-ci.org/ojii/django-classy-tags
......
__version__ = '0.7.2'
__version__ = '0.8.0'
......@@ -14,6 +14,8 @@ class Options(object):
Option class holding the arguments of a tag.
"""
def __init__(self, *options, **kwargs):
self._options = options
self._kwargs = kwargs
self.options = {}
self.raw_options = options
self.breakpoints = []
......@@ -63,19 +65,24 @@ class Options(object):
def __add__(self, other):
if not isinstance(other, Options):
raise TypeError("Cannot add non-Options to Options")
if all((self.blocks, other.blocks)):
raise TypeError("Cannot add Options that both define blocks")
if self.parser_class != other.parser_class:
raise TypeError(
"Cannot add Options that have different parser classes"
raise TypeError("Cannot add Options to non-Options object")
if self.blocks and other.blocks:
raise ValueError(
"Cannot add two Options objects if both objects define blocks"
)
kwargs = {
'parser_class': self.parser_class,
'blocks': self.blocks or other.blocks
if self.parser_class is not other.parser_class:
raise ValueError(
"Cannot add two Options objects with different parser classes"
)
full_options = self._options + other._options
full_kwargs = {
'parser_class': self.parser_class
}
args = list(self.raw_options) + list(other.raw_options)
return Options(*args, **kwargs)
if self._kwargs.get('blocks', False):
full_kwargs['blocks'] = self._kwargs['blocks']
elif other._kwargs.get('blocks', False):
full_kwargs['blocks'] = other._kwargs['blocks']
return Options(*full_options, **full_kwargs)
def get_parser_class(self):
return self.parser_class
......
from __future__ import with_statement
import operator
import os
import sys
import warnings
from distutils.version import LooseVersion
import operator
from unittest import TestCase
import django
......@@ -631,6 +631,36 @@ class ClassytagsTests(TestCase):
]
self._tag_tester(Hello, tpls)
def test_filters_in_arguments(self):
class Filtered(core.Tag):
options = core.Options(
arguments.Argument('value'),
)
def render_tag(self, context, value):
return value
tpls = [
('{% filtered "hello" %}', 'hello', {}),
('{% filtered var %}', 'world', {'var': 'world'}),
('{% filtered var|default:"foo" %}', 'foo', {}),
]
self._tag_tester(Filtered, tpls)
def test_filtered_multi_keyword(self):
class Filtered(core.Tag):
options = core.Options(
arguments.MultiKeywordArgument('kwargs'),
)
def render_tag(self, context, kwargs):
return '|'.join('%s:%s' % (k, v) for k, v in kwargs.items())
tpls = [
('{% filtered hello="world" %}', 'hello:world', {}),
('{% filtered hello=var %}', 'hello:world', {'var': 'world'}),
('{% filtered hello=var|default:"foo" %}', 'hello:foo', {}),
]
self._tag_tester(Filtered, tpls)
def test_blocks(self):
class Blocky(core.Tag):
options = core.Options(
......@@ -1319,55 +1349,116 @@ class MultiBreakpointTests(TestCase):
options.parse, dummy_parser, dummy_tokens
)
def test_repr(self):
options = core.Options(
arguments.Argument('first'),
'breakpoint',
arguments.Flag('flag', true_values=['yes']),
blocks=['block']
def test_add_options(self):
options1 = core.Options(
arguments.Argument('first')
)
self.assertEqual(
repr(options),
'<Options:<Argument: first>,breakpoint,<Flag: flag>;block>'
options2 = core.Options(
arguments.Argument('second')
)
combined = options1 + options2
self.assertEqual(len(combined.options), 1, combined.options)
self.assertIn(None, combined.options)
self.assertEqual(len(combined.options[None]), 2, combined.options[None])
self.assertEqual(combined.all_argument_names, ['first', 'second'])
self.assertEqual(len(combined.blocks), 0, combined.blocks)
def test_add_options(self):
left = core.Options(
arguments.Argument('left')
def test_add_options_blocks_first(self):
options1 = core.Options(
arguments.Argument('first'),
blocks=['a']
)
right = core.Options(
arguments.Argument('right')
options2 = core.Options(
arguments.Argument('second'),
)
combined = left + right
dummy_tokens = DummyTokens('leftval', 'rightval')
kwargs, blocks = combined.parse(dummy_parser, dummy_tokens)
self.assertEqual(blocks, {})
self.assertEqual(len(kwargs), 2)
dummy_context = {}
self.assertEqual(kwargs['left'].resolve(dummy_context), 'leftval')
self.assertEqual(kwargs['right'].resolve(dummy_context), 'rightval')
combined = options1 + options2
self.assertEqual(len(combined.blocks), 1, combined.blocks)
self.assertEqual(combined.blocks[0].alias, 'a')
self.assertEqual(combined.blocks[0].names, ('a', ))
def test_add_options_different_parser(self):
left = core.Options(
parser_class=object()
def test_add_options_blocks_second(self):
options1 = core.Options(
arguments.Argument('first'),
)
right = core.Options(
parser_class=object()
options2 = core.Options(
arguments.Argument('second'),
blocks=['a']
)
self.assertRaises(TypeError, operator.add, left, right)
combined = options1 + options2
self.assertEqual(len(combined.blocks), 1, combined.blocks)
self.assertEqual(combined.blocks[0].alias, 'a')
self.assertEqual(combined.blocks[0].names, ('a', ))
def test_add_options_blocks_both(self):
left = core.Options(
blocks=['leftblock']
options1 = core.Options(
arguments.Argument('first'),
blocks=['a'],
)
right = core.Options(
blocks=['rightblock']
options2 = core.Options(
arguments.Argument('second'),
blocks=['a']
)
self.assertRaises(
ValueError,
operator.add,
options1,
options2,
)
self.assertRaises(TypeError, operator.add, left, right)
def test_add_options_to_something_else(self):
options = core.Options()
self.assertRaises(TypeError, operator.add, options, 1)
def test_add_options_not_options(self):
options = core.Options(
arguments.Argument('first'),
)
self.assertRaises(
TypeError,
operator.add,
options,
1
)
def test_add_options_custom_parser_same(self):
class CustomParser(parser.Parser):
def parse_blocks(self):
return
options1 = core.Options(
parser_class=CustomParser,
)
options2 = core.Options(
parser_class=CustomParser,
)
combined = options1 + options2
self.assertIs(combined.parser_class, CustomParser)
def test_add_options_custom_parser_different(self):
class CustomParser(parser.Parser):
def parse_blocks(self):
return
options1 = core.Options(
parser_class=CustomParser,
)
options2 = core.Options(
parser_class=parser.Parser,
)
self.assertRaises(
ValueError,
operator.add,
options1,
options2,
)
def test_repr(self):
options = core.Options(
arguments.Argument('first'),
'breakpoint',
arguments.Flag('flag', true_values=['yes']),
blocks=['block']
)
self.assertEqual(
repr(options),
'<Options:<Argument: first>,breakpoint,<Flag: flag>;block>'
)
def test_flatten_context(self):
context = Context({'foo': 'bar'})
......
......@@ -3,6 +3,13 @@ Changelog
#########
*****
0.8.0
*****
* Removed Python 2.6 support. Supported versions are now 2.7, 3.3, 3.4 and 3.5.
* Added support for Django 1.10.
*****
0.7.2
*****
......
......@@ -9,6 +9,7 @@ If you don't want to use ``pip``, download the latest version from
`pypi <http://pypi.python.org/pypi/django-classy-tags>`_, unpack the tarball and
run ``sudo python setup.py install``.
django-classy-tags has no dependencies other than Django.
django-classy-tags has no dependencies other than Django. Django 1.3, 1.4, 1.5,
1.6, 1.7, 1.8, 1.9 and 1.10 are supportd.
django-classy-tags supports both Python 2.7 and Python 3.3 (or higher).
django-classy-tags supports Python 2.7, 3.3, 3.4 and 3.5.
......@@ -32,6 +32,17 @@ else:
ROOT_URLCONF = 'runtests'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True,
'DIRS': TEMPLATE_DIRS,
'OPTIONS': {
'debug': TEMPLATE_DEBUG,
},
},
]
def main():
import django
from django.conf import settings
......@@ -43,6 +54,7 @@ def main():
TEMPLATE_DIRS = TEMPLATE_DIRS,
TEMPLATE_DEBUG = TEMPLATE_DEBUG,
MIDDLEWARE_CLASSES = [],
TEMPLATES=TEMPLATES,
)
# Run the test suite, including the extra validation tests.
......
......@@ -22,7 +22,6 @@ setup(
"Intended Audience :: Developers",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment