Pull request #26: Config impl changes

Merge in RR/pyinfra from config_impl_changes to master

Squashed commit of the following:

commit aa732ba18c49edf70198d9bd335193c3509f8e18
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Tue Apr 19 16:45:09 2022 +0200

    test bash script simplified

commit d70c5e48ecfde164f5e508488125c6aa9cd8e621
Author: Matthias Bisping <matthias.bisping@iqser.com>
Date:   Tue Apr 19 16:39:53 2022 +0200

    config coverage
This commit is contained in:
Matthias Bisping 2022-04-19 16:55:34 +02:00
parent 1147a5dc33
commit c933f66a4b
3 changed files with 41 additions and 7 deletions

View File

@ -1,5 +1,6 @@
"""Implements a config object with dot-indexing syntax."""
from envyaml import EnvYAML
from pyinfra.locations import CONFIG_FILE
@ -17,9 +18,6 @@ class DotIndexable:
def __getattr__(self, item):
return _get_item_and_maybe_make_dotindexable(self.x, item)
def __setitem__(self, key, value):
self.x[key] = value
def __repr__(self):
return self.x.__repr__()

View File

@ -0,0 +1,38 @@
import tempfile
import pytest
import yaml
from pyinfra.config import Config
@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

View File

@ -1,11 +1,9 @@
echo "${bamboo_nexus_password}" | docker login --username "${bamboo_nexus_user}" --password-stdin nexus.iqser.com:5001
docker build -f Dockerfile_tests -t pyinfra-tests:dev .
docker tag pyinfra-tests:dev nexus.iqser.com:5001/red/pyinfra-tests:dev
docker push nexus.iqser.com:5001/red/pyinfra-tests:dev
docker build -f Dockerfile_tests -t pyinfra-tests .
rnd=$(date +"%s")
name=pyinfra-tests-${rnd}
echo "running tests container"
docker run --rm --net=host --name $name -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock pyinfra-tests:dev
docker run --rm --net=host --name $name -v $PWD:$PWD -w $PWD -v /var/run/docker.sock:/var/run/docker.sock pyinfra-tests