From 4499fe01ba0d9f200da4943ff9b56a84be5185b4 Mon Sep 17 00:00:00 2001 From: ggorlen <17895165+ggorlen@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:35:05 -0700 Subject: [PATCH 1/5] add example of custom assertions --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 942f76f..4314b07 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,52 @@ # Codewars Test Framework for Python - -## Example +## Basic Example ```python -from solution import add import codewars_test as test +from solution import add @test.describe('Example Tests') def example_tests(): + @test.it('Example Test Case') def example_test_case(): test.assert_equals(add(1, 1), 2, 'Optional Message on Failure') ``` + +## Using Other Assertions + +Any function that raises an `AssertionError` upon a failed assertion can be used instead of `codewars_test` assertions: + +```python +import numpy as np +import pandas as pd +import codewars_test as test + +@test.describe('Example Tests') +def test_custom_assertions(): + + @test.it('Test something in numpy') + def test_numpy_assertion(): + actual = np.reshape(range(16), [4, 4]) + expected = np.reshape(range(16, 0, -1), [4, 4]) + np.testing.assert_equal(expected, actual) + + @test.it('Test something in pandas') + def test_pandas_assertion(): + actual = pd.DataFrame({'foo': [1, 2, 3]}) + expected = pd.DataFrame({'foo': [1, 42, 3]}) + pd.testing.assert_frame_equal(expected, actual) + + @test.it('Test something using a custom assertion') + def test_custom_assertion(): + def custom_assert_eq(actual, expected, msg=None): + if actual != expected: + default_msg = f"`{actual}` did not equal expected `{expected}`" + raise AssertionError(default_msg if msg is None else msg) + + actual = 2 + expected = 1 + custom_assert_eq(actual, expected) +``` + From 73eee3446319b041466024d136d73f055d547d00 Mon Sep 17 00:00:00 2001 From: ggorlen <17895165+ggorlen@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:36:36 -0700 Subject: [PATCH 2/5] add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..58200d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ From 934bd53c704887f2f12cd6da1876c137b7b112fb Mon Sep 17 00:00:00 2001 From: ggorlen <17895165+ggorlen@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:37:40 -0700 Subject: [PATCH 3/5] quote adjustment for consistency --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4314b07..75f6c6b 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ def test_custom_assertions(): def test_custom_assertion(): def custom_assert_eq(actual, expected, msg=None): if actual != expected: - default_msg = f"`{actual}` did not equal expected `{expected}`" + default_msg = f'`{actual}` did not equal expected `{expected}`' raise AssertionError(default_msg if msg is None else msg) actual = 2 From 9b77819598ae58abc2b38cbbdea7392b5ddd7a62 Mon Sep 17 00:00:00 2001 From: ggorlen <17895165+ggorlen@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:43:52 -0700 Subject: [PATCH 4/5] h2 to h3 for headers --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75f6c6b..735ff0a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Codewars Test Framework for Python -## Basic Example +### Basic Example ```python import codewars_test as test @@ -14,7 +14,7 @@ def example_tests(): test.assert_equals(add(1, 1), 2, 'Optional Message on Failure') ``` -## Using Other Assertions +### Using Other Assertions Any function that raises an `AssertionError` upon a failed assertion can be used instead of `codewars_test` assertions: From 5f266c79a54e5aa67d4f9f52fe9aa81b1539a1ba Mon Sep 17 00:00:00 2001 From: ggorlen <17895165+ggorlen@users.noreply.github.com> Date: Thu, 11 Jun 2020 22:44:42 -0700 Subject: [PATCH 5/5] simplify language --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 735ff0a..7fdd592 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ def example_tests(): ### Using Other Assertions -Any function that raises an `AssertionError` upon a failed assertion can be used instead of `codewars_test` assertions: +Any function that raises an `AssertionError` can be used instead of `codewars_test` assertions: ```python import numpy as np