Skip to content

Commit 86b7176

Browse files
Test contribute.py (#138)
1 parent 7a2d9ce commit 86b7176

File tree

2 files changed

+49
-13
lines changed

2 files changed

+49
-13
lines changed

contribute.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
pulling_from_transifex = ('zh-cn', 'pt-br', 'ja', 'uk', 'pl', 'ru', 'fa', 'id')
1+
pulling_from_transifex: frozenset[str] = frozenset(
2+
{'zh-cn', 'pt-br', 'ja', 'uk', 'pl', 'ru', 'fa', 'id'}
3+
)
24

3-
custom_contributing_links = {
5+
custom_contributing_links: dict[str, str] = {
46
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
57
'ko': 'https://www.flowdas.com/pages/python-docs-ko.html',
68
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/3.13/README.rst#%E5%8F%83%E8%88%87%E7%BF%BB%E8%AD%AF',
@@ -21,14 +23,3 @@ def get_contrib_link(language: str, repo: str | None) -> str | None:
2123
)
2224
or (repo and f'https://github.com/{repo}')
2325
)
24-
25-
26-
if __name__ == '__main__':
27-
for code, repo in (
28-
('en', None),
29-
('pl', None),
30-
('ar', 'python/python-docs-ar'),
31-
('zh-cn', None),
32-
('id', None),
33-
):
34-
print(f'{code}: {get_contrib_link(code, repo)}')

tests/test_contribute.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unittest
2+
import urllib3
3+
import support
4+
5+
with support.import_scripts():
6+
import contribute
7+
8+
9+
class testContributeLink(unittest.TestCase):
10+
def test_get_contrib_link(self):
11+
PULL_FROM_TX = 'https://explore.transifex.com/python-doc/python-newest/'
12+
13+
for code, repo, expected in (
14+
('en', None, None),
15+
('pl', None, PULL_FROM_TX),
16+
('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'),
17+
(
18+
'zh-tw',
19+
None,
20+
'https://github.com/python/python-docs-zh-tw/blob/3.13/README.rst#%E5%8F%83%E8%88%87%E7%BF%BB%E8%AD%AF',
21+
),
22+
(
23+
'id',
24+
None,
25+
'https://github.com/python/python-docs-id/blob/3.14/README.md#berkontribusi-untuk-menerjemahkan',
26+
),
27+
):
28+
with self.subTest(code=code, repo=repo, expected=expected):
29+
self.assertEqual(contribute.get_contrib_link(code, repo), expected)
30+
31+
def test_links_are_valid(self):
32+
http = urllib3.PoolManager()
33+
for lang, link in contribute.custom_contributing_links.items():
34+
with self.subTest(lang=lang):
35+
try:
36+
r = http.request('HEAD', link, timeout=urllib3.Timeout(10.0))
37+
self.assertTrue(
38+
200 <= r.status < 400, f'{link} returned {r.status}'
39+
)
40+
except Exception as e:
41+
self.fail(f'{link}: {e}')
42+
43+
44+
if __name__ == '__main__':
45+
unittest.main()

0 commit comments

Comments
 (0)