-
Notifications
You must be signed in to change notification settings - Fork 135
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-487] add tests for the document_utils.py
module
#533
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# SPDX-FileCopyrightText: 2023 spdx contributors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
from unittest import TestCase | ||
|
||
import pytest | ||
|
||
from spdx.document_utils import get_element_from_spdx_id, get_contained_spdx_element_ids | ||
from tests.spdx.fixtures import document_fixture, snippet_fixture, package_fixture, file_fixture | ||
|
||
|
||
@pytest.fixture | ||
def variables(): | ||
return document_fixture(), package_fixture(), file_fixture(), snippet_fixture() | ||
|
||
|
||
def test_contained_element_ids(variables): | ||
document, package, file, snippet = variables | ||
element_ids = get_contained_spdx_element_ids(document) | ||
TestCase().assertCountEqual(element_ids, [package.spdx_id, file.spdx_id, snippet.spdx_id]) | ||
|
||
|
||
def test_get_element_from_spdx_id(variables): | ||
document, package, file, snippet = variables | ||
assert get_element_from_spdx_id(document, package.spdx_id) == package | ||
assert get_element_from_spdx_id(document, file.spdx_id) == file | ||
assert get_element_from_spdx_id(document, snippet.spdx_id) == snippet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if there is no matching element? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
assert get_element_from_spdx_id(document, "unknown_id") is None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also check that no other element is contained? The test relies on the fact that
document_fixture
only contains the respective elements from the fixtures.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertCountEqual()
already tests that there exactly the same elements (with multiplicity) in the listsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh, true, my brain is still on vacation :D