| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  | # -*- coding: utf-8; -*- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from unittest.mock import Mock, patch | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from wuttjamaican.testing import ConfigTestCase | 
					
						
							|  |  |  | from wuttjamaican.cli import problems as mod | 
					
						
							|  |  |  | from wuttjamaican.problems import ProblemHandler, ProblemCheck | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FakeCheck(ProblemCheck): | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |     system_key = "wuttatest" | 
					
						
							|  |  |  |     problem_key = "fake_check" | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  |     title = "Fake problem check" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TestProblems(ConfigTestCase): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def test_basic(self): | 
					
						
							|  |  |  |         ctx = Mock() | 
					
						
							|  |  |  |         ctx.parent.wutta_config = self.config | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # nb. avoid printing to console | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |         with patch.object(mod.rich, "print") as rich_print: | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |             # nb. use fake check | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |             with patch.object( | 
					
						
							|  |  |  |                 ProblemHandler, "get_all_problem_checks", return_value=[FakeCheck] | 
					
						
							|  |  |  |             ): | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |                 with patch.object( | 
					
						
							|  |  |  |                     ProblemHandler, "run_problem_checks" | 
					
						
							|  |  |  |                 ) as run_problem_checks: | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     # list problem checks | 
					
						
							|  |  |  |                     orig_organize = ProblemHandler.organize_problem_checks | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  |                     def mock_organize(checks): | 
					
						
							|  |  |  |                         return orig_organize(None, checks) | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     with patch.object( | 
					
						
							|  |  |  |                         ProblemHandler, | 
					
						
							|  |  |  |                         "organize_problem_checks", | 
					
						
							|  |  |  |                         side_effect=mock_organize, | 
					
						
							|  |  |  |                     ) as organize_problem_checks: | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  |                         mod.problems(ctx, list_checks=True) | 
					
						
							|  |  |  |                         organize_problem_checks.assert_called_once_with([FakeCheck]) | 
					
						
							|  |  |  |                         run_problem_checks.assert_not_called() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     # warning if unknown system key requested | 
					
						
							|  |  |  |                     rich_print.reset_mock() | 
					
						
							|  |  |  |                     # nb. just --list for convenience | 
					
						
							|  |  |  |                     # note that since we also specify invalid --system, no checks will | 
					
						
							|  |  |  |                     # match and hence nothing significant will be printed to stdout | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |                     mod.problems(ctx, list_checks=True, systems=["craziness"]) | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  |                     rich_print.assert_called_once() | 
					
						
							|  |  |  |                     self.assertEqual(len(rich_print.call_args.args), 1) | 
					
						
							| 
									
										
										
										
											2025-08-30 21:25:44 -05:00
										 |  |  |                     self.assertIn( | 
					
						
							|  |  |  |                         "No problem reports exist for system", | 
					
						
							|  |  |  |                         rich_print.call_args.args[0], | 
					
						
							|  |  |  |                     ) | 
					
						
							| 
									
										
										
										
											2025-08-10 11:07:30 -05:00
										 |  |  |                     self.assertEqual(len(rich_print.call_args.kwargs), 0) | 
					
						
							|  |  |  |                     run_problem_checks.assert_not_called() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     # run problem checks | 
					
						
							|  |  |  |                     mod.problems(ctx) | 
					
						
							|  |  |  |                     run_problem_checks.assert_called_once_with([FakeCheck]) |