diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 000000000..0c968d339 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,19 @@ +name: Run test suite +on: + pull_request: + workflow_dispatch: + push: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: "3.x" + - run: pip install -r requirements.txt + - run: python -m unittest discover -s tests diff --git a/tests/support.py b/tests/support.py new file mode 100644 index 000000000..0841ce479 --- /dev/null +++ b/tests/support.py @@ -0,0 +1,25 @@ +import sys +import contextlib + +# -------------------------------- Imports ----------------------------------- # + + +# Support functions borrowed from CPython's test.support +@contextlib.contextmanager +def import_scripts(dir='..'): + with DirsOnSysPath(dir) as cm: + yield cm + + +class DirsOnSysPath(object): + def __init__(self, *paths): + self.original_value = sys.path[:] + self.original_object = sys.path + sys.path.extend(paths) + + def __enter__(self): + return self + + def __exit__(self, *ignore_exc): + sys.path = self.original_object + sys.path[:] = self.original_value diff --git a/tests/test_build_status.py b/tests/test_build_status.py new file mode 100644 index 000000000..b7106e8ba --- /dev/null +++ b/tests/test_build_status.py @@ -0,0 +1,27 @@ +import unittest +import support + +from urllib3 import PoolManager + +with support.import_scripts(): + import build_status + + +class testBuildStatus(unittest.TestCase): + def test_get_languages(self): + result = { + language: translated_name + for language, translated_name in build_status.get_languages(PoolManager()) + } + + self.assertIn('en', result) + self.assertIn('pl', result) + self.assertIn('zh-cn', result) + + self.assertEqual(result.get('en'), None) + self.assertEqual(result.get('pl'), 'polski') + self.assertEqual(result.get('zh-cn'), '简体中文') + + +if __name__ == '__main__': + unittest.main()