-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
[MRG] Backports msg in assert_raises and assert_raises_regex #9536
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
Conversation
|
After having a look at the error log, which states |
| return isinstance(expected, type) and issubclass(expected, basetype) | ||
|
|
||
|
|
||
| class _AssertRaisesContext(_AssertRaisesBaseContext): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we basically just want this (perhaps with some changes for compatibility), and nothing else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll remove all the unnecessary packages once I am sure the whole works. I am getting ImportError on writing import sklearn.utils.modifiedunittest . Please help me in importing it correctly. I'll remove the extra code here.
|
So, now I realise that we don't need to import the modules and all. We can just copy paste the codes in |
|
I guess now we have the minimum amount of code in |
|
many commits is not a problem. I'll try look soon
…On 14 Aug 2017 6:59 am, "Kumar Ashutosh" ***@***.***> wrote:
I guess now we have the minimum amount of code in sklearn.utils.testing.py.
The extra module added is removed. Hope this works fine.
Sorry for so many commits.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#9536 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz64ahlMLxhQ7e0s6KoPcW_idl4Kxjks5sX2O-gaJpZM4O1YVM>
.
|
|
@jnothman Does it work or there's something more to be done here? |
sklearn/utils/testing.py
Outdated
| "assert_approx_equal", "SkipTest"] | ||
|
|
||
|
|
||
| def _is_subtype(expected, basetype): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to put this in a separate file like _unittest_backport.py or something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll make a new file for this.
|
I think we should have a small test for this. |
|
Is the backport implementation working? I wanted to know this. :) |
|
I think I need some help in making the test functions. |
jnothman
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
I don't think TestLongMessage is testing assertRaises.
| @@ -0,0 +1,173 @@ | |||
| import re | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have attribution to where it is backported from (and the copyright notice)
sklearn/utils/_unittest_backport.py
Outdated
| return True | ||
|
|
||
|
|
||
| class TestCase_new(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you inherit from unittest.TestCase you can use this alone as the dummy, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this? class TestCase_new(unittest.TestCase):. And then we can remove the redundant functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This somehow gives error. It says ValueError: no such test method in <class 'TestCase_new'>: runTest . I looked for the error in StackOverflow and found this: https://stackoverflow.com/questions/2090479/valueerror-no-such-test-method-in-class-myapp-tests-sessiontestcase-runtes but could not make use of it. Can you suggest me how to achieve this?
|
to test you want something like: |
|
@jnothman Okay, so I was under the impression that I have to add tests for the functions in |
|
Yes, you won't get good codecov coverage. That's okay for a backport.
…On 16 August 2017 at 12:59, Kumar Ashutosh ***@***.***> wrote:
@jnothman <https://github.com/jnothman> Okay, so I was under the
impression that I have to add tests for the functions in
_unittest_backport.py and not for assert_raises . If only I add tests for
assert_raises_with_msg, the codecov/patch will still fail, isn't it?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#9536 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz61VbBbmWBS2njUIXsHYQlCHgcaeDks5sYlssgaJpZM4O1YVM>
.
|
sklearn/utils/_unittest_backport.py
Outdated
| return True | ||
|
|
||
|
|
||
| class TestCase_new(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could just call the new class TestCase. Certainly, it shouldn't have an underscore in a class name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I'll do that. somehow I am not able to use a single dummy variable, initializing unittest.Test case('init') inside new TestCase gives an error saying the 'init' function take 2 arguments, 4 given. Please look into it
|
So, I have made all the changes suggested so far, added |
|
LGTM |
|
LGTM, thanks! |
|
Thanks a lot, this was a very good learning experience, will continue to contribute :) |
|
Glad to hear it!
…On 17 August 2017 at 19:25, Kumar Ashutosh ***@***.***> wrote:
Thanks a lot, this was a very good learning experience, will continue to
contribute :)
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#9536 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEz6_m4L9GuyFfLeWyV8D_D8kJiS03Zks5sZAcYgaJpZM4O1YVM>
.
|
…learn#9536) * Added modifiedunittest * Backports msg in assertRaises and assertRaisesRegexp * Import statement corrected * Corrected import statement * Added module name in utils.setup.py * Removed Extra modules * Reordered class * _is_subtype added * Missing import added * _formatMessage added * missing variables added * Remove PEP8 failures * Removed safe_repr * _unittest_backport.py added * Import statement corrected * Added copyright * Syntax Error removed * Error removed * runTest function added * Tests added * __init__ added * Import added
…learn#9536) * Added modifiedunittest * Backports msg in assertRaises and assertRaisesRegexp * Import statement corrected * Corrected import statement * Added module name in utils.setup.py * Removed Extra modules * Reordered class * _is_subtype added * Missing import added * _formatMessage added * missing variables added * Remove PEP8 failures * Removed safe_repr * _unittest_backport.py added * Import statement corrected * Added copyright * Syntax Error removed * Error removed * runTest function added * Tests added * __init__ added * Import added
…learn#9536) * Added modifiedunittest * Backports msg in assertRaises and assertRaisesRegexp * Import statement corrected * Corrected import statement * Added module name in utils.setup.py * Removed Extra modules * Reordered class * _is_subtype added * Missing import added * _formatMessage added * missing variables added * Remove PEP8 failures * Removed safe_repr * _unittest_backport.py added * Import statement corrected * Added copyright * Syntax Error removed * Error removed * runTest function added * Tests added * __init__ added * Import added
…learn#9536) * Added modifiedunittest * Backports msg in assertRaises and assertRaisesRegexp * Import statement corrected * Corrected import statement * Added module name in utils.setup.py * Removed Extra modules * Reordered class * _is_subtype added * Missing import added * _formatMessage added * missing variables added * Remove PEP8 failures * Removed safe_repr * _unittest_backport.py added * Import statement corrected * Added copyright * Syntax Error removed * Error removed * runTest function added * Tests added * __init__ added * Import added
Reference Issue
Fixes #9454
What does this implement/fix? Explain your changes.
I added a new directory named
modifiedunittestwhich backportsmsg.Any other comments?
Thanks