Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Resistor Color Expert]: Corrected Small Typos #3469

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions bin/generate_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ def format_file(path: Path) -> NoReturn:


def check_template(slug: str, tests_path: Path, tmpfile: Path):
"""Generate a new test file and diff against existing file.

Note: The timestamp in each test file creates issues with
Python difflib, so it is skipped when being prepped
for diff.

You can see this "skipping" on lines 281 & 283.
However, this rather crude method creates
an empty "false positive" diff. This empty diff is
then skipped in lines 293 & 294, so that it can be
considered a pass..
"""

try:
check_ok = True
if not tmpfile.is_file():
Expand All @@ -271,24 +284,25 @@ def check_template(slug: str, tests_path: Path, tmpfile: Path):
check_ok = False
if check_ok and not filecmp.cmp(tmpfile, tests_path):
with tests_path.open() as f:
for line in range(4):
next(f)
current_lines = f.readlines()
current_lines = f.readlines()[3:]
with tmpfile.open() as f:
for line in range(4):
next(f)
rendered_lines = f.readlines()
diff = difflib.unified_diff(
rendered_lines = f.readlines()[3:]

diff = list(difflib.unified_diff(
current_lines,
rendered_lines,
fromfile=f"[current] {tests_path.name}",
tofile=f"[generated] {tmpfile.name}",
)
logger.debug(f"{slug}: ##### DIFF START #####")
for line in diff:
logger.debug(line.strip())
logger.debug(f"{slug}: ##### DIFF END #####")
check_ok = False
lineterm="\n",
))
if not diff:
check_ok = True
else:
logger.debug(f"{slug}: ##### DIFF START #####")
for line in diff:
logger.debug(line.strip())
logger.debug(f"{slug}: ##### DIFF END #####")
check_ok = False
if not check_ok:
logger.error(
f"{slug}: check failed; tests must be regenerated with bin/generate_tests.py"
Expand Down
31 changes: 31 additions & 0 deletions config/complexnumbers_template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

import math
{{ macros.header(imports=imports, ignore=ignore) }}

{%- macro test_cases_recursive(cases) -%}
{% for case in cases -%}
{% if "cases" in case %}
# {{ case["description"] }}
{{ test_cases_recursive(case["cases"]) }}
{% else %}
{{ test_case(case) }}
{% endif -%}
{% endfor -%}
{% endmacro %}

{% if not additional_tests -%}
{%- macro additional_tests() -%}
{{ test_cases_recursive(additional_cases) }}
{% endmacro %}
{%- endif %}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{{ test_cases_recursive(cases) }}

{% if additional_cases | length -%}
# Additional tests for this track
{{ additional_tests() }}
{%- endif %}

9 changes: 0 additions & 9 deletions config/generator_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
{%- endmacro %}

{% macro header(imports=[], ignore=[]) -%}
{{ canonical_ref() }}

import unittest

Expand All @@ -38,14 +37,6 @@ from {{ exercise | to_snake }} import ({% if imports -%}
return self.assertRaisesRegex(exception, r".+")
{%- endmacro %}

{% macro footer(_has_error_case) -%}
{% if has_error_case or _has_error_case %}
{{ utility() }}
{% endif %}
if __name__ == '__main__':
unittest.main()
{%- endmacro %}

{% macro empty_set(set, list, class_name) -%}
{%- if list|length > 0 -%}
{{ set }} = {{ class_name }}({{ list }})
Expand Down
3 changes: 2 additions & 1 deletion config/master_template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header(imports=imports, ignore=ignore) }}

{%- macro test_cases_recursive(cases) -%}
Expand All @@ -25,4 +27,3 @@ class {{ exercise | camel_case }}Test(unittest.TestCase):
# Additional tests for this track
{{ additional_tests() }}
{%- endif %}
{{ macros.footer() }}
5 changes: 4 additions & 1 deletion exercises/practice/acronym/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header()}}

{% macro test_case(case) -%}
{%- set input = case["input"] -%}
Expand All @@ -8,7 +11,7 @@
"{{ case["expected"] }}"
)
{%- endmacro %}
{{ macros.header()}}


class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/acronym_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/acronym/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
5 changes: 3 additions & 2 deletions exercises/practice/affine-cipher/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header()}}

{% macro test_supercase(supercase) %}
{% for case in supercase["cases"] -%}
Expand All @@ -25,8 +28,6 @@ def test_{{ case["description"] | to_snake }}(self):
{% endif -%}
{%- endmacro %}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for supercase in cases -%}
{{ test_supercase(supercase) }}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/affine-cipher/affine_cipher_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/affine-cipher/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
5 changes: 3 additions & 2 deletions exercises/practice/all-your-base/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header()}}

{%- macro func_call(case) -%}
{{ case["property"] }}(
Expand All @@ -22,8 +25,6 @@
{%- endif %}
{% endmacro %}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases -%}
{{ test_case(case) }}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/all_your_base_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/all-your-base/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/allergies/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header(imports=[ exercise | camel_case ]) }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/allergies/allergies_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/allergies/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/alphametics/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/alphametics/alphametics_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/alphametics/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
1 change: 1 addition & 0 deletions exercises/practice/anagram/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/anagram_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/anagram/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/armstrong-numbers/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/armstrong-numbers/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/atbash-cipher/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/atbash_cipher_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/atbash-cipher/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
4 changes: 3 additions & 1 deletion exercises/practice/bank-account/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header(["BankAccount"]) }}
{% macro test_case(case) -%}
def test_{{ case["description"] | to_snake }}(self):
account = BankAccount()
Expand Down Expand Up @@ -36,7 +39,6 @@
{%- endif %}
{% endmacro %}

{{ macros.header(["BankAccount"]) }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bank-account/bank_account_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/bank-account/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
2 changes: 2 additions & 0 deletions exercises/practice/beer-song/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/beer-song/beer_song_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/beer-song/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
7 changes: 4 additions & 3 deletions exercises/practice/binary-search-tree/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{%- macro build_tree(tree_obj) -%}
{{ macros.header (imports=["BinarySearchTree", "TreeNode"]) }}

{% macro build_tree(tree_obj) %}
{%- if tree_obj is none -%}
None
{%- else -%}
Expand All @@ -25,8 +28,6 @@ TreeNode("{{ tree_obj["data"] }}",
self.{{ assertion }}(BinarySearchTree({{ tree_data }}).{{ prop | to_snake }}(),expected)
{%- endmacro -%}

{{ macros.header (imports=["BinarySearchTree", "TreeNode"]) }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{%- for case in cases %}
{%- if "cases" in case %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search-tree/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
6 changes: 4 additions & 2 deletions exercises/practice/binary-search/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}

{%- macro test_call(case) %}
{{ case["property"] }}(
{{ case["input"]["array"] }},
{{ case["input"]["value"] }}
)
{% endmacro -%}
{% endmacro %}

{{ macros.header() }}

class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases -%}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/binary-search/binary_search_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
3 changes: 3 additions & 0 deletions exercises/practice/bob/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}


class {{ exercise | camel_case }}Test(unittest.TestCase):
{% for case in cases %}
def test_{{ case["description"] | to_snake }}(self):
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/bob/bob_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/bob/canonical-data.json
# File last updated on 2023-07-16
# File last updated on 2023-07-20

import unittest

Expand Down
Loading
Loading