Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: getnikola/nikola
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9a27a2cd635f
Choose a base ref
...
head repository: getnikola/nikola
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 4bbdd98979ce
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Dec 24, 2015

  1. Remove debug print

    Signed-off-by: Chris Warrick <kwpolska@gmail.com>
    Kwpolska committed Dec 24, 2015
    Copy the full SHA
    5688899 View commit details
  2. Fix tests on Python 2.7

    Signed-off-by: Chris Warrick <kwpolska@gmail.com>
    Kwpolska committed Dec 24, 2015
    Copy the full SHA
    4bbdd98 View commit details
Showing with 9 additions and 4 deletions.
  1. +0 −1 nikola/shortcodes.py
  2. +9 −3 tests/test_shortcodes.py
1 change: 0 additions & 1 deletion nikola/shortcodes.py
Original file line number Diff line number Diff line change
@@ -125,7 +125,6 @@ def parse_sc(data):
cvalue = ''
qc = ''
for char in elements[1]:
print(char, flag)
if flag & 0b100 and flag & 1:
# Backslash in value: escape next character, no matter what
cvalue += char
12 changes: 9 additions & 3 deletions tests/test_shortcodes.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
import pytest
from nikola import shortcodes
from .base import FakeSite
import sys

def noargs(site, data=''):
return "noargs {0} success!".format(data)
@@ -15,6 +16,10 @@ def arg(*args, **kwargs):
# don’t clutter the kwargs dict
_ = kwargs.pop('site')
data = kwargs.pop('data')
# TODO hack for Python 2.7 -- remove when possible
if sys.version_info[0] == 2:
args = tuple(i.encode('utf-8') for i in args)
kwargs = {k.encode('utf-8'): v.encode('utf-8') for k, v in kwargs.items()}
return "arg {0}/{1}/{2}".format(args, sorted(kwargs.items()), data)


@@ -32,15 +37,16 @@ def test_noargs(fakesite):
def test_arg_pos(fakesite):
assert shortcodes.apply_shortcodes('test({{% arg 1 %}})', fakesite.shortcode_registry) == "test(arg ('1',)/[]/)"
assert shortcodes.apply_shortcodes('test({{% arg 1 2aa %}})', fakesite.shortcode_registry) == "test(arg ('1', '2aa')/[]/)"
# TODO: currently unsupported!
# assert shortcodes.apply_shortcodes('test({{% arg "hello world" %}})', fakesite.shortcode_registry) == "test(arg ('hello world',)/[]/)"
assert shortcodes.apply_shortcodes('test({{% arg "hello world" %}})', fakesite.shortcode_registry) == "test(arg ('hello world',)/[]/)"
assert shortcodes.apply_shortcodes('test({{% arg back\ slash arg2 %}})', fakesite.shortcode_registry) == "test(arg ('back slash', 'arg2')/[]/)"

def test_arg_keyword(fakesite):
assert shortcodes.apply_shortcodes('test({{% arg 1a=2b %}})', fakesite.shortcode_registry) == "test(arg ()/[('1a', '2b')]/)"
assert shortcodes.apply_shortcodes('test({{% arg 1a="2b 3c" 4d=5f %}})', fakesite.shortcode_registry) == "test(arg ()/[('1a', '2b 3c'), ('4d', '5f')]/)"
assert shortcodes.apply_shortcodes('test({{% arg 1a="2b 3c" 4d=5f back=slash\ slash %}})', fakesite.shortcode_registry) == "test(arg ()/[('1a', '2b 3c'), ('4d', '5f'), ('back', 'slash slash')]/)"

def test_data(fakesite):
assert shortcodes.apply_shortcodes('test({{% arg 123 %}}Hello!{{% /arg %}})', fakesite.shortcode_registry) == "test(arg ('123',)/[]/Hello!)"
assert shortcodes.apply_shortcodes('test({{% arg 123 456 foo=bar %}}Hello world!{{% /arg %}})', fakesite.shortcode_registry) == "test(arg ('123', '456')/[('foo', 'bar')]/Hello world!)"
assert shortcodes.apply_shortcodes('test({{% arg 123 456 foo=bar baz="quotes rock." %}}Hello test suite!{{% /arg %}})', fakesite.shortcode_registry) == "test(arg ('123', '456')/[('baz', 'quotes rock.'), ('foo', 'bar')]/Hello test suite!)"
# assert shortcodes.apply_shortcodes('test({{% arg "123 foo" foobar foo=bar baz="quotes rock." %}}Hello test suite!!{{% /arg %}})', fakesite.shortcode_registry) == "test(arg ('123 foo', 'foobar')/[('baz', 'quotes rock.'), ('foo', 'bar')]/Hello test suite!!)"
assert shortcodes.apply_shortcodes('test({{% arg "123 foo" foobar foo=bar baz="quotes rock." %}}Hello test suite!!{{% /arg %}})', fakesite.shortcode_registry) == "test(arg ('123 foo', 'foobar')/[('baz', 'quotes rock.'), ('foo', 'bar')]/Hello test suite!!)"