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

Replace assertRaises with assertRaisesRegex #1194

Open
jayvdb opened this issue Dec 23, 2016 · 10 comments
Open

Replace assertRaises with assertRaisesRegex #1194

jayvdb opened this issue Dec 23, 2016 · 10 comments

Comments

@jayvdb
Copy link
Member

jayvdb commented Dec 23, 2016

unittest.assertRaises is always lazy, and should be avoided.
unitest.assertRaisesRegex has an extra parameter to check the exception message, and should be used instead.

It is only used in six test files:

$ git grep 'assertRaises('
tests/c_languages/ClangComplexityBearTest.py
tests/c_languages/codeclone_detection/ClangASTPrintBearTest.py
tests/c_languages/codeclone_detection/ClangCountingConditionsTest.py
tests/c_languages/codeclone_detection/CountVectorTest.py
tests/dart/DartLintBearTest.py
tests/java/CheckstyleBearTest.py

The CheckstyleBearTest case overlaps slightly with #1192

@jayvdb jayvdb changed the title Replace assertRaises with assertRaisesRegexp Replace assertRaises with assertRaisesRegex Dec 23, 2016
jayvdb added a commit to jayvdb/coala-bears that referenced this issue Dec 23, 2016
Check the AssertionError exception message.

Addresses coala#1194
jayvdb added a commit to jayvdb/coala-bears that referenced this issue Dec 23, 2016
Check the AssertionError exception message.

Addresses coala#1194
jayvdb added a commit to jayvdb/coala-bears that referenced this issue Dec 24, 2016
Check the AssertionError exception message.

Related to coala#1194
jayvdb added a commit to jayvdb/coala-bears that referenced this issue Dec 24, 2016
Check the AssertionError exception message.

Related to coala#1194
@Mixih
Copy link
Member

Mixih commented Dec 24, 2016

I'll grab this for now...

@Mixih Mixih self-assigned this Dec 24, 2016
@jayvdb
Copy link
Member Author

jayvdb commented Dec 24, 2016

@Mixih this is a GCI task.

@Makman2
Copy link
Member

Makman2 commented Dec 25, 2016

@jayvdb you can assert for the message with assertRaises:

with self.assertRaises(Exception) as cm:
    pass
    # code
self.assertEqual(str(cm.exception), 'Please use x=3 and not x=4.')

@jayvdb
Copy link
Member Author

jayvdb commented Dec 25, 2016

That isnt being done in coala-bears, and it is bad practise to use a context manager outside the with anyway.
This is a GCI task, so the write up needs to be simple, suitable for people without python knowledge even, and context managers is out.

abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
I have replaced assertRaises() with assertRaisesRegex() for the
DartLintBear script [found in tests/dart/DartLintBearTest.py].
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
I have replaced assertRaises() with assertRaisesRegex() for the
DartLintBear script [found in tests/dart/DartLintBearTest.py].
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
…x()`

I have replaced `assertRaises()` with `assertRaisesRegex()` as `assertRaises()` is always lazy.

Link to issue: coala#1194
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
I have replaced `assertRaises()` with `assertRaisesRegex()` as `assertRaises()` is always lazy.

Link to issue: coala#1194
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
I have replaced `assertRaises()` with `assertRaisesRegex()` as `assertRaises()` is always lazy.

Fixes coala#1194
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
abishekvashok added a commit to abishekvashok/coala-bears that referenced this issue Dec 26, 2016
@rultor rultor closed this as completed in c8ddbaa Dec 26, 2016
@jayvdb jayvdb reopened this Dec 26, 2016
yukiisbored added a commit to yukiisbored/coala-bears that referenced this issue Dec 27, 2016
`assertRaisesRegex` is used over `assertRaises` to validate the error
message to confirm the type of error that occured during execution.

Related to coala#1194
yukiisbored added a commit to yukiisbored/coala-bears that referenced this issue Dec 27, 2016
`assertRaisesRegex` is used over `assertRaises` to validate the error
message to confirm the type of error that occured during execution.

Related to coala#1194
yukiisbored added a commit to yukiisbored/coala-bears that referenced this issue Dec 27, 2016
`assertRaisesRegex` is used over `assertRaises` to validate the error
message to confirm the type of error that occured during execution.

Related to coala#1194
yukiisbored added a commit to yukiisbored/coala-bears that referenced this issue Dec 27, 2016
`assertRaisesRegex` is used over `assertRaises` to validate the error
message to confirm the type of error that occured during execution.

Related to coala#1194
yukiisbored added a commit to yukiisbored/coala-bears that referenced this issue Dec 27, 2016
`assertRaisesRegex` is used over `assertRaises` to validate the error
message to confirm the type of error that occured during execution.

Related to coala#1194
rhemon added a commit to rhemon/coala that referenced this issue Dec 27, 2016
Check the AssertionError exception message.

Related to coala/coala-bears#1194
@jayvdb
Copy link
Member Author

jayvdb commented Feb 28, 2017

Note that there are three left, all in clang bears. So, make sure you have clang tests working before trying to assign yourself to this task, as it is hard if the clang bear tests are being skipped.

@shreyans800755
Copy link
Contributor

shreyans800755 commented Mar 9, 2017

On running command: py.test -k c_languages
I get the the following output:

============================================================= test session starts ==============================================================
platform linux -- Python 3.4.3, pytest-3.0.6, py-1.4.32, pluggy-0.4.0
rootdir: /home/thereal/git/coala/coala-bears, inifile: setup.cfg
plugins: xdist-1.15.0, timeout-1.2.0, mock-1.5.0, env-0.6.0, cov-2.4.0
timeout: 35.0s method: signal
collected 550 items / 1 skipped

tests/c_languages/CPPCheckBearTest.py ssss
tests/c_languages/CPPCleanBearTest.py ..
tests/c_languages/CPPLintBearTest.py ......
tests/c_languages/CSecurityBearTest.py ss
tests/c_languages/CSharpLintBearTest.py s
tests/c_languages/ClangBearTest.py ssss
tests/c_languages/ClangComplexityBearTest.py ssss
tests/c_languages/GNUIndentBearTest.py ssssssssssssssss
tests/c_languages/codeclone_detection/ClangASTPrintBearTest.py ss
tests/c_languages/codeclone_detection/ClangCloneDetectionBearTest.py ssss
tests/c_languages/codeclone_detection/ClangCountVectorCreatorTest.py ss
tests/c_languages/codeclone_detection/ClangCountingConditionsTest.py sssssssssssssss
tests/c_languages/codeclone_detection/CloneDetectionRoutinesTest.py .
tests/c_languages/codeclone_detection/CountVectorTest.py .........

============================================================= 478 tests deselected =============================================================
============================================ 18 passed, 55 skipped, 478 deselected in 9.33 seconds =============================================

I've inserted the following line at ClangASTPrintBearTest.py:29
import pdb; pdb.set_trace()
But terminal is not stopping at that point and passing all the test cases. Am I missing something while testing ?
In addition, I tried removing ClangASTPrintBearTest.py:30, to get the exception from one of the following 4 lines. But didn't get any exception and all 18 test cases passed.

@Makman2
Copy link
Member

Makman2 commented Mar 10, 2017

tests/c_languages/codeclone_detection/ClangASTPrintBearTest.py ss

It's being skipped, that's why your pdb.set_trace() is never executed.

@jayvdb
Copy link
Member Author

jayvdb commented Mar 10, 2017

@shreyans800755 , See #1194 (comment) . As you do not have clang working, you should do coala/coala#3374 instead.

@shreyans800755
Copy link
Contributor

@jayvdb @Makman2
How can I fix clang problem and run the tests without skipping it ?

@jack17529
Copy link

@shreyans800755 well to skip ,you need to change the code in your own repo and run.
Only easy if you have already red the code.

Although here clang is an essential so sorry you can't remove it.
Sorry try a newcomer issue first.

twmr pushed a commit to twmr/coala that referenced this issue Jun 15, 2017
gosom pushed a commit to gosom/coala-bears that referenced this issue Jul 15, 2017
Check the AssertionError exception message.

Related to coala#1194
gosom pushed a commit to gosom/coala-bears that referenced this issue Jul 15, 2017
gosom pushed a commit to gosom/coala-bears that referenced this issue Jul 15, 2017
`assertRaisesRegex` is used over `assertRaises` to validate the error
message to confirm the type of error that occured during execution.

Related to coala#1194
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

6 participants