|
8 | 8 | TestSearchIssues: A class to test the search_issues function.
|
9 | 9 | TestGetPerIssueMetrics: A class to test the get_per_issue_metrics function.
|
10 | 10 | TestGetEnvVars: A class to test the get_env_vars function.
|
11 |
| -
|
| 11 | + TestEvaluateMarkdownFileSize: A class to test the evaluate_markdown_file_size function. |
12 | 12 | """
|
13 | 13 |
|
14 | 14 | import os
|
15 | 15 | import unittest
|
16 | 16 | from datetime import datetime, timedelta
|
17 |
| -from unittest.mock import MagicMock, patch |
| 17 | +from unittest.mock import MagicMock, call, patch |
18 | 18 |
|
19 | 19 | from issue_metrics import (
|
20 | 20 | IssueWithMetrics,
|
| 21 | + evaluate_markdown_file_size, |
21 | 22 | get_env_vars,
|
22 | 23 | get_per_issue_metrics,
|
23 | 24 | measure_time_to_close,
|
@@ -478,5 +479,49 @@ def test_get_per_issue_metrics_with_discussion_with_hide_envs(self):
|
478 | 479 | self.assertEqual(metrics[0][1].time_to_first_response, None)
|
479 | 480 |
|
480 | 481 |
|
| 482 | +class TestEvaluateMarkdownFileSize(unittest.TestCase): |
| 483 | + """Test suite for the evaluate_markdown_file_size function.""" |
| 484 | + |
| 485 | + @patch("issue_metrics.markdown_too_large_for_issue_body") |
| 486 | + def test_markdown_too_large_for_issue_body_called_with_output_file( |
| 487 | + self, mock_evaluate |
| 488 | + ): |
| 489 | + """ |
| 490 | + Test that the function uses the output_file. |
| 491 | + """ |
| 492 | + mock_evaluate.return_value = False |
| 493 | + evaluate_markdown_file_size("test_issue_metrics.md") |
| 494 | + |
| 495 | + mock_evaluate.assert_called_with("test_issue_metrics.md", 65535) |
| 496 | + |
| 497 | + @patch("issue_metrics.print") |
| 498 | + @patch("shutil.move") |
| 499 | + @patch("issue_metrics.split_markdown_file") |
| 500 | + @patch("issue_metrics.markdown_too_large_for_issue_body") |
| 501 | + def test_split_markdown_file_when_file_size_too_large( |
| 502 | + self, mock_evaluate, mock_split, mock_move, mock_print |
| 503 | + ): |
| 504 | + """ |
| 505 | + Test that the function is called with the output_file |
| 506 | + environment variable. |
| 507 | + """ |
| 508 | + mock_evaluate.return_value = True |
| 509 | + evaluate_markdown_file_size("test_issue_metrics.md") |
| 510 | + |
| 511 | + mock_split.assert_called_with("test_issue_metrics.md", 65535) |
| 512 | + mock_move.assert_has_calls( |
| 513 | + [ |
| 514 | + call("test_issue_metrics.md", "test_issue_metrics_full.md"), |
| 515 | + call("test_issue_metrics_0.md", "test_issue_metrics.md"), |
| 516 | + ] |
| 517 | + ) |
| 518 | + mock_print.assert_called_with( |
| 519 | + "Issue metrics markdown file is too large for GitHub issue body and has been \ |
| 520 | +split into multiple files. ie. test_issue_metrics.md, test_issue_metrics_1.md, etc. \ |
| 521 | +The full file is saved as test_issue_metrics_full.md\n\ |
| 522 | +See https://github.com/github/issue-metrics/blob/main/docs/dealing-with-large-issue-metrics.md" |
| 523 | + ) |
| 524 | + |
| 525 | + |
481 | 526 | if __name__ == "__main__":
|
482 | 527 | unittest.main()
|
0 commit comments