Skip to content

Commit b83c3d9

Browse files
committed
test: cover empty company fallback
Add a markdown test that expects "-" when company is empty. Signed-off-by: Venu Vardhan Reddy Tekula <venuvrtekula@gmail.com>
1 parent 9f91afc commit b83c3d9

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

test_markdown.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,60 @@ def test_write_to_markdown_with_sponsors(
148148
)
149149
mock_file().write.assert_called_once_with(expected_content)
150150

151+
@patch(
152+
"markdown.os.environ.get", return_value=None
153+
) # Mock GITHUB_STEP_SUMMARY to None
154+
@patch("builtins.open", new_callable=mock_open)
155+
def test_write_to_markdown_empty_company_falls_back(
156+
self, mock_file, mock_env_get
157+
): # pylint: disable=unused-argument
158+
"""
159+
Test the write_to_markdown function with an empty company value.
160+
"""
161+
person1 = contributor_stats.ContributorStats(
162+
"user1",
163+
"",
164+
False,
165+
"url",
166+
100,
167+
"commit url",
168+
"sponsor_url_1",
169+
)
170+
collaborators = [
171+
person1,
172+
]
173+
ghe = ""
174+
175+
write_to_markdown(
176+
collaborators,
177+
"filename",
178+
"2023-01-01",
179+
"2023-01-02",
180+
None,
181+
"org/repo",
182+
"false",
183+
True,
184+
ghe,
185+
)
186+
187+
mock_file.assert_called_once_with("filename", "w", encoding="utf-8")
188+
expected_content = (
189+
"# Contributors\n\n"
190+
"- Date range for contributor list: 2023-01-01 to 2023-01-02\n"
191+
"- Repository: org/repo\n\n"
192+
"| Total Contributors | Total Contributions | % New Contributors |\n"
193+
"| --- | --- | --- |\n"
194+
"| 1 | 100 | 0.0% |\n\n"
195+
"| Username | Company | All Time Contribution Count | New Contributor | "
196+
"Commits between 2023-01-01 and 2023-01-02 |\n"
197+
"| --- | --- | --- | --- | --- |\n"
198+
"| @user1 | - | 100 | False | commit url |\n"
199+
"\n _this file was generated by the "
200+
"[Contributors GitHub Action]"
201+
"(https://github.com/github/contributors)_\n"
202+
)
203+
mock_file().write.assert_called_once_with(expected_content)
204+
151205
@patch(
152206
"markdown.os.environ.get", return_value=None
153207
) # Mock GITHUB_STEP_SUMMARY to None

0 commit comments

Comments
 (0)