|
15 | 15 | import collections |
16 | 16 | import copy |
17 | 17 | import logging |
| 18 | +import pathlib |
18 | 19 | import sys |
19 | 20 | import tempfile |
20 | 21 | import urllib.parse as urlparse |
@@ -1059,6 +1060,45 @@ def test_toml_parse_production(): |
1059 | 1060 | assert value.enabled is False |
1060 | 1061 |
|
1061 | 1062 |
|
| 1063 | +@pytest.mark.parametrize( |
| 1064 | + "pathtype", [str, lambda s: s.encode("utf-8"), pathlib.Path], ids=["str", "bytes", "pathlib.Path"] |
| 1065 | +) |
| 1066 | +def test_config_file_path_types_ini(pathtype): |
| 1067 | + settings = global_settings() |
| 1068 | + _reset_configuration_done() |
| 1069 | + _reset_config_parser() |
| 1070 | + _reset_instrumentation_done() |
| 1071 | + |
| 1072 | + with tempfile.NamedTemporaryFile(suffix=".ini") as f: |
| 1073 | + f.write(newrelic_ini_contents) |
| 1074 | + f.seek(0) |
| 1075 | + |
| 1076 | + config_file = pathtype(f.name) |
| 1077 | + initialize(config_file=config_file) |
| 1078 | + value = fetch_config_setting(settings, "app_name") |
| 1079 | + assert value == "Python Agent Test (agent_features)" |
| 1080 | + |
| 1081 | + |
| 1082 | +@pytest.mark.parametrize( |
| 1083 | + "pathtype", [str, lambda s: s.encode("utf-8"), pathlib.Path], ids=["str", "bytes", "pathlib.Path"] |
| 1084 | +) |
| 1085 | +@SKIP_IF_NOT_PY311 |
| 1086 | +def test_config_file_path_types_toml(pathtype): |
| 1087 | + settings = global_settings() |
| 1088 | + _reset_configuration_done() |
| 1089 | + _reset_config_parser() |
| 1090 | + _reset_instrumentation_done() |
| 1091 | + |
| 1092 | + with tempfile.NamedTemporaryFile(suffix=".toml") as f: |
| 1093 | + f.write(newrelic_toml_contents) |
| 1094 | + f.seek(0) |
| 1095 | + |
| 1096 | + config_file = pathtype(f.name) |
| 1097 | + initialize(config_file=config_file) |
| 1098 | + value = fetch_config_setting(settings, "app_name") |
| 1099 | + assert value == "test11" |
| 1100 | + |
| 1101 | + |
1062 | 1102 | @pytest.fixture |
1063 | 1103 | def caplog_handler(): |
1064 | 1104 | class CaplogHandler(logging.StreamHandler): |
|
0 commit comments