Skip to content

Commit 174c661

Browse files
Test repositories.py (#129)
1 parent 82c244b commit 174c661

File tree

3 files changed

+67
-13
lines changed

3 files changed

+67
-13
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ on:
33
pull_request:
44
workflow_dispatch:
55
push:
6+
branches:
7+
- main
68

79
jobs:
810
test:

repositories.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
from collections.abc import Iterator
33
from dataclasses import dataclass
44
from pathlib import Path
5-
from tempfile import TemporaryDirectory
65

76
from docutils import core
87
from docutils.nodes import table, row
9-
from git import Repo
108

119

1210
def get_languages_and_repos(
@@ -15,10 +13,14 @@ def get_languages_and_repos(
1513
translating = devguide_dir.joinpath(
1614
'documentation/translations/translating.rst'
1715
).read_text()
18-
doctree = core.publish_doctree(translating)
19-
20-
for node in doctree.traverse(table):
21-
for row_node in node.traverse(row)[1:]:
16+
doctree = core.publish_doctree(
17+
translating,
18+
settings_overrides={'report_level': 5},
19+
# docutils errors on Sphinx directives, but this does not matter for us
20+
)
21+
22+
for node in doctree.findall(table):
23+
for row_node in list(node.findall(row))[1:]:
2224
language = row_node[0].astext()
2325
repo = row_node[2].astext()
2426
language_match = re.match(r'(.*) \((.*)\)', language)
@@ -39,10 +41,3 @@ def get_languages_and_repos(
3941
class Language:
4042
code: str
4143
name: str
42-
43-
44-
if __name__ == '__main__':
45-
with TemporaryDirectory() as directory:
46-
Repo.clone_from('https://github.com/python/devguide.git', directory, depth=1)
47-
for item in get_languages_and_repos(Path(directory)):
48-
print(item)

tests/test_repositories.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import unittest
2+
import support
3+
import tempfile
4+
import shutil
5+
6+
from pathlib import Path
7+
from git import Repo
8+
9+
with support.import_scripts():
10+
import repositories
11+
from repositories import Language
12+
13+
14+
class testRepositories(unittest.TestCase):
15+
@classmethod
16+
def setUpClass(cls):
17+
cls.tempdir = tempfile.mkdtemp()
18+
cls.test_repo_path = Path(cls.tempdir) / 'devguide'
19+
cls.test_repo = Repo.clone_from(
20+
'https://github.com/python/devguide',
21+
cls.test_repo_path,
22+
branch='main',
23+
depth=1,
24+
)
25+
26+
@classmethod
27+
def tearDownClass(cls):
28+
shutil.rmtree(cls.tempdir)
29+
30+
def test_get_languages_and_repos(self):
31+
result = list(repositories.get_languages_and_repos(self.test_repo_path))
32+
33+
for entry in result:
34+
info, repo = entry
35+
self.assertIsInstance(info, Language)
36+
37+
self.assertIn(
38+
(Language(code='tr', name='Turkish'), 'python/python-docs-tr'), result
39+
)
40+
self.assertIn(
41+
(Language(code='es', name='Spanish'), 'python/python-docs-es'), result
42+
)
43+
self.assertIn(
44+
(Language(code='pl', name='Polish'), 'python/python-docs-pl'), result
45+
)
46+
self.assertIn(
47+
(
48+
Language(code='zh-tw', name='Traditional Chinese'),
49+
'python/python-docs-zh-tw',
50+
),
51+
result,
52+
)
53+
self.assertIn(
54+
(Language(code='it', name='Italian'), 'python/python-docs-it'), result
55+
)
56+
57+
self.assertGreater(len(result), 23 - 1)

0 commit comments

Comments
 (0)