Skip to content

Commit

Permalink
Update formatting #411 #438
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed Jun 9, 2022
1 parent 552bdb8 commit 155fe97
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
3 changes: 1 addition & 2 deletions scanpipe/pipes/rootfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ def has_hash_diff(install_file, codebase_resource):
# Find a suitable hash type that is present on both install_file and
# codebase_resource, skip otherwise.
if not (
hasattr(install_file, hash_type)
and hasattr(codebase_resource, hash_type)
hasattr(install_file, hash_type) and hasattr(codebase_resource, hash_type)
):
continue

Expand Down
20 changes: 6 additions & 14 deletions scanpipe/pipes/scancode.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,7 @@ def create_codebase_resources(project, scanned_codebase):
# associate DiscoveredPackage to Resource, if applicable
if hasattr(scanned_resource, "for_packages"):
for package_uid in scanned_resource.for_packages:
package = DiscoveredPackage.objects.get(
package_uid=package_uid
)
package = DiscoveredPackage.objects.get(package_uid=package_uid)
set_codebase_resource_for_package(
codebase_resource=cbr, discovered_package=package
)
Expand Down Expand Up @@ -475,10 +473,7 @@ def make_results_summary(project, scan_results_location):

# Inject the `key_files` and their file content in the summary
key_files = []
key_files_qs = (
project.codebaseresources
.filter(is_key_file=True, is_text=True)
)
key_files_qs = project.codebaseresources.filter(is_key_file=True, is_text=True)

for resource in key_files_qs:
resource_data = CodebaseResourceSerializer(resource).data
Expand All @@ -488,14 +483,11 @@ def make_results_summary(project, scan_results_location):
summary["key_files"] = key_files

# Inject the `key_files_packages` filtered from the key_files_qs
key_files_packages_qs = (
project.discoveredpackages
.filter(codebase_resources__in=key_files_qs)
.distinct()
)
key_files_packages_qs = project.discoveredpackages.filter(
codebase_resources__in=key_files_qs
).distinct()
key_files_packages = [
DiscoveredPackageSerializer(package).data
for package in key_files_packages_qs
DiscoveredPackageSerializer(package).data for package in key_files_packages_qs
]
summary["key_files_packages"] = key_files_packages

Expand Down
16 changes: 8 additions & 8 deletions scanpipe/tests/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,13 @@ def _normalize_package_uids(self, data):
and value
):
value = purl_with_fake_uuid(value)
if key == 'for_packages':
value = [
purl_with_fake_uuid(package_uid)
for package_uid in value
]
if key == "for_packages":
value = [purl_with_fake_uuid(package_uid) for package_uid in value]
normalized_data[key] = value
return normalized_data

return data


def assertPipelineResultEqual(self, expected_file, result_file, regen=False):
"""
Set `regen` to True to regenerate the expected results.
Expand Down Expand Up @@ -323,7 +319,9 @@ def test_scanpipe_scan_package_pipeline_integration_test(self):
self.assertEqual("pkg:npm/is-npm@1.0.0", key_file_package_purl)

@skipIf(from_docker_image, "Random failure in the Docker context.")
def test_scanpipe_scan_package_pipeline_integration_test_multiple_package_instances(self):
def test_scanpipe_scan_package_pipeline_integration_test_multiple_package_instances(
self,
):
pipeline_name = "scan_package"
project1 = Project.objects.create(name="Analysis")

Expand All @@ -344,7 +342,9 @@ def test_scanpipe_scan_package_pipeline_integration_test_multiple_package_instan
self.assertPipelineResultEqual(expected_file, scancode_file, regen=False)

summary_file = project1.get_latest_output(filename="summary")
expected_file = self.data_location / "multiple-is-npm-1.0.0_scan_package_summary.json"
expected_file = (
self.data_location / "multiple-is-npm-1.0.0_scan_package_summary.json"
)
self.assertPipelineResultEqual(expected_file, summary_file, regen=False)

def test_scanpipe_scan_codebase_pipeline_integration_test(self):
Expand Down
4 changes: 3 additions & 1 deletion scanpipe/tests/test_pipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,9 @@ def test_scanpipe_pipes_scancode_make_results_summary(self):
summary = scancode.make_results_summary(project, scan_results_location)
self.assertEqual(10, len(summary.keys()))

scan_results_location = self.data_location / "multiple-is-npm-1.0.0_scan_package.json"
scan_results_location = (
self.data_location / "multiple-is-npm-1.0.0_scan_package.json"
)
summary = scancode.make_results_summary(project, scan_results_location)
self.assertEqual(10, len(summary.keys()))

Expand Down

0 comments on commit 155fe97

Please sign in to comment.