def test_conf_list_operations(text1, text2, expected): c1 = ConfDefinition() c1.loads(text1) c2 = ConfDefinition() c2.loads(text2) c1.update_conf_definition(c2) assert c1.get(text1.split("=")[0]) == expected
def test_conf_get_different_type_input_objects(text, expected): """ Testing any possible Python-evaluable-input-format introduced by the user """ c = ConfDefinition() c.loads(text) assert c.get(text.split("=")[0]) == expected
def test_conf_list_operations_fails_with_wrong_types(text1, text2): c1 = ConfDefinition() c1.loads(text1) c1_value_type = type(c1.get("user.company.list:objs")).__name__ c2 = ConfDefinition() c2.loads(text2) with pytest.raises(ConanException) as exc_info: c1.update_conf_definition(c2) assert "It's not possible to compose list values and %s ones" % c1_value_type \ in str(exc_info.value)
def test_conf_get_check_type_and_default(): text = textwrap.dedent("""\ user.company.cpu:jobs=5 user.company.build:ccflags=--m otherflag user.company.list:objs=[0, 1, 2, 3, 4, 'mystr', {'a': 1}, 5, 6] user.company.network:proxies={'url': 'http://api.site.com/apiv2', 'dataType': 'json', 'method': 'GET'} zlib:user.company.check:shared=! zlib:user.company.check:shared_str="False" zlib:user.company.check:static_str=off user.company.list:newnames+=myname """) c = ConfDefinition() c.loads(text) assert c.get("user.company.cpu:jobs", check_type=int) == 5 assert c.get("user.company.cpu:jobs", check_type=str) == "5" # smart conversion with pytest.raises(ConanException) as exc_info: c.get("user.company.cpu:jobs", check_type=list) assert "[conf] user.company.cpu:jobs must be a list-like object." in str( exc_info.value) # Check type does not affect to default value assert c.get("non:existing:conf", default=0, check_type=dict) == 0 assert c.get("zlib:user.company.check:shared") is None # unset value assert c.get("zlib:user.company.check:shared_str") == '"False"' assert c.get("zlib:user.company.check:shared_str", check_type=bool) is False # smart conversion assert c.get("zlib:user.company.check:static_str") == "off" assert c.get("zlib:user.company.check:static_str", check_type=bool) is False # smart conversion assert c.get("user.company.list:newnames") == ["myname" ] # Placeholder is removed