File: test_settings.py

package info (click to toggle)
python-azure 20250603%2Bgit-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 851,724 kB
  • sloc: python: 7,362,925; ansic: 804; javascript: 287; makefile: 195; sh: 145; xml: 109
file content (43 lines) | stat: -rw-r--r-- 1,424 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See LICENSE.txt in the project root for
# license information.
# -------------------------------------------------------------------------
"""Tests for the global settings."""
from unittest import mock

import pytest

from corehttp.settings import Settings, settings, _convert_bool


def test_global_settings_default():
    assert settings.tracing_enabled is False


def test_global_settings_set():
    settings.tracing_enabled = True
    assert settings.tracing_enabled is True

    settings.tracing_enabled = False
    assert settings.tracing_enabled is False


def test_environment_settings():
    with mock.patch.dict("os.environ", {"SDK_TRACING_ENABLED": "True"}):
        test_settings = Settings()
        assert test_settings.tracing_enabled is True

    with mock.patch.dict("os.environ", {"SDK_TRACING_ENABLED": "False"}):
        test_settings = Settings()
        assert test_settings.tracing_enabled is False


@pytest.mark.parametrize("value", ["Yes", "YES", "yes", "1", "ON", "on", "true", "True", True])
def test_convert_bool(value):
    assert _convert_bool(value)


@pytest.mark.parametrize("value", ["No", "NO", "no", "0", "OFF", "off", "false", "False", False])
def test_convert_bool_false(value):
    assert not _convert_bool(value)