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

Test fails if any VENDOR_PRODUCT pair in checker is not lowercase #1032

Merged
merged 6 commits into from
Jan 27, 2021

Conversation

chaitanyamogal
Copy link
Contributor

The test fails when the VENDOR_PRODUCT pairs provided is not lowercase. ( #987 )

The test fails when the `VENDOR_PRODUCT` pair provided is not lowercase. ( intel#987 )
@codecov-io
Copy link

codecov-io commented Jan 21, 2021

Codecov Report

Merging #1032 (c4d86c0) into master (4cad69b) will decrease coverage by 0.78%.
The diff coverage is 71.42%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1032      +/-   ##
==========================================
- Coverage   87.25%   86.47%   -0.79%     
==========================================
  Files         169      169              
  Lines        2895     2942      +47     
  Branches      321      331      +10     
==========================================
+ Hits         2526     2544      +18     
- Misses        290      316      +26     
- Partials       79       82       +3     
Flag Coverage Δ
longtests 86.47% <71.42%> (-0.79%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cve_bin_tool/checkers/__init__.py 95.45% <66.66%> (-4.55%) ⬇️
cve_bin_tool/error_handler.py 87.71% <100.00%> (+0.21%) ⬆️
test/test_scanner.py 74.21% <0.00%> (-16.80%) ⬇️
cve_bin_tool/version_scanner.py 82.20% <0.00%> (-1.42%) ⬇️
test/test_cli.py 93.06% <0.00%> (ø)
test/test_file.py 100.00% <0.00%> (ø)
test/test_json.py 89.65% <0.00%> (ø)
test/test_cvedb.py 100.00% <0.00%> (ø)
cve_bin_tool/cli.py 86.02% <0.00%> (ø)
test/test_strings.py 100.00% <0.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cad69b...c4d86c0. Read the comment docs.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Good start!

for items in cls.VENDOR_PRODUCT:
for vp in items:
if vp.islower() != True:
raise AssertionError(
Copy link
Contributor

Choose a reason for hiding this comment

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

Mostly we log errors but don't fail in cve-bin-tool, but the use case for this is "developer added new checker that has a flaw" so we probably do want to halt with an error. So I think raising an error is correct, but assertions in python are a bit of a problem (they get optimized out of production code, so they're used sparingly in test code only) so it probably shouldn't be AssertionError that's raised.

I think in other places we've made our own errors, so probably you want to make something like InvalidCheckerError and raise that instead. Take a look at https://github.com/intel/cve-bin-tool/blob/master/cve_bin_tool/error_handler.py to see what the others look like, and probably add it there.

for vp in items:
if vp.islower() != True:
raise AssertionError(
"Checker %s has a VENDOR_PRODUCT string that is not lowercase"
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use fstrings here. (In case you missed it, here's where we ask for fstrings in the style guide: https://cve-bin-tool.readthedocs.io/en/latest/CONTRIBUTORS.html#style-guide-for-cve-bin-tool )

@chaitanyamogal
Copy link
Contributor Author

Hey, @terriko I have done all changes as you suggested. Please review it.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Almost there!

@@ -140,6 +144,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
SystemExit: -2,
FileNotFoundError: -3,
InvalidCsvError: -4,
InvalidCheckerError: -4,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably want InvalidCheckerError to have its own number, so I guess -16 ? InvalidCsvError and InvalidJsonError have the same number presumably because they're very similar parsing errors, but there's no particular reason not to give every error a separate number.

@@ -2,6 +2,7 @@
import collections
import re

from ..error_handler import InvalidCheckerError
Copy link
Contributor

Choose a reason for hiding this comment

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

We're trying to move away from using relative imports, so this should be cve_bin_tool.error_handler (and it would be great if you could fix the one below as well, which should be cve_bin_tool.util instead of ..util)

@chaitanyamogal
Copy link
Contributor Author

chaitanyamogal commented Jan 26, 2021

@terriko It's done. close #987

And should I fix relative imports in other files too.

Copy link
Contributor

@terriko terriko left a comment

Choose a reason for hiding this comment

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

Thank you so much for working to make this really great!

@terriko
Copy link
Contributor

terriko commented Jan 27, 2021

And sure, if you spot relative imports go ahead and fix them. There's probably a few left.

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