Skip to content

Commit

Permalink
chore: adds additional type hints to tests and trestlebot pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jun 26, 2023
1 parent 360e4e6 commit 93f4fc7
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests/trestlebot/tasks/authored/test_ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
markdown_dir = "md_ssp"


def test_assemble(tmp_trestle_dir) -> None:
def test_assemble(tmp_trestle_dir: str) -> None:
"""Test to test assemble functionality for SSPs"""
# Prepare the workspace and generate the markdown
trestle_root = pathlib.Path(tmp_trestle_dir)
Expand All @@ -59,7 +59,7 @@ def test_assemble(tmp_trestle_dir) -> None:
assert len(ssp.control_implementation.implemented_requirements) == 12


def test_assemble_no_ssp_entry(tmp_trestle_dir) -> None:
def test_assemble_no_ssp_entry(tmp_trestle_dir: str) -> None:
"""Test to test assemble functionality for SSPs"""
# Prepare the workspace and generate the markdown
trestle_root = pathlib.Path(tmp_trestle_dir)
Expand Down
10 changes: 5 additions & 5 deletions tests/trestlebot/tasks/test_assemble_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
ssp_md_dir = "md_ssp"


def test_catalog_assemble_task(tmp_trestle_dir):
def test_catalog_assemble_task(tmp_trestle_dir: str) -> None:
"""Test catalog assemble at the task level"""
trestle_root = pathlib.Path(tmp_trestle_dir)
md_path = os.path.join(cat_md_dir, test_cat)
Expand All @@ -58,7 +58,7 @@ def test_catalog_assemble_task(tmp_trestle_dir):
assert assemble_task.execute() == 0


def test_profile_assemble_task(tmp_trestle_dir):
def test_profile_assemble_task(tmp_trestle_dir: str) -> None:
"""Test profile assemble at the task level"""
trestle_root = pathlib.Path(tmp_trestle_dir)
md_path = os.path.join(prof_md_dir, test_prof)
Expand All @@ -74,7 +74,7 @@ def test_profile_assemble_task(tmp_trestle_dir):
assert assemble_task.execute() == 0


def test_compdef_assemble_task(tmp_trestle_dir):
def test_compdef_assemble_task(tmp_trestle_dir: str) -> None:
"""Test compdef assemble at the task level"""
trestle_root = pathlib.Path(tmp_trestle_dir)
md_path = os.path.join(compdef_md_dir, test_comp)
Expand All @@ -90,7 +90,7 @@ def test_compdef_assemble_task(tmp_trestle_dir):
assert assemble_task.execute() == 0


def test_ssp_assemble_task(tmp_trestle_dir):
def test_ssp_assemble_task(tmp_trestle_dir: str) -> None:
"""Test ssp assemble at the task level"""
ssp_index_path = os.path.join(tmp_trestle_dir, "ssp-index.txt")
with open(ssp_index_path, "w") as f:
Expand All @@ -111,7 +111,7 @@ def test_ssp_assemble_task(tmp_trestle_dir):
assert assemble_task.execute() == 0


def test_ssp_assemble_task_no_index_path(tmp_trestle_dir):
def test_ssp_assemble_task_no_index_path(tmp_trestle_dir: str) -> None:
"""Test ssp assemble at the task level with failure"""
ssp_index_path = os.path.join(tmp_trestle_dir, "ssp-index.txt")
with open(ssp_index_path, "w") as f:
Expand Down
13 changes: 8 additions & 5 deletions tests/trestlebot/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
"""Test for top-level Trestle Bot logic."""

import os
from typing import Tuple

from git.repo import Repo

import trestlebot.bot as bot
from tests.testutils import clean


def test_stage_files(tmp_repo) -> None:
def test_stage_files(tmp_repo: Tuple[str, Repo]) -> None:
repo_path, repo = tmp_repo

# Create test files
Expand All @@ -44,7 +47,7 @@ def test_stage_files(tmp_repo) -> None:
clean(repo_path, repo)


def test_local_commit(tmp_repo) -> None:
def test_local_commit(tmp_repo: Tuple[str, Repo]) -> None:
repo_path, repo = tmp_repo

# Create a test file
Expand Down Expand Up @@ -74,7 +77,7 @@ def test_local_commit(tmp_repo) -> None:
clean(repo_path, repo)


def test_local_commit_with_committer(tmp_repo) -> None:
def test_local_commit_with_committer(tmp_repo: Tuple[str, Repo]) -> None:
repo_path, repo = tmp_repo

# Create a test file
Expand Down Expand Up @@ -104,7 +107,7 @@ def test_local_commit_with_committer(tmp_repo) -> None:
clean(repo_path, repo)


def test_local_commit_with_author(tmp_repo) -> None:
def test_local_commit_with_author(tmp_repo: Tuple[str, Repo]) -> None:
repo_path, repo = tmp_repo

# Create a test file
Expand Down Expand Up @@ -136,7 +139,7 @@ def test_local_commit_with_author(tmp_repo) -> None:
clean(repo_path, repo)


def test_run_dry_run(tmp_repo) -> None:
def test_run_dry_run(tmp_repo: Tuple[str, Repo]) -> None:
repo_path, repo = tmp_repo

# Create a test file
Expand Down
6 changes: 3 additions & 3 deletions trestlebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class RepoException(Exception):
"""


def _stage_files(gitwd: Repo, patterns: List[str]):
def _stage_files(gitwd: Repo, patterns: List[str]) -> None:
"""Stages files in git based on file patterns"""
for pattern in patterns:
logging.info(f"Adding file for pattern {pattern}")
Expand All @@ -52,7 +52,7 @@ def _local_commit(
commit_message: str,
author_name: str = "",
author_email: str = "",
):
) -> None:
"""Creates a local commit in git working directory"""
try:
# Set the user and email for the commit
Expand Down Expand Up @@ -121,7 +121,7 @@ def run(
remote.push(refspec=f"HEAD:{branch}")

logging.info(f"Changes pushed to {branch} successfully.")
return True
return 0

except GitCommandError as e:
raise RepoException(f"Git push to {branch} failed: {e}") from e
Expand Down
2 changes: 1 addition & 1 deletion trestlebot/tasks/authored/ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, trestle_root: str, comps_by_ssp: Dict[str, str]) -> None:
self.comps_by_ssp = comps_by_ssp

def assemble(self, model_path: str, version_tag: str = "") -> None:
ssp_assemble = SSPAssemble()
ssp_assemble: SSPAssemble = SSPAssemble()
ssp = os.path.basename(model_path)

try:
Expand Down
6 changes: 3 additions & 3 deletions trestlebot/tasks/authored/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class AuthoredType(Enum):
COMPDEF = "compdef"


def check_authored_type(string):
def check_authored_type(input_type: str) -> AuthoredType:
"""Check if the string has a matching AuthoredType, if not raise an error"""
try:
item_type = AuthoredType[string.upper()]
item_type = AuthoredType[input_type.upper()]
return item_type
except KeyError:
raise ValueError(f"Invalid item type: {string}")
raise ValueError(f"Invalid item type: {input_type}")

0 comments on commit 93f4fc7

Please sign in to comment.