python-utility-scripts 0.0.21__tar.gz → 0.0.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-utility-scripts
3
- Version: 0.0.21
3
+ Version: 0.0.24
4
4
  Summary: Python utility scripts
5
5
  Home-page: https://github.com/RedHatQE/python-utility-scripts
6
6
  License: Apache-2.0
@@ -15,7 +15,7 @@ Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
- Requires-Dist: pyhelper-utils (>=0.0.21,<0.0.22)
18
+ Requires-Dist: pyhelper-utils (>=0.0.22,<0.0.23)
19
19
  Requires-Dist: pylero (>=0.1.0,<0.2.0)
20
20
  Requires-Dist: pytest-mock (>=3.14.0,<4.0.0)
21
21
  Requires-Dist: python-simple-logger (>=1.0.8,<2.0.0)
@@ -0,0 +1,66 @@
1
+ # scripts to interact with Polarion instance
2
+
3
+ ## pyutils-polarion-verify-tc-requirements
4
+ Utility to check if test cases in a pytest repository has associated Polarion requirements.
5
+
6
+ ## Requirements
7
+ This script uses [pylero](https://github.com/RedHatQE/pylero) and expects .pylero config file to be present in current directory or user's home directory.
8
+
9
+ ## Usage
10
+ ```bash
11
+ pyutils-polarion-verify-tc-requirements --help
12
+ pyutils-polarion-verify-tc-requirements --project_id <project_id> --branch <remote_branch_to_compare_to>
13
+ ```
14
+
15
+ ## Config file
16
+ To specify polation project id for polarion scripts, it can be added to the config file:
17
+ `~/.config/python-utility-scripts/config.yaml`
18
+
19
+
20
+ ### Example:
21
+
22
+ ```yaml
23
+ pyutils-polarion-verify-tc-requirements:
24
+ project_id: "<project_id>"
25
+ branch: "<remote_branch_to_compare_to>"
26
+ ```
27
+ This would run the polarion requirement check against Polarion project <project_id> and remote branch <remote_branch_to_compare_to>
28
+
29
+ To run from CLI with `--project-id` and `--branch`
30
+
31
+ ```bash
32
+ pyutils-polarion-verify-tc-requirements --project-id 'my_project_id' --branch "origin/main"
33
+ ```
34
+
35
+
36
+ ## pyutils-polarion-set-automated
37
+ Utility to mark newly added test cases in a pytest repository as approved automatically.
38
+
39
+ ## Requirements
40
+ This script uses [pylero](https://github.com/RedHatQE/pylero) and expects .pylero config file to be present in current directory or user's home directory.
41
+
42
+ ## Usage
43
+ ```bash
44
+ pyutils-polarion-set-automated --help
45
+ pyutils-polarion-set-automated --project_id <project_id> --branch <remote_branch_to_compare_to>
46
+ ```
47
+
48
+ ## Config file
49
+ To specify polation project id for polarion scripts, it can be added to the config file:
50
+ `~/.config/python-utility-scripts/config.yaml`
51
+
52
+
53
+ ### Example:
54
+
55
+ ```yaml
56
+ pyutils-polarion-set-automated:
57
+ project_id: "<project_id>"
58
+ branch: "<remote_branch_to_compare_to>"
59
+ ```
60
+ This would run the polarion requirement check against Polarion project <project_id> and remote branch <remote_branch_to_compare_to>
61
+
62
+ To run from CLI with `--project-id` and `--branch`
63
+
64
+ ```bash
65
+ pyutils-polarion-set-automated --project-id 'my_project_id' --branch "origin/main"
66
+ ```
@@ -20,12 +20,14 @@ def approve_tests(polarion_project_id: str, added_ids: List[str]) -> Dict[str, L
20
20
  )
21
21
 
22
22
 
23
- def remove_approved_tests(polarion_project_id: str, added_ids: Optional[List[str]] = None) -> Dict[str, List[str]]:
23
+ def remove_approved_tests(
24
+ polarion_project_id: str, branch: str, added_ids: Optional[List[str]] = None
25
+ ) -> Dict[str, List[str]]:
24
26
  removed_polarions = {}
25
27
  added_ids = added_ids or []
26
- if removed_ids := set(find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="removed")) - set(
27
- added_ids
28
- ):
28
+ if removed_ids := set(
29
+ find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="removed", branch=branch)
30
+ ) - set(added_ids):
29
31
  LOGGER.info(f"Following polarion ids were removed: {removed_ids}")
30
32
  removed_polarions = update_polarion_ids(
31
33
  polarion_ids=list(removed_ids), project_id=polarion_project_id, is_automated=False
@@ -42,8 +44,9 @@ def remove_approved_tests(polarion_project_id: str, added_ids: Optional[List[str
42
44
  default=os.path.expanduser("~/.config/python-utility-scripts/config.yaml"),
43
45
  )
44
46
  @click.option("--project-id", "-p", help="Provide the polarion project id")
47
+ @click.option("--branch", "-b", help="Provide the github remote branch to run against", default="origin/main")
45
48
  @click.option("--verbose", default=False, is_flag=True)
46
- def polarion_approve_automate(config_file_path: str, project_id: str, verbose: bool) -> None:
49
+ def polarion_approve_automate(config_file_path: str, project_id: str, branch: str, verbose: bool) -> None:
47
50
  if verbose:
48
51
  LOGGER.setLevel(logging.INFO)
49
52
  else:
@@ -52,11 +55,13 @@ def polarion_approve_automate(config_file_path: str, project_id: str, verbose: b
52
55
  config_file_path=config_file_path, util_name="pyutils-polarion-set-automated"
53
56
  )
54
57
  added_polarions = {}
55
- if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added"):
58
+ if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added", branch=branch):
56
59
  added_polarions = approve_tests(polarion_project_id=polarion_project_id, added_ids=added_ids)
57
60
  LOGGER.info(f"Following polarion ids were marked automated and approved: {added_polarions.get('updated')}")
58
61
 
59
- removed_polarions = remove_approved_tests(polarion_project_id=polarion_project_id, added_ids=added_ids)
62
+ removed_polarions = remove_approved_tests(
63
+ polarion_project_id=polarion_project_id, added_ids=added_ids, branch=branch
64
+ )
60
65
  if removed_polarions.get("failed") or added_polarions.get("failed"):
61
66
  error = "Following polarion ids updates failed."
62
67
  if removed_polarions.get("failed"):
@@ -15,14 +15,14 @@ NOT_AUTOMATED = "notautomated"
15
15
  APPROVED = "approved"
16
16
 
17
17
 
18
- def git_diff() -> str:
19
- data = subprocess.check_output(shlex.split("git diff HEAD^-1"))
18
+ def git_diff(branch: str) -> str:
19
+ data = subprocess.check_output(shlex.split(f"git diff {branch} HEAD"))
20
20
  return data.decode()
21
21
 
22
22
 
23
- def git_diff_lines() -> Dict[str, List[str]]:
23
+ def git_diff_lines(branch: str) -> Dict[str, List[str]]:
24
24
  diff: Dict[str, List[str]] = {}
25
- for line in git_diff().splitlines():
25
+ for line in git_diff(branch=branch).splitlines():
26
26
  LOGGER.info(line)
27
27
  if line.startswith("+"):
28
28
  diff.setdefault("added", []).append(line)
@@ -58,10 +58,10 @@ def validate_polarion_requirements(
58
58
  return tests_with_missing_requirements
59
59
 
60
60
 
61
- def find_polarion_ids(polarion_project_id: str, string_to_match: str) -> List[str]:
61
+ def find_polarion_ids(polarion_project_id: str, string_to_match: str, branch: str) -> List[str]:
62
62
  return re.findall(
63
63
  rf"pytest.mark.polarion.*({polarion_project_id}-[0-9]+)",
64
- "\n".join(git_diff_lines().get(string_to_match, [])),
64
+ "\n".join(git_diff_lines(branch=branch).get(string_to_match, [])),
65
65
  re.MULTILINE | re.IGNORECASE,
66
66
  )
67
67
 
@@ -17,8 +17,9 @@ LOGGER = get_logger(name="polarion-verify-tc-requirements")
17
17
  default=os.path.expanduser("~/.config/python-utility-scripts/config.yaml"),
18
18
  )
19
19
  @click.option("--project-id", "-p", help="Provide the polarion project id")
20
+ @click.option("--branch", "-b", help="Provide the github remote branch to run against", default="origin/main")
20
21
  @click.option("--verbose", default=False, is_flag=True)
21
- def has_verify(config_file_path: str, project_id: str, verbose: bool) -> None:
22
+ def has_verify(config_file_path: str, project_id: str, branch: str, verbose: bool) -> None:
22
23
  if verbose:
23
24
  LOGGER.setLevel(logging.INFO)
24
25
  else:
@@ -26,7 +27,7 @@ def has_verify(config_file_path: str, project_id: str, verbose: bool) -> None:
26
27
  polarion_project_id = project_id or get_polarion_project_id(
27
28
  config_file_path=config_file_path, util_name="pyutils-polarion-verify-tc-requirements"
28
29
  )
29
- if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added"):
30
+ if added_ids := find_polarion_ids(polarion_project_id=polarion_project_id, string_to_match="added", branch=branch):
30
31
  LOGGER.info(f"Checking following ids: {added_ids}")
31
32
  if tests_with_missing_requirements := validate_polarion_requirements(
32
33
  polarion_test_ids=added_ids,
@@ -29,7 +29,7 @@ exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]
29
29
 
30
30
  [tool.poetry]
31
31
  name = "python-utility-scripts"
32
- version = "0.0.21"
32
+ version = "0.0.24"
33
33
  description = "Python utility scripts"
34
34
  authors = ["dbasunag <dbasunag@redhat.com>"]
35
35
  license = "Apache License 2.0"
@@ -53,7 +53,7 @@ pyutils-polarion-set-automated = "apps.polarion.polarion_set_automated:polarion_
53
53
  python = "^3.8"
54
54
  python-simple-logger = "^1.0.8"
55
55
  pylero = "^0.1.0"
56
- pyhelper-utils = "^0.0.21"
56
+ pyhelper-utils = "^0.0.22"
57
57
  pytest-mock = "^3.14.0"
58
58
  pyyaml = "^6.0.1"
59
59
 
@@ -1,32 +0,0 @@
1
- # scripts to interact with Polarion instance
2
-
3
- ## pyutils-polarion-verify-tc-requirements
4
- Utility to check if test cases in a pytest repository has associated Polarion requirements.
5
-
6
- ## Requirements
7
- This script uses [pylero](https://github.com/RedHatQE/pylero) and expects .pylero config file to be present in current directory or user's home directory.
8
-
9
- ## Usage
10
- ```bash
11
- pyutils-polarion-verify-tc-requirements --help
12
- pyutils-polarion-verify-tc-requirements --project_id <project_id>
13
- ```
14
-
15
- ## Config file
16
- To specify polation project id for polarion scripts, it can be added to the config file:
17
- `~/.config/python-utility-scripts/config.yaml`
18
-
19
-
20
- ### Example:
21
-
22
- ```yaml
23
- pyutils-polarion-verify-tc-requirements :
24
- project_id: "<project_id>"
25
- ```
26
- This would run the polarion requirement check against Polarion project <project_id>
27
-
28
- To run from CLI with `--project-id`
29
-
30
- ```bash
31
- pyutils-polarion-verify-tc-requirements --project-id 'my_project_id'
32
- ```