Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lmolkova committed Dec 5, 2023
1 parent 446eb27 commit 510f528
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _render_group_by_root_namespace(
):
attribute_and_templates = self._grouped_attribute_definitions(semconvset)
metrics = self._grouped_metric_definitions(semconvset)
for ns in attribute_and_templates.keys():
for ns in attribute_and_templates:
sanitized_ns = ns if ns != "" else "other"
output_name = self.prefix_output_file(output_file, sanitized_ns)

Expand All @@ -338,9 +338,9 @@ def _render_group_by_root_namespace(
def _grouped_attribute_definitions(self, semconvset):
grouped_attributes = {}
for semconv in semconvset.models.values():
for attr in filter(
lambda a: is_definition(a), semconv.attributes_and_templates
):
for attr in semconv.attributes_and_templates:
if not is_definition(attr): # skip references
continue
if attr.root_namespace not in grouped_attributes:
grouped_attributes[attr.root_namespace] = []
grouped_attributes[attr.root_namespace].append(attr)
Expand All @@ -351,7 +351,10 @@ def _grouped_attribute_definitions(self, semconvset):

def _grouped_metric_definitions(self, semconvset):
grouped_metrics = {}
for semconv in filter(lambda s: is_metric(s), semconvset.models.values()):
for semconv in semconvset.models.values():
if not is_metric(semconv):
continue

if semconv.root_namespace not in grouped_metrics:
grouped_metrics[semconv.root_namespace] = []

Expand All @@ -370,5 +373,5 @@ def _write_template_to_file(self, template, data, output_name):

content = template.render(data)
if content != "":
with open(output_name, "w") as f:
with open(output_name, "w", encoding="utf-8") as f:
f.write(content)
17 changes: 8 additions & 9 deletions semantic-conventions/src/tests/semconv/templating/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_codegen_units(test_file_path, read_test_file):

filename = os.path.join(tempfile.mkdtemp(), "Attributes.java")
renderer.render(semconv, template_path, filename, None)
with open(filename) as f:
with open(filename, "r", encoding="utf-8") as f:
result = f.read()

expected = read_test_file("jinja", "metrics", "expected.java")
Expand All @@ -36,7 +36,7 @@ def test_strip_blocks_enabled(test_file_path, read_test_file):

filename = os.path.join(tempfile.mkdtemp(), "Attributes.java")
renderer.render(semconv, template_path, filename, None)
with open(filename) as f:
with open(filename, "r", encoding="utf-8") as f:
result = f.read()

expected = read_test_file(
Expand All @@ -58,7 +58,7 @@ def test_codegen_attribute_templates(test_file_path, read_test_file):

filename = os.path.join(tempfile.mkdtemp(), "Attributes.java")
renderer.render(semconv, template_path, filename, None)
with open(filename) as f:
with open(filename, "r", encoding="utf-8") as f:
result = f.read()
expected = read_test_file("jinja", "attribute_templates", "expected.java")

Expand Down Expand Up @@ -134,8 +134,8 @@ def test_codegen_attribute_root_ns_no_group_prefix(test_file_path, read_test_fil
"root_namespace",
)

foo = read_test_file("jinja", test_path, "FooAttributes.java")
check_file(tmppath, "FooAttributes.java", foo)
res = read_test_file("jinja", test_path, "FooAttributes.java")
check_file(tmppath, "FooAttributes.java", res)

other = read_test_file("jinja", test_path, "OtherAttributes.java")
check_file(tmppath, "OtherAttributes.java", other)
Expand All @@ -154,8 +154,8 @@ def test_codegen_attribute_root_ns_single_file(test_file_path, read_test_file):
tmppath = tempfile.mkdtemp()
renderer.render(semconv, template_path, os.path.join(tmppath, "All.java"), None)

all = read_test_file("jinja", test_path, "All.java")
check_file(tmppath, "All.java", all)
result = read_test_file("jinja", test_path, "All.java")
check_file(tmppath, "All.java", result)


def test_codegen_attribute_root_ns_metrics(test_file_path, read_test_file):
Expand All @@ -181,7 +181,6 @@ def test_codegen_attribute_root_ns_metrics(test_file_path, read_test_file):


def check_file(tmppath, actual_filename, expected_content):
with open(os.path.join(tmppath, actual_filename)) as f:
with open(os.path.join(tmppath, actual_filename), "r", encoding="utf-8") as f:
actual = f.read()
print(actual)
assert actual == expected_content

0 comments on commit 510f528

Please sign in to comment.