MCPcopy Create free account
hub / github.com/anthropics/claude-code-security-review / TestMainFunction

Class TestMainFunction

claudecode/test_main_function.py:15–512  ·  view source on GitHub ↗

Test main function execution flow.

Source from the content-addressed store, hash-verified

13
14
15class TestMainFunction:
16 """Test main function execution flow."""
17
18 def test_main_missing_environment_vars(self, capsys):
19 """Test main with missing environment variables."""
20 with patch.dict(os.environ, {}, clear=True):
21 with pytest.raises(SystemExit) as exc_info:
22 main()
23
24 assert exc_info.value.code == 2 # EXIT_CONFIGURATION_ERROR
25
26 captured = capsys.readouterr()
27 output = json.loads(captured.out)
28 assert 'error' in output
29 assert 'GITHUB_REPOSITORY' in output['error']
30
31 def test_main_missing_pr_number(self, capsys):
32 """Test main with missing PR number."""
33 with patch.dict(os.environ, {'GITHUB_REPOSITORY': 'owner/repo'}, clear=True):
34 with pytest.raises(SystemExit) as exc_info:
35 main()
36
37 assert exc_info.value.code == 2 # EXIT_CONFIGURATION_ERROR
38
39 captured = capsys.readouterr()
40 output = json.loads(captured.out)
41 assert 'PR_NUMBER' in output['error']
42
43 def test_main_invalid_pr_number(self, capsys):
44 """Test main with invalid PR number."""
45 with patch.dict(os.environ, {
46 'GITHUB_REPOSITORY': 'owner/repo',
47 'PR_NUMBER': 'not-a-number'
48 }, clear=True):
49 with pytest.raises(SystemExit) as exc_info:
50 main()
51
52 assert exc_info.value.code == 2 # EXIT_CONFIGURATION_ERROR
53
54 captured = capsys.readouterr()
55 output = json.loads(captured.out)
56 assert 'Invalid PR_NUMBER' in output['error']
57
58 @patch('claudecode.github_action_audit.GitHubActionClient')
59 def test_main_github_client_init_failure(self, mock_client_class, capsys):
60 """Test main when GitHub client initialization fails."""
61 mock_client_class.side_effect = Exception("Token invalid")
62
63 with patch.dict(os.environ, {
64 'GITHUB_REPOSITORY': 'owner/repo',
65 'PR_NUMBER': '123',
66 'GITHUB_TOKEN': 'invalid'
67 }):
68 with pytest.raises(SystemExit) as exc_info:
69 main()
70
71 assert exc_info.value.code == 2 # EXIT_CONFIGURATION_ERROR
72

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected