Skip to content

Commit

Permalink
fix some typos and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Heffernan committed Mar 15, 2024
1 parent b0a6ff4 commit 792409e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion secureli/modules/language_analyzer/language_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ def build_pre_commit_config(
else None
)
data = yaml.safe_load(result.config_data)
config_repos += data["repos"] or []

config_repos += data["repos"] or []
config = {**existing_data, "repos": config_repos}
version = hash_config(yaml.dump(config))

Expand Down
6 changes: 3 additions & 3 deletions tests/modules/language_analyzer/test_language_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def test_write_pre_commit_configs_writes_successfully(


def test_build_pre_commit_displays_error_parsing_existing_config(
language_support_service: LanguageSupportService,
language_support_service: language_support.LanguageSupportService,
mock_language_config_service: MagicMock,
mock_open: MagicMock,
mock_echo: MagicMock,
Expand All @@ -410,10 +410,10 @@ def test_build_pre_commit_displays_error_parsing_existing_config(
patch("builtins.open", mock_open(read_data="data")),
patch.object(yaml, "safe_load", side_effect=yaml.YAMLError),
):
mock_language_config_service.get_language_config.return_value = LanguagePreCommitResult(
mock_language_config_service.get_language_config.return_value = language.LanguagePreCommitResult(
language="Python",
version="abc123",
linter_config=LoadLinterConfigsResult(
linter_config=language.LoadLinterConfigsResult(
successful=True,
linter_data=[{"filename": "test.txt", "settings": {}}],
),
Expand Down
63 changes: 35 additions & 28 deletions tests/modules/shared/abstractions/test_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,26 @@
import pytest
from pytest_mock import MockerFixture

from secureli.abstractions.pre_commit import (
from secureli.modules.shared.abstractions.pre_commit import (
InstallResult,
PreCommitAbstraction,
)
from secureli.repositories.settings import (
PreCommitSettings,
PreCommitRepo,
PreCommitHook,
)
from secureli.repositories import repo_settings


test_folder_path = Path("does-not-matter")
example_git_sha = "a" * 40


@pytest.fixture()
def settings_dict() -> dict:
return PreCommitSettings(
return repo_settings.PreCommitSettings(
repos=[
PreCommitRepo(
repo_settings.PreCommitRepo(
repo="http://example-repo.com/",
rev="master",
hooks=[
PreCommitHook(
repo_settings.PreCommitHook(
id="hook-id",
arguments=None,
additional_args=None,
Expand All @@ -48,7 +45,7 @@ def mock_hashlib(mocker: MockerFixture) -> MagicMock:
mock_md5 = MagicMock()
mock_hashlib.md5.return_value = mock_md5
mock_md5.hexdigest.return_value = "mock-hash-code"
mocker.patch("secureli.utilities.hash.hashlib", mock_hashlib)
mocker.patch("secureli.modules.shared.utilities.hashlib", mock_hashlib)
return mock_hashlib


Expand All @@ -58,7 +55,7 @@ def mock_hashlib_no_match(mocker: MockerFixture) -> MagicMock:
mock_md5 = MagicMock()
mock_hashlib.md5.return_value = mock_md5
mock_md5.hexdigest.side_effect = ["first-hash-code", "second-hash-code"]
mocker.patch("secureli.utilities.hash.hashlib", mock_hashlib)
mocker.patch("secureli.modules.shared.utilities.hashlib", mock_hashlib)
return mock_hashlib


Expand All @@ -73,7 +70,9 @@ def mock_data_loader() -> MagicMock:
def mock_subprocess(mocker: MockerFixture) -> MagicMock:
mock_subprocess = MagicMock()
mock_subprocess.run.return_value = CompletedProcess(args=[], returncode=0)
mocker.patch("secureli.abstractions.pre_commit.subprocess", mock_subprocess)
mocker.patch(
"secureli.modules.shared.abstractions.pre_commit.subprocess", mock_subprocess
)
return mock_subprocess


Expand Down Expand Up @@ -431,14 +430,16 @@ def test_check_for_hook_updates_infers_freeze_param_when_not_provided(
rev_is_sha: bool,
):
with um.patch(
"secureli.abstractions.pre_commit.HookRepoRevInfo.from_config"
"secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config"
) as mock_hook_repo_rev_info:
pre_commit_config_repo = PreCommitRepo(
pre_commit_config_repo = repo_settings.PreCommitRepo(
repo="http://example-repo.com/",
rev=rev,
hooks=[PreCommitHook(id="hook-id")],
hooks=[repo_settings.PreCommitHook(id="hook-id")],
)
pre_commit_config = repo_settings.PreCommitSettings(
repos=[pre_commit_config_repo]
)
pre_commit_config = PreCommitSettings(repos=[pre_commit_config_repo])
rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev)
mock_hook_repo_rev_info.return_value = rev_info_mock
rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date
Expand All @@ -454,14 +455,16 @@ def test_check_for_hook_updates_respects_freeze_param_when_false(
regardless of whether the existing rev is a tag or a commit hash.
"""
with um.patch(
"secureli.abstractions.pre_commit.HookRepoRevInfo.from_config"
"secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config"
) as mock_hook_repo_rev_info:
pre_commit_config_repo = PreCommitRepo(
pre_commit_config_repo = repo_settings.PreCommitRepo(
repo="http://example-repo.com/",
rev=example_git_sha,
hooks=[PreCommitHook(id="hook-id")],
hooks=[repo_settings.PreCommitHook(id="hook-id")],
)
pre_commit_config = repo_settings.PreCommitSettings(
repos=[pre_commit_config_repo]
)
pre_commit_config = PreCommitSettings(repos=[pre_commit_config_repo])
rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev)
mock_hook_repo_rev_info.return_value = rev_info_mock
rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date
Expand All @@ -473,14 +476,16 @@ def test_check_for_hook_updates_respects_freeze_param_when_true(
pre_commit: PreCommitAbstraction,
):
with um.patch(
"secureli.abstractions.pre_commit.HookRepoRevInfo.from_config"
"secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo.from_config"
) as mock_hook_repo_rev_info:
pre_commit_config_repo = PreCommitRepo(
pre_commit_config_repo = repo_settings.PreCommitRepo(
repo="http://example-repo.com/",
rev="tag1",
hooks=[PreCommitHook(id="hook-id")],
hooks=[repo_settings.PreCommitHook(id="hook-id")],
)
pre_commit_config = repo_settings.PreCommitSettings(
repos=[pre_commit_config_repo]
)
pre_commit_config = PreCommitSettings(repos=[pre_commit_config_repo])
rev_info_mock = MagicMock(rev=pre_commit_config_repo.rev)
mock_hook_repo_rev_info.return_value = rev_info_mock
rev_info_mock.update.return_value = rev_info_mock # Returning the same revision info on update means the hook will be considered up to date
Expand All @@ -492,15 +497,17 @@ def test_check_for_hook_updates_returns_repos_with_new_revs(
pre_commit: PreCommitAbstraction,
):
with um.patch(
"secureli.abstractions.pre_commit.HookRepoRevInfo"
"secureli.modules.shared.abstractions.pre_commit.HookRepoRevInfo"
) as mock_hook_repo_rev_info:
repo_urls = ["http://example-repo.com/", "http://example-repo-2.com/"]
old_rev = "tag1"
repo_1_new_rev = "tag2"
pre_commit_config = PreCommitSettings(
pre_commit_config = repo_settings.PreCommitSettings(
repos=[
PreCommitRepo(
repo=repo_url, rev=old_rev, hooks=[PreCommitHook(id="hook-id")]
repo_settings.PreCommitRepo(
repo=repo_url,
rev=old_rev,
hooks=[repo_settings.PreCommitHook(id="hook-id")],
)
for repo_url in repo_urls
]
Expand Down

0 comments on commit 792409e

Please sign in to comment.