Skip to content

Commit

Permalink
Split old and new summarizer code
Browse files Browse the repository at this point in the history
    * Remove summarizer2.py

Reference: #2842
Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed Apr 5, 2022
1 parent 976ea12 commit 8c807ea
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 307 deletions.
30 changes: 0 additions & 30 deletions src/summarycode/legacy_summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,6 @@ def logger_debug(*args):
"""


@post_scan_impl
class ScanSummary(PostScanPlugin):
"""
Summarize a scan at the codebase level.
"""
sort_order = 10

codebase_attributes = dict(summary=attr.ib(default=attr.Factory(dict)))

options = [
PluggableCommandLineOption(('--summary',),
is_flag=True, default=False,
help='Summarize license, copyright and other scans at the codebase level.',
help_group=POST_SCAN_GROUP,
required_options=['classify', 'license_clarity_score']
)
]

def is_enabled(self, summary, **kwargs):
return summary

def process_codebase(self, codebase, summary, **kwargs):
if TRACE_LIGHT: logger_debug('ScanSummary:process_codebase')
summary = summarize_codebase(codebase, keep_details=False, **kwargs)
declared_holders = get_declared_holders(codebase, summary)
codebase.attributes.summary['declared_holders'] = declared_holders
codebase.attributes.summary['primary_programming_language'] = get_primary_language(summary)
remove_declared_from_fields(codebase, summary)


class SummaryLegacyPluginDeprecationWarning(DeprecationWarning):
pass

Expand Down
159 changes: 0 additions & 159 deletions src/summarycode/summarizer2.py

This file was deleted.

141 changes: 141 additions & 0 deletions tests/summarycode/test_legacy_summarizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://github.com/nexB/scancode-toolkit for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#


from os import path

import pytest

from commoncode.testcase import FileDrivenTesting

from scancode.cli_test_utils import check_json_scan
from scancode.cli_test_utils import check_jsonlines_scan
from scancode.cli_test_utils import run_scan_click
from scancode_config import REGEN_TEST_FIXTURES


pytestmark = pytest.mark.scanslow


class TestScanSummaryLegacy(FileDrivenTesting):

test_data_dir = path.join(path.dirname(__file__), 'data')

def test_copyright_summary_base(self):
test_dir = self.get_test_loc('summary_legacy/copyright_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/copyright_summary/summary.expected.json')
run_scan_click(['-c', '--summary-legacy', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_copyright_summary_with_details(self):
test_dir = self.get_test_loc('summary_legacy/copyright_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/copyright_summary/summary_details.expected.json')
run_scan_click(['-c', '--summary-with-details', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_copyright_summary_with_details_plain_json(self):
test_dir = self.get_test_loc('summary_legacy/copyright_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/copyright_summary/summary_details.expected2.json')
run_scan_click(['-c', '--summary-with-details', '--json', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_copyright_summary_does_not_crash(self):
test_dir = self.get_test_loc('summary_legacy/copyright_summary/scan2')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/copyright_summary/summary2.expected.json')
run_scan_click(['-c', '--summary-legacy', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_full_summary_base(self):
test_dir = self.get_test_loc('summary_legacy/full_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/full_summary/summary.expected.json')
run_scan_click(['-clip', '--summary-legacy', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_instance_uuid=True, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_full_summary_with_details(self):
test_dir = self.get_test_loc('summary_legacy/full_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/full_summary/summary_details.expected.json')
run_scan_click(['-clip', '--summary-with-details', '--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_instance_uuid=True, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_copyright_summary_key_files(self):
test_dir = self.get_test_loc('summary_legacy/copyright_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/copyright_summary/summary_key_files.expected.json')
run_scan_click(
['-c', '-i', '--classify', '--summary-legacy', '--summary-key-files',
'--json-pp', result_file, test_dir])

check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_full_summary_key_files(self):
test_dir = self.get_test_loc('summary_legacy/full_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/full_summary/summary_key_files.expected.json')
run_scan_click(
['-cli', '--classify', '--summary-legacy', '--summary-key-files',
'--json-pp', result_file, test_dir])
check_json_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_full_summary_key_files_json_lines(self):
test_dir = self.get_test_loc('summary_legacy/full_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/full_summary/summary_key_files-details.expected.json-lines')
run_scan_click(
['-cli', '--classify', '--summary-legacy', '--summary-key-files',
'--json-lines', result_file, test_dir])
check_jsonlines_scan(expected_file, result_file, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_full_summary_by_facet(self):
test_dir = self.get_test_loc('summary_legacy/full_summary/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/full_summary/summary_by_facet.expected.json')
run_scan_click([
'-clpieu',
'--facet', 'dev=*.java',
'--facet', 'dev=*.cs',
'--facet', 'dev=*ada*',
'--facet', 'data=*.S',
'--facet', 'tests=*infback9*',
'--facet', 'docs=*README',
'--summary-legacy',
'--summary-by-facet',
'--json-pp', result_file, test_dir
])
check_json_scan(expected_file, result_file, remove_instance_uuid=True, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_end2end_summary_and_classify_works_with_empty_dir_and_empty_values(self):
test_dir = self.extract_test_tar('summary_legacy/end-2-end/bug-1141.tar.gz')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/end-2-end/bug-1141.expected.json')
run_scan_click([
'-clip',
'--classify',
'--facet', 'dev=*.java',
'--summary-legacy',
'--summary-key-files',
'--json-pp', result_file, test_dir
])
check_json_scan(expected_file, result_file, remove_instance_uuid=True, remove_file_date=True, regen=REGEN_TEST_FIXTURES)

def test_summary_with_packages_reports_packages_with_files(self):
test_dir = self.get_test_loc('summary_legacy/packages/scan')
result_file = self.get_temp_file('json')
expected_file = self.get_test_loc('summary_legacy/packages/expected.json')
run_scan_click([
'--package',
'--summary-legacy',
'--json-pp', result_file, test_dir
])
check_json_scan(expected_file, result_file, remove_instance_uuid=True, remove_file_date=True, regen=REGEN_TEST_FIXTURES)
Loading

0 comments on commit 8c807ea

Please sign in to comment.