Skip to content

Commit

Permalink
add first test
Browse files Browse the repository at this point in the history
  • Loading branch information
tamsinforbes committed Apr 22, 2024
1 parent f5ad799 commit 4248cee
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
__pycache__/
*.pytest_cache
*venv
*.venv
*.venv
*.vscode
1 change: 0 additions & 1 deletion python-malformed-yaml/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pytest==8.1.1
pytest-mock==3.14.0
32 changes: 10 additions & 22 deletions python-malformed-yaml/test/test_main.py
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"])

0 comments on commit 4248cee

Please sign in to comment.