Skip to content

Commit be79419

Browse files
authored
[Resistor Color Expert]: Corrected Small Typos (exercism#3469)
* Corrected small typos around resistor bands. * Due to failing CI, alterations to the test generator script were needed. The generated vs submitted diff now skips the first three lines of the file so that the generation date is not picked up and flagged as needing regeneration. Sadly, a workaround was also needed to prevent Python difflib from noting the difference anyways and producing an empty "false positive" diff. All templates and test files also needed to be altered to ensure that the first three lines of every test file will always be the autogeneration comment and date. Hopefully, this will now stop the CI failures without creating any subtle additional bugs. * Touch up to bowling template. Added back the error raising utility. * Touch up to two-bucket template to add back in error raising utility. [no important files changed]
1 parent a093eaa commit be79419

File tree

237 files changed

+571
-330
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

237 files changed

+571
-330
lines changed

bin/generate_tests.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ def format_file(path: Path) -> NoReturn:
261261

262262

263263
def check_template(slug: str, tests_path: Path, tmpfile: Path):
264+
"""Generate a new test file and diff against existing file.
265+
266+
Note: The timestamp in each test file creates issues with
267+
Python difflib, so it is skipped when being prepped
268+
for diff.
269+
270+
You can see this "skipping" on lines 281 & 283.
271+
However, this rather crude method creates
272+
an empty "false positive" diff. This empty diff is
273+
then skipped in lines 293 & 294, so that it can be
274+
considered a pass..
275+
"""
276+
264277
try:
265278
check_ok = True
266279
if not tmpfile.is_file():
@@ -271,24 +284,25 @@ def check_template(slug: str, tests_path: Path, tmpfile: Path):
271284
check_ok = False
272285
if check_ok and not filecmp.cmp(tmpfile, tests_path):
273286
with tests_path.open() as f:
274-
for line in range(4):
275-
next(f)
276-
current_lines = f.readlines()
287+
current_lines = f.readlines()[3:]
277288
with tmpfile.open() as f:
278-
for line in range(4):
279-
next(f)
280-
rendered_lines = f.readlines()
281-
diff = difflib.unified_diff(
289+
rendered_lines = f.readlines()[3:]
290+
291+
diff = list(difflib.unified_diff(
282292
current_lines,
283293
rendered_lines,
284294
fromfile=f"[current] {tests_path.name}",
285295
tofile=f"[generated] {tmpfile.name}",
286-
)
287-
logger.debug(f"{slug}: ##### DIFF START #####")
288-
for line in diff:
289-
logger.debug(line.strip())
290-
logger.debug(f"{slug}: ##### DIFF END #####")
291-
check_ok = False
296+
lineterm="\n",
297+
))
298+
if not diff:
299+
check_ok = True
300+
else:
301+
logger.debug(f"{slug}: ##### DIFF START #####")
302+
for line in diff:
303+
logger.debug(line.strip())
304+
logger.debug(f"{slug}: ##### DIFF END #####")
305+
check_ok = False
292306
if not check_ok:
293307
logger.error(
294308
f"{slug}: check failed; tests must be regenerated with bin/generate_tests.py"

config/complexnumbers_template.j2

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
import math
5+
{{ macros.header(imports=imports, ignore=ignore) }}
6+
7+
{%- macro test_cases_recursive(cases) -%}
8+
{% for case in cases -%}
9+
{% if "cases" in case %}
10+
# {{ case["description"] }}
11+
{{ test_cases_recursive(case["cases"]) }}
12+
{% else %}
13+
{{ test_case(case) }}
14+
{% endif -%}
15+
{% endfor -%}
16+
{% endmacro %}
17+
18+
{% if not additional_tests -%}
19+
{%- macro additional_tests() -%}
20+
{{ test_cases_recursive(additional_cases) }}
21+
{% endmacro %}
22+
{%- endif %}
23+
24+
class {{ exercise | camel_case }}Test(unittest.TestCase):
25+
{{ test_cases_recursive(cases) }}
26+
27+
{% if additional_cases | length -%}
28+
# Additional tests for this track
29+
{{ additional_tests() }}
30+
{%- endif %}
31+

config/generator_macros.j2

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
{%- endmacro %}
1717

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

2120
import unittest
2221

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

41-
{% macro footer(_has_error_case) -%}
42-
{% if has_error_case or _has_error_case %}
43-
{{ utility() }}
44-
{% endif %}
45-
if __name__ == '__main__':
46-
unittest.main()
47-
{%- endmacro %}
48-
4940
{% macro empty_set(set, list, class_name) -%}
5041
{%- if list|length > 0 -%}
5142
{{ set }} = {{ class_name }}({{ list }})

config/master_template.j2

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header(imports=imports, ignore=ignore) }}
35

46
{%- macro test_cases_recursive(cases) -%}
@@ -25,4 +27,3 @@ class {{ exercise | camel_case }}Test(unittest.TestCase):
2527
# Additional tests for this track
2628
{{ additional_tests() }}
2729
{%- endif %}
28-
{{ macros.footer() }}

exercises/practice/acronym/.meta/template.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
{{ macros.header()}}
25

36
{% macro test_case(case) -%}
47
{%- set input = case["input"] -%}
@@ -8,7 +11,7 @@
811
"{{ case["expected"] }}"
912
)
1013
{%- endmacro %}
11-
{{ macros.header()}}
14+
1215

1316
class {{ exercise | camel_case }}Test(unittest.TestCase):
1417
{% for case in cases %}

exercises/practice/acronym/acronym_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/acronym/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/affine-cipher/.meta/template.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
{{ macros.header()}}
25

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

28-
{{ macros.header() }}
29-
3031
class {{ exercise | camel_case }}Test(unittest.TestCase):
3132
{% for supercase in cases -%}
3233
{{ test_supercase(supercase) }}

exercises/practice/affine-cipher/affine_cipher_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/affine-cipher/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/all-your-base/.meta/template.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
{{ macros.header()}}
25

36
{%- macro func_call(case) -%}
47
{{ case["property"] }}(
@@ -22,8 +25,6 @@
2225
{%- endif %}
2326
{% endmacro %}
2427

25-
{{ macros.header() }}
26-
2728
class {{ exercise | camel_case }}Test(unittest.TestCase):
2829
{% for case in cases -%}
2930
{{ test_case(case) }}

exercises/practice/all-your-base/all_your_base_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/all-your-base/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/allergies/.meta/template.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header(imports=[ exercise | camel_case ]) }}
35

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

exercises/practice/allergies/allergies_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/allergies/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/alphametics/.meta/template.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header() }}
35

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

exercises/practice/alphametics/alphametics_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/alphametics/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/anagram/.meta/template.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
23

34
{{ macros.header() }}
45

exercises/practice/anagram/anagram_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/anagram/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/armstrong-numbers/.meta/template.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header() }}
35

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

exercises/practice/armstrong-numbers/armstrong_numbers_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/armstrong-numbers/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/atbash-cipher/.meta/template.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header() }}
35

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

exercises/practice/atbash-cipher/atbash_cipher_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/atbash-cipher/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/bank-account/.meta/template.j2

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
{{ macros.header(["BankAccount"]) }}
25
{% macro test_case(case) -%}
36
def test_{{ case["description"] | to_snake }}(self):
47
account = BankAccount()
@@ -36,7 +39,6 @@
3639
{%- endif %}
3740
{% endmacro %}
3841

39-
{{ macros.header(["BankAccount"]) }}
4042

4143
class {{ exercise | camel_case }}Test(unittest.TestCase):
4244
{% for case in cases -%}

exercises/practice/bank-account/bank_account_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/bank-account/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/beer-song/.meta/template.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header() }}
35

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

exercises/practice/beer-song/beer_song_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/beer-song/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/binary-search-tree/.meta/template.j2

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
23

3-
{%- macro build_tree(tree_obj) -%}
4+
{{ macros.header (imports=["BinarySearchTree", "TreeNode"]) }}
5+
6+
{% macro build_tree(tree_obj) %}
47
{%- if tree_obj is none -%}
58
None
69
{%- else -%}
@@ -25,8 +28,6 @@ TreeNode("{{ tree_obj["data"] }}",
2528
self.{{ assertion }}(BinarySearchTree({{ tree_data }}).{{ prop | to_snake }}(),expected)
2629
{%- endmacro -%}
2730

28-
{{ macros.header (imports=["BinarySearchTree", "TreeNode"]) }}
29-
3031
class {{ exercise | camel_case }}Test(unittest.TestCase):
3132
{%- for case in cases %}
3233
{%- if "cases" in case %}

exercises/practice/binary-search-tree/binary_search_tree_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search-tree/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/binary-search/.meta/template.j2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
4+
{{ macros.header() }}
25

36
{%- macro test_call(case) %}
47
{{ case["property"] }}(
58
{{ case["input"]["array"] }},
69
{{ case["input"]["value"] }}
710
)
8-
{% endmacro -%}
11+
{% endmacro %}
912

10-
{{ macros.header() }}
1113

1214
class {{ exercise | camel_case }}Test(unittest.TestCase):
1315
{% for case in cases -%}

exercises/practice/binary-search/binary_search_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

exercises/practice/bob/.meta/template.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{%- import "generator_macros.j2" as macros with context -%}
2+
{{ macros.canonical_ref() }}
3+
24
{{ macros.header() }}
35

6+
47
class {{ exercise | camel_case }}Test(unittest.TestCase):
58
{% for case in cases %}
69
def test_{{ case["description"] | to_snake }}(self):

exercises/practice/bob/bob_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These tests are auto-generated with test data from:
22
# https://github.com/exercism/problem-specifications/tree/main/exercises/bob/canonical-data.json
3-
# File last updated on 2023-07-16
3+
# File last updated on 2023-07-20
44

55
import unittest
66

0 commit comments

Comments
 (0)