Skip to content

Commit dc35644

Browse files
committed
Fix render_patterns using the wrong value as a file name
1 parent ad29167 commit dc35644

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

pattern_library/management/commands/render_patterns.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ def handle(self, **options):
6969
def render_group(self, request, parent_dir: Path, pattern_templates):
7070
for template in pattern_templates['templates_stored']:
7171
if self.verbosity >= 2:
72-
self.stderr.write(f'Pattern: {template.pattern_name}')
72+
self.stderr.write(f'Pattern: {template.pattern_filename}')
7373
if self.verbosity >= 1:
7474
self.stderr.write(template.origin.template_name)
7575

76-
render_path = parent_dir.joinpath(template.pattern_name)
76+
render_path = parent_dir.joinpath(template.pattern_filename)
7777
rendered_pattern = self.render_pattern(request, template.origin.template_name)
7878

7979
if self.dry_run:

pattern_library/utils.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,17 @@ def get_pattern_templates():
9292
template = get_template(pattern_path)
9393
pattern_config = get_pattern_config(pattern_path)
9494
pattern_name = pattern_config.get('name')
95+
pattern_filename = os.path.relpath(
96+
template.origin.template_name,
97+
base_path,
98+
)
9599
if pattern_name:
96100
template.pattern_name = pattern_name
97101
else:
98-
template.pattern_name = os.path.relpath(
99-
template.origin.template_name,
100-
base_path,
101-
)
102+
template.pattern_name = pattern_filename
103+
104+
template.pattern_filename = pattern_filename
105+
102106
found_templates.append(template)
103107

104108
if found_templates:

tests/tests/test_commands.py

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def test_shows_wrap_fragment(self):
6060
</body>
6161
</html>""", stdout.getvalue())
6262

63+
def test_saves_with_template_filename(self):
64+
stdout = io.StringIO()
65+
stderr = io.StringIO()
66+
call_command('render_patterns', dry_run=True, stdout=stdout, stderr=stderr, verbosity=2)
67+
self.assertIn('Pattern: test_molecule.html', stderr.getvalue())
68+
6369

6470
class RenderPatternsFileSystemTests(SimpleTestCase):
6571
"""Tests of the render_pattern command’s file system changes, based on the test project’s templates"""

0 commit comments

Comments
 (0)