Skip to content

Commit

Permalink
Fix of linting and formatting errors
Browse files Browse the repository at this point in the history
Signed-off-by: Gergely Csatari <[email protected]>
  • Loading branch information
CsatariGergely committed Dec 28, 2023
1 parent 93b983c commit dc3c53d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
8 changes: 4 additions & 4 deletions ntia_conformance_checker/sbom_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ def get_components_without_names(self):
components_without_names.append(package.spdx_id)
return components_without_names

def get_components_without_versions(self, returnTuples=False):
def get_components_without_versions(self, return_tuples=False):
"""Retrieve name and/or SPDX ID of components without versions."""
components_without_versions = []
for package in self.doc.packages:
if not package.version:
if returnTuples:
if return_tuples:
components_without_versions.append((package.name, package.spdx_id))
else:
components_without_versions.append(package.name)
return components_without_versions

def get_components_without_suppliers(self, returnTuples=False):
def get_components_without_suppliers(self, return_tuples=False):
"""Retrieve name and/or SPDX ID of components without suppliers."""
components_without_suppliers = []
for package in self.doc.packages:
Expand All @@ -99,7 +99,7 @@ def get_components_without_suppliers(self, returnTuples=False):
package.originator, SpdxNoAssertion
)
if no_package_supplier and no_package_originator:
if returnTuples:
if return_tuples:
components_without_suppliers.append((package.name, package.spdx_id))
else:
components_without_suppliers.append(package.name)
Expand Down
31 changes: 15 additions & 16 deletions tests/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@

import ntia_conformance_checker.sbom_checker as sbom_checker

import logging

logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)

dirname = os.path.join(os.path.dirname(__file__), "data", "no_elements_missing")
test_files = [os.path.join(dirname, fn) for fn in os.listdir(dirname)]

Expand Down Expand Up @@ -233,24 +227,29 @@ def test_sbomchecker_output_html():

assert got == expected


def test_components_without_functions():
logger = logging.getLogger(__name__)
logger.info("In test")
filepath = os.path.join(
os.path.dirname(__file__), "data", "other_tests", "test_components_without_functions.spdx"
os.path.dirname(__file__),
"data",
"other_tests",
"test_components_without_functions.spdx",
)
sbom = sbom_checker.SbomChecker(filepath)
components = sbom.get_components_without_names()
assert components == ["SPDXRef-Package1"]
components = sbom.get_components_without_versions()
assert components == ["glibc-no-version-1", "glibc-no-version-2"]
components = sbom.get_components_without_versions(returnTuples=True)
assert components == [("glibc-no-version-1", "SPDXRef-Package2"),
("glibc-no-version-2", "SPDXRef-Package3")]
components = sbom.get_components_without_versions(return_tuples=True)
assert components == [
("glibc-no-version-1", "SPDXRef-Package2"),
("glibc-no-version-2", "SPDXRef-Package3"),
]
components = sbom.get_components_without_suppliers()
assert components == ["glibc-no-supplier"]
components = sbom.get_components_without_suppliers(returnTuples=True)
components = sbom.get_components_without_suppliers(return_tuples=True)
assert components == [("glibc-no-supplier", "SPDXRef-Package4")]
# TODO: Not sure how to test this. If any package misses the SPDXID the whole file seems to be invalid.
#components = sbom.get_components_without_identifiers()
#assert components == ["glibc-no-identifier"]
# Not sure how to test this. If any package misses the SPDXID the whole file seems to be
# invalid.
# components = sbom.get_components_without_identifiers()
# assert components == ["glibc-no-identifier"]

0 comments on commit dc3c53d

Please sign in to comment.