-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5ad799
commit 4248cee
Showing
3 changed files
with
12 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
__pycache__/ | ||
*.pytest_cache | ||
*venv | ||
*.venv | ||
*.venv | ||
*.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pytest==8.1.1 | ||
pytest-mock==3.14.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
import pytest | ||
import unittest | ||
import os | ||
from unittest.mock import patch | ||
from main import get_changed_yaml_files_from_pr, get_malformed_yaml_files, main | ||
import unittest | ||
from main import get_changed_yaml_files_from_pr, get_malformed_yaml_files_and_errors, main | ||
from github_service import GitHubService as github_service | ||
# python_malformed_yaml_main = importlib.import_module( | ||
# "python-malformed-yaml.main") | ||
# main = python_malformed_yaml_main.main | ||
|
||
def test_get_changed_yaml_files_from_pr(mocker): | ||
# get_github_env_mock = mocker.patch("get_github_env") | ||
# get_github_env_mock.return_value = ("fake_github_token", "fake_repo", "123") | ||
# github_mock = mocker.patch("github") | ||
|
||
get_changed_files_from_pr_mock = mocker.patch("get_changed_files_from_pr") | ||
get_changed_files_from_pr_mock.return_value(["a.yml", "b.py", "c.yaml", "d.txt"]) | ||
assert get_changed_yaml_files_from_pr() == ["a.yml", "c.yaml"] | ||
class TestMain(unittest.TestCase): | ||
|
||
|
||
def test_main_exception(): | ||
with pytest.raises(Exception) as exc_info: | ||
main() | ||
expected_malformed_files = [ | ||
"test_python_malformed_yaml/test_yaml_files/bad.yml", | ||
"test_python_malformed_yaml/test_yaml_files/bad.yaml" | ||
] | ||
assert all(file in str(exc_info.value) | ||
for file in expected_malformed_files) | ||
@patch.object(github_service, "__new__") | ||
@patch.dict(os.environ, {"GITHUB_TOKEN": "token", "PR_NUMBER": "123", "REPOSITORY_NAME": "repo_name"}) | ||
def test_get_changed_yaml_files_from_pr_all_yaml(self, mock_github_service): | ||
mock_github_service.return_value.get_changed_files_from_pr.return_value = ["a.txt", "b.yaml"] | ||
result = get_changed_yaml_files_from_pr() | ||
self.assertEqual(result, ["b.yaml"]) |