pyinfra/test/unit_tests/config_test.py
Matthias Bisping c9bfc767a8 Pull request #32: restructuring: moved test out of module scope
Merge in RR/pyinfra from partial_responses to master

Squashed commit of the following:

commit afd67d87a6349c4b97453a12274c6ccf5e976339
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Tue Apr 26 12:48:12 2022 +0200

    updated test container dockerfile for new location of tests directory

commit 37881da08ebedf0f2d0c6c2b267bdb47818a0da1
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Tue Apr 26 12:45:12 2022 +0200

    restructuring: moved test out  of module scope
2022-04-26 13:12:54 +02:00

46 lines
1.1 KiB
Python

import os
import tempfile
import pytest
import yaml
from pyinfra.config import Config, parse_disjunction_string
@pytest.fixture
def config_file_content():
return {"A": [{"B": [1, 2]}, {"C": 3}, 4], "D": {"E": {"F": True}}}
@pytest.fixture
def config(config_file_content):
with tempfile.NamedTemporaryFile(suffix=".yaml", mode="w") as f:
yaml.dump(config_file_content, f, default_flow_style=False)
yield Config(f.name)
def test_dot_access_key_exists(config):
assert config.A == [{"B": [1, 2]}, {"C": 3}, 4]
assert config.D.E["F"]
def test_access_key_exists(config):
assert config["A"] == [{"B": [1, 2]}, {"C": 3}, 4]
assert config["A"][0] == {"B": [1, 2]}
assert config["A"][0]["B"] == [1, 2]
assert config["A"][0]["B"][0] == 1
def test_dot_access_key_does_not_exists(config):
assert config.B is None
def test_access_key_does_not_exists(config):
assert config["B"] is None
def test_parse_disjunction_string():
assert parse_disjunction_string("A|Bb|c") == "c"
os.environ["Bb"] = "d"
assert parse_disjunction_string("A|Bb|c") == "d"