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

Modernized and update test.py #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Lokeshsri11
Copy link

@Lokeshsri11 Lokeshsri11 commented May 9, 2023

The changes made to the code are:

  • Added a check to ensure that the needledir directory exists before attempting to read its contents. This is done using the os.path.exists() function.
  • Removed the use of the global keyword for the returncode variable and instead passed it as an argument to the error() function.
  • Simplified the code that checks for the existence of JSON and PNG files for each needle. Instead of using multiple if statements, a single if statement is used with the continue keyword to skip to the next iteration of the loop if the JSON file does not exist.
  • Replaced the regular expression used to extract the timestamp from the needle name with the str.split() method. This method splits a string at a specified separator and returns a list of the resulting substrings.

The changes made to the code are:

- Added a check to ensure that the `needledir` directory exists before attempting to read its contents. This is done using the `os.path.exists()` function.
Removed the use of the `global` keyword for the `returncode` variable and instead passed it as an argument to the `error()` function.
Simplified the code that checks for the existence of JSON and PNG files for each needle. Instead of using multiple `if` statements, a single `if` statement is used with the `continue` keyword to skip to the next iteration of the loop if the JSON file does not exist.
Replaced the regular expression used to extract the timestamp from the needle name with the `str.split()` method. This method splits a string at a specified separator and returns a list of the resulting substrings.
@Lokeshsri11
Copy link
Author

Hey @asdil12 please review it

error("Needle '{}' includes a workaround tag but has no reason in json file!".format(needle))
break
properties = n.get('properties', [])
if properties is not None:
Copy link
Member

Choose a reason for hiding this comment

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

This should never evaluate to false, as the .get() method returns a default of [] here.

workaround_found = True
break
if not workaround_found:
error(f"Needle '{needle}' includes a workaround tag but has no bug-ID in filename or reason in json file!")
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer the old approach of individual messages.
No reason to summarize two different issues.
Let's let the user know exactly, what they did wrong.

@@ -1,12 +1,10 @@
#!/usr/bin/python3
Copy link
Member

Choose a reason for hiding this comment

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

Please leave the shebang - the script won't work otherwise.


# Check if name contains timestamp
timestamp = re.sub(r"_.*$", '', re.sub(r"[_-][0-9]{1,2}$", '', needle).split("-")[-1])
Copy link
Member

Choose a reason for hiding this comment

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

IIRC this regex was used to replace suffixes, that would remain in your simpler approach.
Eg if a needle was called foo-20201231-01 or foo-20201231_bar, the simpler approach would fail.
Do you have a reason to expect that we won't have needles anymore with such names?

import os
import sys
import re
import json

scriptdir = os.path.dirname(os.path.realpath(__file__))
needledir = os.path.join(scriptdir, "..")
needledir = os.path.abspath(os.path.join(scriptdir, ".."))
Copy link
Member

Choose a reason for hiding this comment

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

Why is abspath needed here?

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.

2 participants