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

handle and display AssertionErrors #5

Merged
merged 1 commit into from
Jun 12, 2020

Conversation

ggorlen
Copy link
Contributor

@ggorlen ggorlen commented Jun 12, 2020

This allows frameworks like numpy to raise AssertionErrors which can be handled in a similar way to in-suite assertion errors.

import numpy as np
import test_framework as test

@test.describe('Example Tests')
def example_tests():
    @test.it('Example Test Case')
    def example_test_case():
        actual = np.reshape(range(16), [4, 4])
        expected = np.reshape(range(1, 17), [4, 4])
        np.testing.assert_equal(expected, actual)

which produces:

<DESCRIBE::>Example Tests

<IT::>Example Test Case

<FAILED::><:LF:>Arrays are not equal<:LF:><:LF:>Mismatched elements: 16 / 16 (100%)<:LF:>Max absolute difference: 1<:LF:>Max relative difference: 1.<:LF:> x: array([[ 1,  2,  3,  4],<:LF:>       [ 5,  6,  7,  8],<:LF:>       [ 9, 10, 11, 12],<:LF:>       [13, 14, 15, 16]])<:LF:> y: array([[ 0,  1,  2,  3],<:LF:>       [ 4,  5,  6,  7],<:LF:>       [ 8,  9, 10, 11],<:LF:>       [12, 13, 14, 15]])

<COMPLETEDIN::>281.39

<COMPLETEDIN::>287.13

Copy link
Member

@kazk kazk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!
image

Thanks, Greg!

@kazk kazk merged commit e5a0195 into codewars:master Jun 12, 2020
@kazk
Copy link
Member

kazk commented Jun 17, 2020

This is deployed but we can't use it yet because I forgot that we need to output something when it doesn't throw. So currently the failure works, but it marks the successful test as failed because it doesn't contain <PASSED::>.

I'll take a look and hopefully open a PR soon.

@ggorlen
Copy link
Contributor Author

ggorlen commented Jun 17, 2020

I knew it seemed too easy! I'll also take a look today, thanks for the catch.

@Blind4Basics
Copy link
Contributor

that would require to decorate all numpy assertions after the import, no?

@kazk
Copy link
Member

kazk commented Jul 8, 2020

It raises AssertionError so the failure is reported correctly. We need to report something when no AssertionError is raised.

See comments on #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants