Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[issue-798] fix tag-value parser: parse Tool or Organization as annotator #799

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/spdx_tools/spdx/parser/tagvalue/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def p_snippet_range(self, p):

# parsing methods for annotation

@grammar_rule("annotator : ANNOTATOR PERSON_VALUE\n| TOOL_VALUE\n| ORGANIZATION_VALUE")
@grammar_rule("annotator : ANNOTATOR PERSON_VALUE\n| ANNOTATOR TOOL_VALUE\n| ANNOTATOR ORGANIZATION_VALUE")
def p_annotator(self, p):
self.initialize_new_current_element(Annotation)
set_value(p, self.current_element, method_to_apply=ActorParser.parse_actor)
Expand Down
22 changes: 22 additions & 0 deletions tests/spdx/parser/tagvalue/test_annotation_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ def test_parse_annotation():
assert annotation.spdx_id == DOCUMENT_SPDX_ID


def test_parse_annotation_with_organization_as_annotator():
parser = Parser()
annotation_str = "\n".join(
[
"Annotator: Organization: some-organization",
"AnnotationDate: 2010-01-29T18:30:22Z",
"AnnotationComment: <text>Document level annotation</text>",
"AnnotationType: OTHER",
f"SPDXREF: {DOCUMENT_SPDX_ID}",
]
)
document = parser.parse("\n".join([DOCUMENT_STR, annotation_str]))
assert document is not None
assert len(document.annotations) == 1
annotation = document.annotations[0]
assert annotation.annotator.name == "some-organization"
assert annotation.annotation_date == datetime(2010, 1, 29, 18, 30, 22)
assert annotation.annotation_comment == "Document level annotation"
assert annotation.annotation_type == AnnotationType.OTHER
assert annotation.spdx_id == DOCUMENT_SPDX_ID


@pytest.mark.parametrize(
"annotation_str, expected_message",
[
Expand Down
Loading