From f35402a2a1208e0e7520ebc0fa2796159f2f63ce Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Thu, 24 Sep 2020 09:21:57 +0100 Subject: [PATCH 01/10] Add first draft render_patterns management command --- pattern_library/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/render_patterns.py | 36 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 pattern_library/management/__init__.py create mode 100644 pattern_library/management/commands/__init__.py create mode 100644 pattern_library/management/commands/render_patterns.py diff --git a/pattern_library/management/__init__.py b/pattern_library/management/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pattern_library/management/commands/__init__.py b/pattern_library/management/commands/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py new file mode 100644 index 00000000..1eed3cef --- /dev/null +++ b/pattern_library/management/commands/render_patterns.py @@ -0,0 +1,36 @@ +from pathlib import Path + +from django.core.management.base import BaseCommand +from django.test.client import RequestFactory + +from pattern_library.utils import ( + get_pattern_templates, render_pattern +) + + +class Command(BaseCommand): + help = "Renders all patterns." + + def handle(self, **options): + templates = get_pattern_templates() + factory = RequestFactory() + request = factory.get('/') + parent_dir = Path.cwd().joinpath('dpl-static') + parent_dir.mkdir(exist_ok=True) + self.render_group(request, parent_dir, templates) + + def render_group(self, request, parent_dir: Path, pattern_templates): + for template in pattern_templates['templates_stored']: + print(template.origin.template_name) + print('-------------------') + render_path = parent_dir.joinpath(template.pattern_name) + render_path.write_text(render_pattern(request, template.origin.template_name)) + + if not pattern_templates['template_groups']: + return + + for pattern_type_group, pattern_templates in pattern_templates['template_groups'].items(): + print(pattern_type_group) + group_parent = parent_dir.joinpath(pattern_type_group) + group_parent.mkdir(exist_ok=True) + self.render_group(request, group_parent, pattern_templates) From cb1ce4cf0c95aae98e1916a4d473723b295c20ae Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Thu, 24 Sep 2020 14:55:29 +0100 Subject: [PATCH 02/10] Refine implementation for real-world usage --- .../management/commands/render_patterns.py | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index 1eed3cef..dc9b432c 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -9,28 +9,61 @@ class Command(BaseCommand): - help = "Renders all patterns." + help = "Renders all django-pattern-library patterns to HTML files, in a directory structure." + + def add_arguments(self, parser): + super().add_arguments(parser) + parser.add_argument( + '--output', + '-o', + action='store', + dest='output_dir', + default='dpl-rendered-patterns', + help='Directory where to render your patterns', + type=str, + ) + parser.add_argument( + '--dry-run', + action='store_true', + help="Render the patterns without writing them to disk.", + ) def handle(self, **options): + self.verbosity = options['verbosity'] + self.dry_run = options['dry_run'] + self.output_dir = options['output_dir'] + templates = get_pattern_templates() + factory = RequestFactory() request = factory.get('/') - parent_dir = Path.cwd().joinpath('dpl-static') + + if self.verbosity >= 2: + self.stdout.write(f'Target directory: {self.output_dir}') + + # Resolve the output dir according to the directory the command is run from. + parent_dir = Path.cwd().joinpath(self.output_dir) parent_dir.mkdir(exist_ok=True) + self.render_group(request, parent_dir, templates) def render_group(self, request, parent_dir: Path, pattern_templates): for template in pattern_templates['templates_stored']: - print(template.origin.template_name) - print('-------------------') + if self.verbosity >= 2: + self.stdout.write(f'Pattern: {template.pattern_name}') + if self.verbosity >= 1: + self.stdout.write(template.origin.template_name) + render_path = parent_dir.joinpath(template.pattern_name) - render_path.write_text(render_pattern(request, template.origin.template_name)) + rendered_pattern = render_pattern(request, template.origin.template_name) + render_path.write_text(rendered_pattern) if not pattern_templates['template_groups']: return for pattern_type_group, pattern_templates in pattern_templates['template_groups'].items(): - print(pattern_type_group) + if self.verbosity >= 2: + self.stdout.write(f'Group: {pattern_type_group}') group_parent = parent_dir.joinpath(pattern_type_group) group_parent.mkdir(exist_ok=True) self.render_group(request, group_parent, pattern_templates) From d789a9b0d16a7d00eb63ddb4eaf8dd668f45c62d Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Thu, 24 Sep 2020 15:08:18 +0100 Subject: [PATCH 03/10] Implement dry run support --- .../management/commands/render_patterns.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index dc9b432c..130e88f0 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -43,7 +43,9 @@ def handle(self, **options): # Resolve the output dir according to the directory the command is run from. parent_dir = Path.cwd().joinpath(self.output_dir) - parent_dir.mkdir(exist_ok=True) + + if not self.dry_run: + parent_dir.mkdir(exist_ok=True) self.render_group(request, parent_dir, templates) @@ -56,7 +58,12 @@ def render_group(self, request, parent_dir: Path, pattern_templates): render_path = parent_dir.joinpath(template.pattern_name) rendered_pattern = render_pattern(request, template.origin.template_name) - render_path.write_text(rendered_pattern) + + if self.dry_run: + if self.verbosity >= 2: + self.stdout.write(rendered_pattern) + else: + render_path.write_text(rendered_pattern) if not pattern_templates['template_groups']: return @@ -65,5 +72,6 @@ def render_group(self, request, parent_dir: Path, pattern_templates): if self.verbosity >= 2: self.stdout.write(f'Group: {pattern_type_group}') group_parent = parent_dir.joinpath(pattern_type_group) - group_parent.mkdir(exist_ok=True) + if not self.dry_run: + group_parent.mkdir(exist_ok=True) self.render_group(request, group_parent, pattern_templates) From 68ff2cdea9c2b589b20c8700437d29505f3019d2 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Thu, 24 Sep 2020 17:07:58 +0100 Subject: [PATCH 04/10] Add tests (unit / integration) for new render_patterns command --- tests/tests/test_commands.py | 78 ++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/tests/test_commands.py diff --git a/tests/tests/test_commands.py b/tests/tests/test_commands.py new file mode 100644 index 00000000..5b403169 --- /dev/null +++ b/tests/tests/test_commands.py @@ -0,0 +1,78 @@ +import io + +import tempfile +from pathlib import Path +import shutil + +from django.test import SimpleTestCase +from django.core.management import call_command + + +class RenderPatternsTests(SimpleTestCase): + """Tests of the render_pattern command’s output, based on the test project’s templates""" + + def test_displays_patterns(self): + stdout = io.StringIO() + call_command('render_patterns', dry_run=True, stdout=stdout) + stdout = stdout.getvalue() + self.assertIn("""patterns/atoms/tags_test_atom/tags_test_atom.html +patterns/atoms/test_atom/test_atom.html +""", stdout) + + def test_verbose_output(self): + stdout = io.StringIO() + call_command('render_patterns', dry_run=True, stdout=stdout, verbosity=2) + stdout = stdout.getvalue() + self.assertIn("""Target directory: dpl-rendered-patterns +Group: atoms +Group: tags_test_atom +Pattern: tags_test_atom.html +patterns/atoms/tags_test_atom/tags_test_atom.html + + +SANDWICH +SANDNoneWICH +SAND0WICH +""", stdout) + + def test_quiet_output(self): + stdout = io.StringIO() + call_command('render_patterns', dry_run=True, stdout=stdout, verbosity=0) + stdout = stdout.getvalue() + self.assertEqual(stdout, '') + + def test_shows_output_folder(self): + stdout = io.StringIO() + temp = tempfile.gettempdir() + call_command('render_patterns', dry_run=True, stdout=stdout, output=temp, verbosity=2) + stdout = stdout.getvalue() + self.assertIn(temp, stdout) + + +class RenderPatternsFileSystemTests(SimpleTestCase): + """Tests of the render_pattern command’s file system changes, based on the test project’s templates""" + + def setUp(self): + self.output = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self.output) + + def test_uses_output(self): + stdout = io.StringIO() + modification_time_before = Path(self.output).stat().st_mtime + call_command('render_patterns', dry_run=False, stdout=stdout, output=self.output) + self.assertNotEqual(Path(self.output).stat().st_mtime, modification_time_before) + stdout = stdout.getvalue() + + def test_uses_subfolders(self): + stdout = io.StringIO() + call_command('render_patterns', dry_run=False, stdout=stdout, output=self.output) + subfolders = Path(self.output).iterdir() + self.assertIn('atoms', [p.name for p in subfolders]) + + def test_outputs_html(self): + stdout = io.StringIO() + call_command('render_patterns', dry_run=False, stdout=stdout, output=self.output) + html_files = Path(self.output).glob('**/*.html') + self.assertIn('test_atom.html', [p.name for p in html_files]) From 196dab844e68ddde9897e8f6771cc08c6866ddef Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 2 Nov 2020 15:18:25 +0000 Subject: [PATCH 05/10] Switch render_patterns to do most of its logging to stderr --- .../management/commands/render_patterns.py | 8 +-- .../templates/patterns/atoms/icons/icon.yaml | 2 + tests/tests/test_commands.py | 49 ++++++++++--------- 3 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 tests/templates/patterns/atoms/icons/icon.yaml diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index 130e88f0..95d25499 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -39,7 +39,7 @@ def handle(self, **options): request = factory.get('/') if self.verbosity >= 2: - self.stdout.write(f'Target directory: {self.output_dir}') + self.stderr.write(f'Target directory: {self.output_dir}') # Resolve the output dir according to the directory the command is run from. parent_dir = Path.cwd().joinpath(self.output_dir) @@ -52,9 +52,9 @@ def handle(self, **options): def render_group(self, request, parent_dir: Path, pattern_templates): for template in pattern_templates['templates_stored']: if self.verbosity >= 2: - self.stdout.write(f'Pattern: {template.pattern_name}') + self.stderr.write(f'Pattern: {template.pattern_name}') if self.verbosity >= 1: - self.stdout.write(template.origin.template_name) + self.stderr.write(template.origin.template_name) render_path = parent_dir.joinpath(template.pattern_name) rendered_pattern = render_pattern(request, template.origin.template_name) @@ -70,7 +70,7 @@ def render_group(self, request, parent_dir: Path, pattern_templates): for pattern_type_group, pattern_templates in pattern_templates['template_groups'].items(): if self.verbosity >= 2: - self.stdout.write(f'Group: {pattern_type_group}') + self.stderr.write(f'Group: {pattern_type_group}') group_parent = parent_dir.joinpath(pattern_type_group) if not self.dry_run: group_parent.mkdir(exist_ok=True) diff --git a/tests/templates/patterns/atoms/icons/icon.yaml b/tests/templates/patterns/atoms/icons/icon.yaml new file mode 100644 index 00000000..2ebc4180 --- /dev/null +++ b/tests/templates/patterns/atoms/icons/icon.yaml @@ -0,0 +1,2 @@ +context: + name: close diff --git a/tests/tests/test_commands.py b/tests/tests/test_commands.py index 5b403169..1c989725 100644 --- a/tests/tests/test_commands.py +++ b/tests/tests/test_commands.py @@ -13,40 +13,39 @@ class RenderPatternsTests(SimpleTestCase): def test_displays_patterns(self): stdout = io.StringIO() - call_command('render_patterns', dry_run=True, stdout=stdout) - stdout = stdout.getvalue() + stderr = io.StringIO() + call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr) self.assertIn("""patterns/atoms/tags_test_atom/tags_test_atom.html patterns/atoms/test_atom/test_atom.html -""", stdout) +""", stderr.getvalue()) def test_verbose_output(self): stdout = io.StringIO() - call_command('render_patterns', dry_run=True, stdout=stdout, verbosity=2) - stdout = stdout.getvalue() + stderr = io.StringIO() + call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr, verbosity=2) self.assertIn("""Target directory: dpl-rendered-patterns Group: atoms -Group: tags_test_atom -Pattern: tags_test_atom.html -patterns/atoms/tags_test_atom/tags_test_atom.html - - -SANDWICH -SANDNoneWICH -SAND0WICH -""", stdout) +Group: icons +Pattern: icon.html +patterns/atoms/icons/icon.html +""", stderr.getvalue()) + self.assertIn("""""", stdout.getvalue()) def test_quiet_output(self): stdout = io.StringIO() - call_command('render_patterns', dry_run=True, stdout=stdout, verbosity=0) - stdout = stdout.getvalue() - self.assertEqual(stdout, '') + stderr = io.StringIO() + call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr, verbosity=0) + self.assertEqual(stdout.getvalue(), '') + self.assertEqual(stderr.getvalue(), '') def test_shows_output_folder(self): stdout = io.StringIO() + stderr = io.StringIO() temp = tempfile.gettempdir() - call_command('render_patterns', dry_run=True, stdout=stdout, output=temp, verbosity=2) - stdout = stdout.getvalue() - self.assertIn(temp, stdout) + call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr, output=temp, verbosity=2) + self.assertIn(temp, stderr.getvalue()) class RenderPatternsFileSystemTests(SimpleTestCase): @@ -60,19 +59,21 @@ def tearDown(self): def test_uses_output(self): stdout = io.StringIO() + stderr = io.StringIO() modification_time_before = Path(self.output).stat().st_mtime - call_command('render_patterns', dry_run=False, stdout=stdout, output=self.output) + call_command('render_patterns', dry_run=False, stdout=stdout, stderr=stderr, output=self.output) self.assertNotEqual(Path(self.output).stat().st_mtime, modification_time_before) - stdout = stdout.getvalue() def test_uses_subfolders(self): stdout = io.StringIO() - call_command('render_patterns', dry_run=False, stdout=stdout, output=self.output) + stderr = io.StringIO() + call_command('render_patterns', dry_run=False, stdout=stdout, stderr=stderr, output=self.output) subfolders = Path(self.output).iterdir() self.assertIn('atoms', [p.name for p in subfolders]) def test_outputs_html(self): stdout = io.StringIO() - call_command('render_patterns', dry_run=False, stdout=stdout, output=self.output) + stderr = io.StringIO() + call_command('render_patterns', dry_run=False, stdout=stdout, stderr=stderr, output=self.output) html_files = Path(self.output).glob('**/*.html') self.assertIn('test_atom.html', [p.name for p in html_files]) From 5e0035329a8d5b9d24d4d078cc2647e95cb2a4b6 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 2 Nov 2020 15:46:24 +0000 Subject: [PATCH 06/10] Log whether render_patterns is dry run or not --- pattern_library/management/commands/render_patterns.py | 5 ++++- tests/tests/test_commands.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index 95d25499..a000dfe2 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -39,7 +39,10 @@ def handle(self, **options): request = factory.get('/') if self.verbosity >= 2: - self.stderr.write(f'Target directory: {self.output_dir}') + if self.dry_run: + self.stderr.write(f'Target directory: {self.output_dir}. Dry run, not writing files to disk') + else: + self.stderr.write(f'Target directory: {self.output_dir}') # Resolve the output dir according to the directory the command is run from. parent_dir = Path.cwd().joinpath(self.output_dir) diff --git a/tests/tests/test_commands.py b/tests/tests/test_commands.py index 1c989725..e7a48793 100644 --- a/tests/tests/test_commands.py +++ b/tests/tests/test_commands.py @@ -23,7 +23,7 @@ def test_verbose_output(self): stdout = io.StringIO() stderr = io.StringIO() call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr, verbosity=2) - self.assertIn("""Target directory: dpl-rendered-patterns + self.assertIn("""Target directory: dpl-rendered-patterns. Dry run, not writing files to disk Group: atoms Group: icons Pattern: icon.html From 004bf5111b94a0edd779d984731d331b4a5f9bc1 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 2 Nov 2020 15:51:30 +0000 Subject: [PATCH 07/10] Add support for render_patterns wrapping fragments in the base template --- .../management/commands/render_patterns.py | 37 ++++++++++++++++++- tests/tests/test_commands.py | 14 +++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index a000dfe2..592e6204 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -1,10 +1,12 @@ from pathlib import Path from django.core.management.base import BaseCommand +from django.template.loader import render_to_string from django.test.client import RequestFactory +from pattern_library import get_base_template_names, get_pattern_base_template_name from pattern_library.utils import ( - get_pattern_templates, render_pattern + get_pattern_templates, get_pattern_context, get_template_ancestors, render_pattern ) @@ -27,10 +29,16 @@ def add_arguments(self, parser): action='store_true', help="Render the patterns without writing them to disk.", ) + parser.add_argument( + '--wrap-fragments', + action='store_true', + help="Render fragment patterns wrapped in the base template.", + ) def handle(self, **options): self.verbosity = options['verbosity'] self.dry_run = options['dry_run'] + self.wrap_fragments = options['wrap_fragments'] self.output_dir = options['output_dir'] templates = get_pattern_templates() @@ -44,6 +52,10 @@ def handle(self, **options): else: self.stderr.write(f'Target directory: {self.output_dir}') + if self.wrap_fragments: + self.stderr.write('Writing fragment patterns wrapped in base template') + + # Resolve the output dir according to the directory the command is run from. parent_dir = Path.cwd().joinpath(self.output_dir) @@ -60,7 +72,7 @@ def render_group(self, request, parent_dir: Path, pattern_templates): self.stderr.write(template.origin.template_name) render_path = parent_dir.joinpath(template.pattern_name) - rendered_pattern = render_pattern(request, template.origin.template_name) + rendered_pattern = self.render_pattern(request, template.origin.template_name) if self.dry_run: if self.verbosity >= 2: @@ -78,3 +90,24 @@ def render_group(self, request, parent_dir: Path, pattern_templates): if not self.dry_run: group_parent.mkdir(exist_ok=True) self.render_group(request, group_parent, pattern_templates) + + def render_pattern(self, request, pattern_template_name): + rendered_pattern = render_pattern(request, pattern_template_name) + + # If we don’t wrap fragments in the base template, we can simply render the pattern and return as-is. + if not self.wrap_fragments: + return rendered_pattern + + pattern_template_ancestors = get_template_ancestors( + pattern_template_name, + context=get_pattern_context(pattern_template_name), + ) + pattern_is_fragment = set(pattern_template_ancestors).isdisjoint(set(get_base_template_names())) + + if pattern_is_fragment: + base_template = get_pattern_base_template_name() + context = get_pattern_context(base_template) + context['pattern_library_rendered_pattern'] = rendered_pattern + return render_to_string(base_template, request=request, context=context) + else: + return rendered_pattern diff --git a/tests/tests/test_commands.py b/tests/tests/test_commands.py index e7a48793..86b96308 100644 --- a/tests/tests/test_commands.py +++ b/tests/tests/test_commands.py @@ -47,6 +47,20 @@ def test_shows_output_folder(self): call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr, output=temp, verbosity=2) self.assertIn(temp, stderr.getvalue()) + def test_shows_wrap_fragment(self): + stdout = io.StringIO() + stderr = io.StringIO() + call_command('render_patterns', dry_run=True, wrap_fragments=True, stdout=stdout, stderr=stderr, verbosity=2) + self.assertIn('Writing fragment patterns wrapped in base template', stderr.getvalue()) + # Only testing a small subset of the output just to show patterns are wrapped. + self.assertIn(""" + + + +""", stdout.getvalue()) + class RenderPatternsFileSystemTests(SimpleTestCase): """Tests of the render_pattern command’s file system changes, based on the test project’s templates""" From e7577c953c2519dc8568873c8cb34868fd8119d5 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 2 Nov 2020 15:52:11 +0000 Subject: [PATCH 08/10] Ignore dpl-rendered-patterns --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e43caa8f..65ef6861 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ local.py # ------------------------------------------------- # Your own project's ignores # ------------------------------------------------- +dpl-rendered-patterns From 16abc218a6069aca777e69165ba3437223a97f21 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 2 Nov 2020 15:57:01 +0000 Subject: [PATCH 09/10] Add render_patterns to project test suite & contributing notes --- CONTRIBUTING.md | 5 ++++- pattern_library/management/commands/render_patterns.py | 1 - tox.ini | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 14e29c87..3155d3af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,10 @@ Then you can install the dependencies and run the test app: ```sh poetry install -poetry run 'django-admin runserver --settings=tests.settings --pythonpath=.' +# Start the server for testing: +poetry run django-admin runserver --settings=tests.settings --pythonpath=. +# Or to try out the render_patterns command: +poetry run django-admin render_patterns --settings=tests.settings --pythonpath=. --dry-run --verbosity 2 ``` ### Run a local build with docker diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index 592e6204..2b709901 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -55,7 +55,6 @@ def handle(self, **options): if self.wrap_fragments: self.stderr.write('Writing fragment patterns wrapped in base template') - # Resolve the output dir according to the directory the command is run from. parent_dir = Path.cwd().joinpath(self.output_dir) diff --git a/tox.ini b/tox.ini index 6154dac5..39005b63 100644 --- a/tox.ini +++ b/tox.ini @@ -9,6 +9,7 @@ install_command = ./tox_install.sh {packages} commands = poetry run ./runtests.py + poetry run django-admin render_patterns --settings=tests.settings --pythonpath=. --dry-run deps = dj22: Django>=2.2,<2.3 dj30: Django>=3.0,<3.1 From 8940474df90867c0803c607ec438b8f929bedeee Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Mon, 2 Nov 2020 16:08:32 +0000 Subject: [PATCH 10/10] Sort imports with isort --- pattern_library/management/commands/render_patterns.py | 7 +++++-- tests/tests/test_commands.py | 5 ++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pattern_library/management/commands/render_patterns.py b/pattern_library/management/commands/render_patterns.py index 2b709901..3f3d3bb1 100644 --- a/pattern_library/management/commands/render_patterns.py +++ b/pattern_library/management/commands/render_patterns.py @@ -4,9 +4,12 @@ from django.template.loader import render_to_string from django.test.client import RequestFactory -from pattern_library import get_base_template_names, get_pattern_base_template_name +from pattern_library import ( + get_base_template_names, get_pattern_base_template_name +) from pattern_library.utils import ( - get_pattern_templates, get_pattern_context, get_template_ancestors, render_pattern + get_pattern_context, get_pattern_templates, get_template_ancestors, + render_pattern ) diff --git a/tests/tests/test_commands.py b/tests/tests/test_commands.py index 86b96308..26473bbd 100644 --- a/tests/tests/test_commands.py +++ b/tests/tests/test_commands.py @@ -1,11 +1,10 @@ import io - +import shutil import tempfile from pathlib import Path -import shutil -from django.test import SimpleTestCase from django.core.management import call_command +from django.test import SimpleTestCase class RenderPatternsTests(SimpleTestCase):