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

PYSCAN-4: Add tests for environment #5

Merged
merged 6 commits into from
Dec 12, 2023
Merged

PYSCAN-4: Add tests for environment #5

merged 6 commits into from
Dec 12, 2023

Conversation

joke1196
Copy link
Contributor

@joke1196 joke1196 commented Dec 8, 2023

No description provided.

log.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.terminator = ""
log.addHandler(handler)
Copy link
Contributor Author

@joke1196 joke1196 Dec 11, 2023

Choose a reason for hiding this comment

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

I have added a ticket to use this logger in other parts of the application. i.e the scanner

@joke1196
Copy link
Contributor Author

I didn't think it was strictly necessary to test all the other functions _unzip_binaries _write_binaries and _change_permissions_recursive. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good overall, left some questions.
Minor feedback: the ordering of commits did not help with the review here: first commit uses the ApplicationLogger which is introduced in the second commit. also, it would have been nice to have the formatting changes in a separate commits from the actual changes.

@@ -17,67 +17,90 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
from logging import Logger

Choose a reason for hiding this comment

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

This import is unused following the introduction of ApplicationLogger.

with open(destination, "wb") as output:
output.write(scanner_res.read())

def _unzip_binaries(self, scanner_zip_path: str, destination: str):

Choose a reason for hiding this comment

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

Should we consider making turning these simple methods into functions, as they don't really use anything from the class? (I guess that would make us revisit the way the logger works as well though - not sure about that).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the last two methods to a utils file. But not the _download_scanner_binraies as it is still too strongly linked to the environment. I created a ticket so that we do not forget.

from logging import Logger
from typing import Optional

class ApplicationLogger():

Choose a reason for hiding this comment

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

Just so I understand, the point of having this class is to wrap a single logging logger associated with main in the whole application?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, exactly this was so that the main configuration would be the same everywhere.

def _setup_logger(log: Logger):
log.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.terminator = ""

Choose a reason for hiding this comment

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

Why do we need to set terminators to ""? Is is to ensure this can run into multiple environments? Aren't the newlines needed to prevent logs from being merged together in a single line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When processing the logs from SonarScanner we would need to set this terminator in order to not have blank lines for each line of logs. we had to do it already when using print. #4 . Now I am thinking if there could be a way the logs would get merged together if they are not flushed directly. Not sure yet.

Choose a reason for hiding this comment

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

Thanks for clarifying. So indeed when dealing with logs from the wrapped scanner, they already contain the newline token and we should make sure to not add it again? But when we produce our own, we should still have one?
Anyway, I guess we can add the proper testing for the various scenarios when implementing PYSCAN-28.

Copy link
Contributor

@jdodinh jdodinh left a comment

Choose a reason for hiding this comment

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

LGTM! I don't have much to say here, except to thank you for providing such good examples based on which I can get inspired.

@@ -20,7 +20,8 @@ classifiers = [
]

dependencies = [
"toml>=0.10.2",
"toml>=0.10.2",
"pyfiglet"
Copy link
Contributor

Choose a reason for hiding this comment

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

lol ;)

@joke1196
Copy link
Contributor Author

Sorry about this mix-up in the commit history I am not sure what I did here but it is certainly wrong.

@joke1196
Copy link
Contributor Author

joke1196 commented Dec 12, 2023

LGTM! I don't have much to say here, except to thank you for providing such good examples based on which I can get inspired.

You are welcome, just don't get inspired by my commit history :).

@joke1196 joke1196 merged commit 1c1deca into master Dec 12, 2023
@joke1196 joke1196 deleted the DAVID/PYSCAN-4 branch December 12, 2023 13:30
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