|
9 | 9 |
|
10 | 10 | class testContributeLink(unittest.TestCase): |
11 | 11 | def test_get_contrib_link(self): |
12 | | - PULL_FROM_TX = 'https://explore.transifex.com/python-doc/python-newest/' |
13 | | - DEVGUIDE = 'https://devguide.python.org/documentation/translations/translating/' |
14 | | - |
15 | 12 | for code, repo, expected in ( |
16 | | - ('en', None, DEVGUIDE), |
17 | | - ('pl', None, PULL_FROM_TX), |
18 | | - ('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'), |
19 | | - ( |
20 | | - 'zh-tw', |
21 | | - None, |
22 | | - 'https://github.com/python/python-docs-zh-tw/blob/3.14/README.rst#id2', |
23 | | - ), |
24 | 13 | ( |
25 | | - 'id', |
| 14 | + 'en', |
26 | 15 | None, |
27 | | - 'https://github.com/python/python-docs-id/blob/3.14/README.md#berkontribusi-untuk-menerjemahkan', |
| 16 | + 'https://devguide.python.org/documentation/translations/translating/', |
28 | 17 | ), |
| 18 | + ('pl', None, 'https://explore.transifex.com/python-doc/python-newest/'), |
| 19 | + ('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'), |
29 | 20 | ): |
30 | | - with self.subTest(code=code, repo=repo, expected=expected): |
31 | | - self.assertEqual(contribute.get_contrib_link(code, repo), expected) |
| 21 | + for branch in ('3.12', '3.14', '3.15', 'main', 'master'): |
| 22 | + with self.subTest(code=code, repo=repo, branch=branch): |
| 23 | + self.assertEqual( |
| 24 | + contribute.get_contrib_link(code, repo, branch), expected |
| 25 | + ) |
| 26 | + |
| 27 | + def test_custom_contrib_links(self): |
| 28 | + expected_links = { |
| 29 | + 'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/{branch}/README.rst#id2', |
| 30 | + 'id': 'https://github.com/python/python-docs-id/blob/{branch}/README.md#berkontribusi-untuk-menerjemahkan', |
| 31 | + 'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/{branch}/CONTRIBUTING.rst', |
| 32 | + 'tr': 'https://github.com/python/python-docs-tr/blob/{branch}/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak', |
| 33 | + 'el': 'https://github.com/python/python-docs-el/blob/{branch}/CONTRIBUTING.md', |
| 34 | + 'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html', |
| 35 | + } |
| 36 | + for code, expected in expected_links.items(): |
| 37 | + for branch in ('3.12', '3.14', '3.15', 'main', 'master'): |
| 38 | + with self.subTest(code=code, branch=branch): |
| 39 | + self.assertEqual( |
| 40 | + contribute.get_contrib_link(code, None, branch), |
| 41 | + expected.format(branch=branch), |
| 42 | + ) |
32 | 43 |
|
33 | 44 | def test_links_are_valid(self): |
34 | | - http = urllib3.PoolManager() |
| 45 | + http = urllib3.PoolManager( |
| 46 | + timeout=1.0, retries=urllib3.Retry(total=3, read=False) |
| 47 | + ) |
35 | 48 | for lang, link in contribute.custom_contributing_links.items(): |
36 | | - with self.subTest(lang=lang): |
| 49 | + link = link.format(branch='3.12' if lang == 'tr' else '3.14') |
| 50 | + with self.subTest(lang=lang, link=link): |
37 | 51 | try: |
38 | | - r = http.request('HEAD', link, timeout=urllib3.Timeout(10.0)) |
39 | | - self.assertTrue( |
40 | | - 200 <= r.status < 400, f'{link} returned {r.status}' |
41 | | - ) |
42 | | - except urllib3.exceptions.MaxRetryError as e: |
43 | | - if isinstance(e.reason, urllib3.exceptions.ReadTimeoutError): |
44 | | - self.skipTest(f'{link}: read timeout, skipping slow server') |
45 | | - self.fail(f'{link}: {e}') |
46 | | - except urllib3.exceptions.HTTPError as e: |
47 | | - self.fail(f'{link}: {e}') |
| 52 | + response = http.request('HEAD', link) |
| 53 | + except urllib3.exceptions.ReadTimeoutError: |
| 54 | + self.skipTest(f'{link}: read timeout, skipping slow server') |
| 55 | + self.assertTrue( |
| 56 | + 200 <= response.status < 400, f'{link} returned {response.status}' |
| 57 | + ) |
48 | 58 |
|
49 | 59 |
|
50 | 60 | if __name__ == '__main__': |
|
0 commit comments