Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add example of using custom assertions #6

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

Merged
merged 6 commits into from
Jun 12, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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` 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)
```