Skip to content

Commit

Permalink
[FIX, TESTING] Fix example code tester (hedyorg#4083)
Browse files Browse the repository at this point in the history
* when a level misses example code, the example code of the previous level is tested (leading to issues)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Felienne and pre-commit-ci[bot] authored Mar 2, 2023
1 parent bfeb69b commit 1e3b204
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tests/test_snippets/test_adventures.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,25 @@ def collect_snippets(path, filtered_language=None):
# Code snippets inside example code
try:
example_code = utils.markdown_to_html_tags(level['example_code'])
for tag in example_code:
if tag.name != 'pre' or not tag.contents[0]:
continue
code_snippet_counter += 1
try:
code = tag.contents[0].contents[0]
except BaseException:
print("Code container is empty...")
continue

snippet = Snippet(
filename=f,
level=level_number,
field_name=adventure_name + ' snippet #' + str(code_snippet_counter),
code=code,
adventure_name=adventure_name)
Hedy_snippets.append(snippet)
except Exception as E:
print(E)
for tag in example_code:
if tag.name != 'pre' or not tag.contents[0]:
continue
code_snippet_counter += 1
try:
code = tag.contents[0].contents[0]
except BaseException:
print("Code container is empty...")
continue

snippet = Snippet(
filename=f,
level=level_number,
field_name=adventure_name + ' snippet #' + str(code_snippet_counter),
code=code,
adventure_name=adventure_name)
Hedy_snippets.append(snippet)

return Hedy_snippets

Expand All @@ -106,7 +106,7 @@ def collect_snippets(path, filtered_language=None):
Hedy_snippets = [(s.name, s) for s in collect_snippets(path='../../content/adventures',
filtered_language=filtered_language)]
#
# level = 3
# level = 4
if level:
Hedy_snippets = [(name, snippet) for (name, snippet) in Hedy_snippets if snippet.level == level]

Expand Down

0 comments on commit 1e3b204

Please sign in to comment.