Skip to content

Commit 751ea75

Browse files
committed
Fix test cases
1 parent eb4baea commit 751ea75

File tree

1 file changed

+24
-34
lines changed

1 file changed

+24
-34
lines changed

_file_configuration/tests/test_file_configuration.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from unittest.mock import patch
1919

2020
from ipdb import set_trace
21-
from jsonschema.validators import Draft202012Validator
2221
from pytest import fail
2322

2423
from opentelemetry.file_configuration import (
@@ -40,19 +39,22 @@
4039
def test_create_object():
4140

4241
file_configuration = load_file_configuration(
43-
data_path.joinpath("file_configuration").joinpath("file_configuration_0.yaml")
42+
data_path.joinpath("file_configuration").
43+
joinpath("file_configuration_0.yaml")
4444
)
4545

4646
schema_path = data_path.joinpath("schema").joinpath(
4747
"opentelemetry_file_configuration.json"
4848
)
4949

50+
resolved_schema = resolve_schema(schema_path)
51+
5052
try:
51-
validate_file_configuration(schema_path, file_configuration)
53+
validate_file_configuration(resolved_schema, file_configuration)
5254
except Exception as error:
5355
fail(f"Unexpected exception raised: {error}")
5456

55-
processed_schema = process_schema(resolve_schema(schema_path))
57+
processed_schema = process_schema(resolved_schema)
5658

5759
set_resource(create_object(file_configuration, processed_schema, "resource"))
5860

@@ -101,28 +103,34 @@ def test_create_object():
101103

102104
@patch.dict(environ, {"OTEL_BLRB_EXPORT_TIMEOUT": "943"}, clear=True)
103105
def test_substitute_environment_variables():
106+
104107
file_configuration = load_file_configuration(
105-
data_path.joinpath("file_configuration").joinpath("file_configuration_1.yaml")
108+
data_path.joinpath("file_configuration").
109+
joinpath("file_configuration_1.yaml")
106110
)
107111

108112
schema_path = data_path.joinpath("schema").joinpath(
109113
"opentelemetry_file_configuration.json"
110114
)
111115

112-
processed_schema = process_schema(resolve_schema(schema_path))
116+
resolved_schema = resolve_schema(schema_path)
117+
118+
processed_schema = process_schema(resolved_schema)
119+
113120
file_configuration = substitute_environment_variables(
114121
file_configuration, processed_schema
115122
)
116123

124+
try:
125+
validate_file_configuration(resolved_schema, file_configuration)
126+
except Exception as error:
127+
fail(f"Unexpected exception raised: {error}")
128+
117129
assert (
118130
file_configuration["logger_provider"]["processors"][0]["batch"][
119131
"export_timeout"
120132
]
121133
) == 943
122-
try:
123-
validate_file_configuration(schema_path, file_configuration)
124-
except Exception as error:
125-
fail(f"Unexpected exception raised: {error}")
126134

127135

128136
def test_render(tmpdir):
@@ -142,43 +150,25 @@ def test_render(tmpdir):
142150
fail(f"Unexpected exception raised: {error}")
143151

144152

145-
def test_subschemas():
146-
147-
schema_path = data_path.joinpath("schema").joinpath(
148-
"opentelemetry_file_configuration.json"
149-
)
150-
resolved_schema = resolve_schema(schema_path)
151-
resolved_schema
152-
153-
# FIXME once the schema has been resolved, we get a dictionary. Add to this
154-
# dictionary the schema components of each plugin component sub schema then
155-
# use the resulting schema dictionary to do the validation.
156-
157-
file_configuration = load_file_configuration(
158-
data_path.joinpath("file_configuration").joinpath("file_configuration_0.yaml")
159-
)
160-
161-
# FIXME do the same for file_configuration components
162-
163-
Draft202012Validator(resolved_schema).validate(file_configuration)
164-
165-
166153
def test_dry_run():
167154

168155
file_configuration = load_file_configuration(
169-
data_path.joinpath("file_configuration").joinpath("file_configuration_0.yaml")
156+
data_path.joinpath("file_configuration").
157+
joinpath("file_configuration_0.yaml")
170158
)
171159

172160
schema_path = data_path.joinpath("schema").joinpath(
173161
"opentelemetry_file_configuration.json"
174162
)
175163

164+
resolved_schema = resolve_schema(schema_path)
165+
176166
try:
177-
validate_file_configuration(schema_path, file_configuration)
167+
validate_file_configuration(resolved_schema, file_configuration)
178168
except Exception as error:
179169
fail(f"Unexpected exception raised: {error}")
180170

181-
processed_schema = process_schema(resolve_schema(schema_path))
171+
processed_schema = process_schema(resolved_schema)
182172

183173
set_resource(create_object(file_configuration, processed_schema, "resource"))
184174

0 commit comments

Comments
 (0)