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-487] add tests for the document_utils.py module #533

Merged
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
28 changes: 28 additions & 0 deletions tests/spdx/test_document_utils.py
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])
Copy link
Collaborator

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.

Copy link
Collaborator Author

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 lists

Copy link
Collaborator

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



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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there is no matching element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return None, I will add this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assert get_element_from_spdx_id(document, "unknown_id") is None