]> Devi Nivas Git - chevron.git/commitdiff
fix my flake issues
authorKay-Uwe (Kiwi) Lorenz <kiwi@franka.dyndns.org>
Sat, 28 Jul 2018 07:15:50 +0000 (09:15 +0200)
committerKay-Uwe (Kiwi) Lorenz <kiwi@franka.dyndns.org>
Sat, 28 Jul 2018 07:15:50 +0000 (09:15 +0200)
chevron/renderer.py
test_spec.py

index 2f933676a7c3f9d35a1304b3eb42f20344cca393..bcd4f3c6a60c03e252e4105c9026a772e3326e4c 100644 (file)
@@ -214,12 +214,11 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
             # Get the sections scope
             scope = _get_key(key, scopes)
 
-            # If the scope is a callable (as described in https://mustache.github.io/mustache.5.html)
+            # If the scope is a callable (as described in
+            # https://mustache.github.io/mustache.5.html)
             if type(scope) is function:
 
-                # Gather up all the tags inside the section and generate a template text
-                tags = []
-
+                # Generate template text from tags
                 text = unicode('', 'utf-8')
                 for tag in tokens:
                     if tag == ('end', key):
@@ -231,7 +230,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
                     elif tag_type == 'no escape':
                         text += "%s& %s %s" % (def_ldel, tag_key, def_rdel)
                     else:
-                        text += "%s%s %s%s" % (def_ldel,{
+                        text += "%s%s %s%s" % (def_ldel, {
                                 'commment': '!',
                                 'section': '#',
                                 'inverted section': '^',
@@ -241,16 +240,14 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
                                 'no escape': '&'
                             }[tag_type], tag_key, def_rdel)
 
-                    tags.append(tag)
-
                 rend = scope(text, lambda template, data=None: render(template,
-                        data={},
-                        partials_path=partials_path,
-                        partials_ext=partials_ext,
-                        partials_dict=partials_dict,
-                        padding=padding,
-                        def_ldel=def_ldel, def_rdel=def_rdel,
-                        scopes=data and [data]+scopes or scopes))
+                             data={},
+                             partials_path=partials_path,
+                             partials_ext=partials_ext,
+                             partials_dict=partials_dict,
+                             padding=padding,
+                             def_ldel=def_ldel, def_rdel=def_rdel,
+                             scopes=data and [data]+scopes or scopes))
 
                 if python3:
                     output += rend
index 14e8eeeea87425c08d07d98d4d0118e7f8a46da4..ccb136b1c32c67e2496b2c5f6c9e054f3456bb0b 100755 (executable)
@@ -6,7 +6,6 @@ import os
 import json
 
 import chevron
-from textwrap import dedent
 
 SPECS_PATH = os.path.join('spec', 'specs')
 if os.path.exists(SPECS_PATH):
@@ -236,6 +235,7 @@ class ExpandedCoverage(unittest.TestCase):
     # https://github.com/noahmorrison/chevron/issues/17
     def test_callable_1(self):
         args_passed = {}
+
         def first(content, render):
             args_passed['content'] = content
             args_passed['render'] = render
@@ -243,7 +243,8 @@ class ExpandedCoverage(unittest.TestCase):
             return "not implemented"
 
         args = {
-            'template': '{{{postcode}}} {{#first}} {{{city}}} || {{{town}}} || {{{village}}} || {{{state}}} {{/first}}',
+            'template': '{{{postcode}}} {{#first}} {{{city}}} || {{{town}}} '
+                        '|| {{{village}}} || {{{state}}} {{/first}}',
             'data': {
                 "postcode": "1234",
                 "city": "Mustache City",
@@ -255,20 +256,22 @@ class ExpandedCoverage(unittest.TestCase):
 
         result = chevron.render(**args)
         expected = '1234 not implemented'
-        template_content = " {{& city }} || {{& town }} || {{& village }} || {{& state }} "
+        template_content = " {{& city }} || {{& town }} || {{& village }} "\
+                           "|| {{& state }} "
 
         self.assertEqual(result, expected)
         self.assertEqual(args_passed['content'], template_content)
 
     def test_callable_2(self):
-        args_passed = {}
+
         def first(content, render):
             result = render(content)
-            result = [ x.strip() for x in result.split(" || ") if x.strip() ]
+            result = [x.strip() for x in result.split(" || ") if x.strip()]
             return result[0]
 
         args = {
-            'template': '{{{postcode}}} {{#first}} {{{city}}} || {{{town}}} || {{{village}}} || {{{state}}} {{/first}}',
+            'template': '{{{postcode}}} {{#first}} {{{city}}} || {{{town}}} '
+                        '|| {{{village}}} || {{{state}}} {{/first}}',
             'data': {
                 "postcode": "1234",
                 "town": "Mustache Town",
@@ -279,21 +282,21 @@ class ExpandedCoverage(unittest.TestCase):
 
         result = chevron.render(**args)
         expected = '1234 Mustache Town'
-        template_content = " {{& city }} || {{& town }} || {{& village }} || {{& state }} "
 
         self.assertEqual(result, expected)
 
     def test_callable_3(self):
         '''Test generating some data within the function
         '''
-        args_passed = {}
+
         def first(content, render):
             result = render(content, {'city': "Injected City"})
-            result = [ x.strip() for x in result.split(" || ") if x.strip() ]
+            result = [x.strip() for x in result.split(" || ") if x.strip()]
             return result[0]
 
         args = {
-            'template': '{{{postcode}}} {{#first}} {{{city}}} || {{{town}}} || {{{village}}} || {{{state}}} {{/first}}',
+            'template': '{{{postcode}}} {{#first}} {{{city}}} || {{{town}}} '
+                        '|| {{{village}}} || {{{state}}} {{/first}}',
             'data': {
                 "postcode": "1234",
                 "town": "Mustache Town",
@@ -304,7 +307,6 @@ class ExpandedCoverage(unittest.TestCase):
 
         result = chevron.render(**args)
         expected = '1234 Injected City'
-        template_content = " {{& city }} || {{& town }} || {{& village }} || {{& state }} "
 
         self.assertEqual(result, expected)