Skip to content

Commit

Permalink
refactor: clean up module from duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
vagabondHustler committed Jan 28, 2024
1 parent 7f96499 commit 18d956d
Showing 1 changed file with 5 additions and 56 deletions.
61 changes: 5 additions & 56 deletions tools/github_actions/cli/handlers/binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,7 @@ def end_process(psutil, process_name: str) -> None:
process.terminate()


def print_log_file(file_path):
try:
with open(file_path, "r") as log_file:
contents = log_file.read()
print(contents)
except FileNotFoundError:
print(f"The file {file_path} does not exist.")
except Exception as e:
print(f"An error occurred: {e}")


def expected_files_exists() -> None:
def print_log_file(file_path):
def _print_file_content(file_path):
try:
with open(file_path, "r") as log_file:
contents = log_file.read()
Expand All @@ -91,17 +79,13 @@ def expected_files_exists() -> None:
expected_files: list[Path] = [LOG_LOG_PATH, CONFIG_TOML_PATH]
for i in expected_files:
if not i.parent.exists():
list_files_in_directory(i.parent.parent)
list_files_in_directory(i.parent.parent)
raise FileNotFoundError(f"Directory '{i.parent}' does not exist.")
if not i.is_file():
print_log_file()
list_files_in_directory(i.parent)
print_log_file()
list_files_in_directory(i.parent)
raise FileNotFoundError(f"File '{i}' does not exist.")
print_log_file(i)
print_log_file(i)
if i.is_file():
_print_file_content(i)


def test_executable(test_length: int = 30) -> None:
Expand Down Expand Up @@ -135,9 +119,9 @@ def _get_test_result_text(result: bool) -> str:
return test_result


def _get_emojis(exe, log, cfg, key) -> tuple[str, str, str, str]:
def _get_emojis(exe, log_, cfg, key) -> tuple[str, str, str, str]:
emojis = {True: ":heavy_check_mark:", False: ":x:"}
return emojis[exe], emojis[log], emojis[cfg], emojis[key]
return emojis[exe], emojis[log_], emojis[cfg], emojis[key]


def _get_booleans_result() -> tuple[bool, bool, bool, bool]:
Expand All @@ -153,33 +137,6 @@ def _get_expected_yea_nah(name: str, yea: str, nah: str) -> tuple:
return x[name]


def _get_expected_result(name: str) -> tuple[bool, bool, bool, bool]:
x = {
"install": (True, False, False, True),
"executable": (True, True, True, True),
"uninstall": (False, True, True, False),
}
return x[name]



def _get_test_result_text(result: bool) -> str:
test_result = "Test failed"
if result:
test_result = "Test passed"
return test_result


def _get_emojis(exe, log, cfg, key) -> tuple[str, str, str, str]:
emojis = {True: ":heavy_check_mark:", False: ":x:"}
return emojis[exe], emojis[log], emojis[cfg], emojis[key]


def _get_booleans_result() -> tuple[bool, bool, bool, bool]:
return EXE_INSTALLED_PATH.is_file(), LOG_LOG_PATH.is_file(), CONFIG_TOML_PATH.is_file(), registry_key_exists()



def _get_expected_result(name: str) -> tuple[bool, bool, bool, bool]:
x = {
"install": (True, False, False, True),
Expand Down Expand Up @@ -234,14 +191,6 @@ def set_test_result(name: str) -> None:
_software_test_result(name)


def set_test_result(name: str) -> None:
header = f"| Test Stage | Exe exists | Log exists | Config exists | Registry key exists | Test result | Expected result |"
line = f"|-----------------------|------------|------------|---------------|---------------------|-------------|-----------------|"
github_actions.set_step_summary(f"{header}")
github_actions.set_step_summary(f"{line}")
_software_test_result(name)


def calculate_sha256(file_path: str) -> str:
sha256_hash = hashlib.sha256()
_file_path = Path(file_path)
Expand Down

0 comments on commit 18d956d

Please sign in to comment.