Skip to content

Commit

Permalink
Using the pathlib module to handle file paths enhances the readabilit…
Browse files Browse the repository at this point in the history
…y and maintainability of the code

Signed-off-by: mataotao <[email protected]>
  • Loading branch information
mataotao committed Jun 27, 2024
1 parent 1051bc0 commit 6c660eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
24 changes: 12 additions & 12 deletions avocado/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ def check_test(self, state):
:param test: A dict with test internal state
"""
status = state.get("status")
status_mapping = {
"PASS": "passed",
"SKIP": "skipped",
"FAIL": "failed",
"WARN": "warned",
"INTERRUPTED": "interrupted",
"CANCEL": "cancelled",
}
if status in status_mapping:
setattr(
self, status_mapping[status], getattr(self, status_mapping[status]) + 1
)
if status == "PASS":
self.passed += 1
elif status == "SKIP":
self.skipped += 1
elif status == "FAIL":
self.failed += 1
elif status == "WARN":
self.warned += 1
elif status == "INTERRUPTED":
self.interrupted += 1
elif status == "CANCEL":
self.cancelled += 1
else:
self.errors += 1
self.end_test(state)
Expand Down
13 changes: 10 additions & 3 deletions avocado/utils/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import logging
import operator
import os
import pathlib
import re
import shutil
import stat
Expand Down Expand Up @@ -684,9 +685,15 @@ def remove_asset_by_path(cls, asset_path):
:param asset_path: full path of the asset file.
"""
os.remove(asset_path)
filename = f"{asset_path}-CHECKSUM"
os.remove(filename)
try:
file_path = pathlib.Path(asset_path)
file_path.unlink()
checksum_path = pathlib.Path(f"{asset_path}-CHECKSUM")
checksum_path.unlink()
except FileNotFoundError:
LOG.error(f"File not found: {asset_path} or its checksum file.")
except Exception as e:
LOG.error(f"An error occurred while removing files: {e}")

@property
def urls(self):
Expand Down

0 comments on commit 6c660eb

Please sign in to comment.