Skip to content

Commit

Permalink
TST: Add configuration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgxd committed Jun 28, 2022
1 parent d60d01e commit 3dd78f6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Empty file added etelemetry/tests/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions etelemetry/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import uuid

import pytest

from .. import config


@pytest.fixture(autouse=True)
def tmp_config(tmp_path, monkeypatch):
home = tmp_path / 'config.json'
monkeypatch.setattr(config, 'DEFAULT_CONFIG_FILE', home)


def test_setup_default():

conf = config.Config
assert conf.endpoint is None
assert conf.user_id is None
assert conf.session_id is None
assert conf._is_setup is False

config.setup()
assert conf.endpoint == config.DEFAULT_ENDPOINT
assert uuid.UUID(conf.user_id)
assert conf.session_id is None
assert conf._is_setup is True

# after being set up, cannot be overriden
new_endpoint = 'https://github.com'
config.setup(endpoint=new_endpoint)
assert conf.endpoint == config.DEFAULT_ENDPOINT

# but fine if cleared
conf._reset()
assert conf.endpoint is None
config.setup(endpoint=new_endpoint)
assert conf.endpoint == new_endpoint
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ install_requires =
ci-info >= 0.2
typing_extensions; python_version<'3.8'

[options.extras_require]
test =
pytest

[flake8]
max-line-length = 99

Expand Down

0 comments on commit 3dd78f6

Please sign in to comment.