Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 Support - Bare Minimum #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Packages
*.egg
*.egg-info
.eggs
dist
build
eggs
Expand All @@ -21,6 +22,7 @@ pip-log.txt

# Unit test / coverage reports
.coverage
.pytest_cache

# Translations
*.mo
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def run_tests(self):
]

install_requires = [

'six'
]

# Readthedocs requires Sphinx extensions to be specified as part of
Expand Down
18 changes: 10 additions & 8 deletions source/lucidity/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# :license: See LICENSE.txt.

import abc
import six
import sys
import re
import functools
Expand Down Expand Up @@ -247,12 +248,11 @@ def _construct_regular_expression(self, pattern):
'bad group name' in str(error),
'bad character in group name' in str(error)
]):
raise ValueError('Placeholder name contains invalid '
'characters.')
message = 'Placeholder name contains invalid characters.'
else:
_, value, traceback = sys.exc_info()
message = 'Invalid pattern: {0}'.format(value)
raise ValueError, message, traceback #@IgnorePep8
message = 'Invalid pattern: ' + str(error)

six.raise_from(ValueError(message), error)

return compiled

Expand Down Expand Up @@ -303,10 +303,12 @@ def _escape(self, match):
return groups['placeholder']


class Resolver(object):
'''Template resolver interface.'''
# Python 2 and 3 compatible ABCMeta
ABC = abc.ABCMeta('ABC', (object,), {})

__metaclass__ = abc.ABCMeta

class Resolver(ABC):
'''Template resolver interface.'''

@abc.abstractmethod
def get(self, template_name, default=None):
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_lucidity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

TEST_TEMPLATE_PATH = os.path.join(
os.path.dirname(__file__), '..', 'fixture', 'template'
)
)


@pytest.fixture
Expand All @@ -36,7 +36,7 @@ def test_discover(recursive, expected):
templates = lucidity.discover_templates(
[TEST_TEMPLATE_PATH], recursive=recursive
)
assert map(operator.attrgetter('name'), templates) == expected
assert [t.name for t in templates] == expected


@pytest.mark.parametrize(('path', 'expected'), [
Expand All @@ -50,7 +50,7 @@ def test_discover_with_env(path, expected, monkeypatch):
'''Discover templates using environment variable.'''
monkeypatch.setenv('LUCIDITY_TEMPLATE_PATH', path)
templates = lucidity.discover_templates()
assert map(operator.attrgetter('name'), templates) == expected
assert [t.name for t in templates] == expected


@pytest.mark.parametrize(('path', 'expected'), [
Expand Down