@@ -93,9 +93,66 @@ def test_print_help(self, mock_isatty, mock_print_help):
93
93
94
94
self .assertEqual (e .exception .code , 1 )
95
95
mock_print_help .assert_called_once ()
96
- mock_isatty .assert_called_once ()
96
+ # isatty should be called at least once
97
+ self .assertTrue (mock_isatty .call_count >= 1 )
97
98
# self.assertEqual(mock_isatty.call_count, 2)
98
99
100
+ @patch ("argparse.ArgumentParser.print_help" )
101
+ @patch ("sys.stdin.isatty" )
102
+ def test_no_templates_no_deployment_files (self , mock_isatty , mock_print_help ):
103
+ """Test that help is printed when no templates or deployment
104
+ files are provided and stdin is a tty"""
105
+ # Create a config with no templates or deployment files
106
+ config = ConfigMixIn ([])
107
+
108
+ # Ensure templates and deployment_files are empty or None
109
+ self .assertTrue (not config .templates or config .templates == [])
110
+ self .assertTrue (not config .deployment_files or config .deployment_files == [])
111
+
112
+ runner = Runner (config )
113
+ mock_isatty .return_value = True
114
+
115
+ # Should exit with code 1 and print help
116
+ with self .assertRaises (SystemExit ) as e :
117
+ runner .cli ()
118
+
119
+ self .assertEqual (e .exception .code , 1 )
120
+ mock_print_help .assert_called_once ()
121
+ # isatty should be called at least once
122
+ self .assertTrue (mock_isatty .call_count >= 1 )
123
+
124
+ @patch ("argparse.ArgumentParser.print_help" )
125
+ @patch ("sys.stdin.isatty" )
126
+ @patch ("cfnlint.runner.Runner._cli_output" )
127
+ def test_no_templates_no_deployment_files_with_stdin (
128
+ self , mock_cli_output , mock_isatty , mock_print_help
129
+ ):
130
+ """Test that when no templates or deployment files are
131
+ provided but stdin is not a tty, the program continues
132
+ execution without printing help"""
133
+ # Create a config with no templates or deployment files
134
+ config = ConfigMixIn ([])
135
+
136
+ # Ensure templates and deployment_files are empty or None
137
+ self .assertTrue (not config .templates or config .templates == [])
138
+ self .assertTrue (not config .deployment_files or config .deployment_files == [])
139
+
140
+ # Mock _cli_output to avoid actual processing
141
+ mock_cli_output .return_value = None
142
+
143
+ runner = Runner (config )
144
+ mock_isatty .return_value = False
145
+
146
+ # Should not exit and not print help
147
+ runner .cli ()
148
+
149
+ # Help should not be printed
150
+ mock_print_help .assert_not_called ()
151
+ # isatty should be called at least once
152
+ self .assertTrue (mock_isatty .call_count >= 1 )
153
+ # _cli_output should be called once
154
+ mock_cli_output .assert_called_once ()
155
+
99
156
def test_bad_regions (self ):
100
157
config = ConfigMixIn (
101
158
[
0 commit comments