Skip to content

Commit

Permalink
test: formats test_ssp.py and adds test for check_only in bot.run
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jun 30, 2023
1 parent 68cedab commit fe0a9ee
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[flake8]
max-line-length=100
max-line-length=105
8 changes: 6 additions & 2 deletions tests/trestlebot/tasks/authored/test_ssp.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def test_assemble_no_ssp_entry(tmp_trestle_dir: str) -> None:

authored_ssp = AuthoredSSP(tmp_trestle_dir, ssp_index)

with pytest.raises(AuthoredObjectException, match="SSP test-ssp does not exists in the index"):
with pytest.raises(
AuthoredObjectException, match="SSP test-ssp does not exists in the index"
):
authored_ssp.assemble(md_path)


Expand Down Expand Up @@ -115,7 +117,9 @@ def test_regenerate_no_ssp_entry(tmp_trestle_dir: str) -> None:
authored_ssp = AuthoredSSP(tmp_trestle_dir, ssp_index)

model_path = os.path.join(const.MODEL_DIR_SSP, test_ssp_output)
with pytest.raises(AuthoredObjectException, match="SSP test-ssp does not exists in the index"):
with pytest.raises(
AuthoredObjectException, match="SSP test-ssp does not exists in the index"
):
authored_ssp.regenerate(model_path, md_path)


Expand Down
28 changes: 28 additions & 0 deletions tests/trestlebot/test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
from typing import Tuple

import pytest
from git.repo import Repo

import trestlebot.bot as bot
Expand Down Expand Up @@ -201,3 +202,30 @@ def test_empty_commit(tmp_repo: Tuple[str, Repo]) -> None:
assert commit_sha == ""

clean(repo_path, repo)


def test_run_check_only(tmp_repo: Tuple[str, Repo]) -> None:
"""Test bot run with check_only"""
repo_path, repo = tmp_repo

# Create a test file
test_file_path = os.path.join(repo_path, "test.txt")
with open(test_file_path, "w") as f:
f.write("Test content")

with pytest.raises(
bot.RepoException,
match="Check only mode is enable and diff detected. Manual intervention on main is required.",
):
_ = bot.run(
working_dir=repo_path,
branch="main",
commit_name="Test User",
commit_email="[email protected]",
commit_message="Test commit message",
author_name="The Author",
author_email="[email protected]",
patterns=["*.txt"],
dry_run=True,
check_only=True,
)

0 comments on commit fe0a9ee

Please sign in to comment.