ci: validate custom Tryton packages and translations
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import importlib.util
|
||||
import os
|
||||
import pathlib
|
||||
import unittest
|
||||
from unittest.mock import ANY, patch
|
||||
|
||||
|
||||
SCRIPT = pathlib.Path(__file__).parents[1] / 'upstream_pr.py'
|
||||
|
||||
|
||||
class UpstreamPullRequestTestCase(unittest.TestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
environment = {
|
||||
'GITEA_URL': 'https://gitea.example.test',
|
||||
'CUSTOM_REPOSITORY': 'tryton-do/tryton',
|
||||
'GITEA_TOKEN': 'test-token',
|
||||
'INTEGRATION_BRANCH': 'integration/8.0',
|
||||
'UPDATE_BRANCH': 'automation/upstream-8.0',
|
||||
}
|
||||
with patch.dict(os.environ, environment, clear=False):
|
||||
spec = importlib.util.spec_from_file_location('upstream_pr', SCRIPT)
|
||||
cls.module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(cls.module)
|
||||
|
||||
def test_reuses_existing_pull_request(self):
|
||||
existing = [{
|
||||
'head': {'ref': self.module.HEAD},
|
||||
'base': {'ref': self.module.TARGET},
|
||||
'html_url': 'https://gitea.example.test/pulls/1',
|
||||
}]
|
||||
with patch.object(self.module, 'open_pulls', return_value=existing), \
|
||||
patch.object(self.module, 'request') as request:
|
||||
self.module.ensure_pull_request('a' * 40)
|
||||
request.assert_not_called()
|
||||
|
||||
def test_creates_pull_request_with_review_target(self):
|
||||
created = {'html_url': 'https://gitea.example.test/pulls/2'}
|
||||
with patch.object(self.module, 'open_pulls', return_value=[]), \
|
||||
patch.object(self.module, 'request', return_value=created) as request:
|
||||
self.module.ensure_pull_request('b' * 40)
|
||||
request.assert_called_once_with(
|
||||
'POST', '/repos/tryton-do/tryton/pulls', ANY)
|
||||
payload = request.call_args.args[2]
|
||||
self.assertEqual(payload['head'], 'automation/upstream-8.0')
|
||||
self.assertEqual(payload['base'], 'integration/8.0')
|
||||
|
||||
def test_reuses_existing_conflict_issue(self):
|
||||
existing = [{
|
||||
'title': 'Upstream Tryton 8.0 synchronization conflict',
|
||||
'html_url': 'https://gitea.example.test/issues/1',
|
||||
}]
|
||||
with patch.object(self.module, 'request', return_value=existing) as request:
|
||||
self.module.ensure_conflict_issue('trytond/file.py')
|
||||
request.assert_called_once()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Validate every Gettext catalog changed or maintained in this repository."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import polib
|
||||
|
||||
|
||||
def main() -> int:
|
||||
failures: list[str] = []
|
||||
catalogs = sorted(Path('.').glob('**/*.po'))
|
||||
if not catalogs:
|
||||
failures.append('no PO catalogs were found')
|
||||
|
||||
for path in catalogs:
|
||||
try:
|
||||
catalog = polib.pofile(path, check_for_duplicates=True)
|
||||
except (OSError, UnicodeError, ValueError) as exc:
|
||||
failures.append(f'{path}: {exc}')
|
||||
continue
|
||||
if not catalog.metadata.get('Content-Type', '').startswith('text/plain'):
|
||||
failures.append(f'{path}: missing or invalid Content-Type metadata')
|
||||
|
||||
if failures:
|
||||
print('\n'.join(failures), file=sys.stderr)
|
||||
return 1
|
||||
print(f'Validated {len(catalogs)} PO catalogs')
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user