diff options
author | 2019-09-15 16:48:10 +0200 | |
---|---|---|
committer | 2019-09-18 00:50:50 +1000 | |
commit | 0d27d5d0edf17fec789b752700e9e4a753f45df0 (patch) | |
tree | d5a8ab211a71c5e15073977915bd24de833600b6 | |
parent | Add coverage reporting & JUnit XML to tests. (#432) (diff) |
Validate configuration against typehints.
-rw-r--r-- | azure-pipelines.yml | 2 | ||||
-rw-r--r-- | bot/constants.py | 7 | ||||
-rw-r--r-- | config-default.yml | 6 | ||||
-rw-r--r-- | tests/test_constants.py | 23 |
4 files changed, 25 insertions, 13 deletions
diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 242513ab4..4dcad685c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -38,7 +38,7 @@ jobs: - script: python -m flake8 displayName: 'Run linter' - - script: BOT_TOKEN=foobar python -m pytest --junitxml=junit.xml --cov=bot --cov-branch --cov-report=term --cov-report=xml tests + - script: BOT_API_KEY=foo BOT_TOKEN=bar WOLFRAM_API_KEY=baz python -m pytest --junitxml=junit.xml --cov=bot --cov-branch --cov-report=term --cov-report=xml tests displayName: Run tests - task: PublishCodeCoverageResults@1 diff --git a/bot/constants.py b/bot/constants.py index d5b73bd1d..e1c47889c 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -347,9 +347,9 @@ class Channels(metaclass=YAMLGetter): message_log: int mod_alerts: int modlog: int + off_topic_0: int off_topic_1: int off_topic_2: int - off_topic_3: int python: int reddit: int talent_pool: int @@ -394,8 +394,6 @@ class Guild(metaclass=YAMLGetter): class Keys(metaclass=YAMLGetter): section = "keys" - deploy_bot: str - deploy_site: str site_api: str @@ -411,14 +409,11 @@ class URLs(metaclass=YAMLGetter): # Misc endpoints bot_avatar: str - deploy: str github_bot_repo: str - status: str # Site endpoints site: str site_api: str - site_clean_api: str site_superstarify_api: str site_logs_api: str site_logs_view: str diff --git a/config-default.yml b/config-default.yml index fd83e69a4..403de21ad 100644 --- a/config-default.yml +++ b/config-default.yml @@ -227,8 +227,6 @@ filter: keys: - deploy_bot: !ENV "DEPLOY_BOT_KEY" - deploy_site: !ENV "DEPLOY_SITE" site_api: !ENV "BOT_API_KEY" @@ -263,10 +261,6 @@ urls: # Snekbox snekbox_eval_api: "https://snekbox.pythondiscord.com/eval" - # Env vars - deploy: !ENV "DEPLOY_URL" - status: !ENV "STATUS_URL" - # Discord API URLs discord_api: &DISCORD_API "https://discordapp.com/api/v7/" discord_invite_api: !JOIN [*DISCORD_API, "invites"] diff --git a/tests/test_constants.py b/tests/test_constants.py new file mode 100644 index 000000000..e4a29d994 --- /dev/null +++ b/tests/test_constants.py @@ -0,0 +1,23 @@ +import inspect + +import pytest + +from bot import constants + + + 'section', + ( + cls + for (name, cls) in inspect.getmembers(constants) + if hasattr(cls, 'section') and isinstance(cls, type) + ) +) +def test_section_configuration_matches_typespec(section): + for (name, annotation) in section.__annotations__.items(): + value = getattr(section, name) + + if getattr(annotation, '_name', None) in ('Dict', 'List'): + pytest.skip("Cannot validate containers yet") + + assert isinstance(value, annotation) |