Skip to content

Commit

Permalink
Update tests for copyright_tallies.py
Browse files Browse the repository at this point in the history
    * Remove copyright_summary.py
    * Update summarizer help text

Reference: #2842
Signed-off-by: Jono Yang <jyang@nexb.com>
  • Loading branch information
JonoYang committed Apr 14, 2022
1 parent b562e3f commit be6b2a1
Show file tree
Hide file tree
Showing 3,153 changed files with 6,243 additions and 6,822 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
577 changes: 0 additions & 577 deletions src/summarycode/copyright_summary.py

This file was deleted.

10 changes: 5 additions & 5 deletions src/summarycode/plugin_consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from packagedcode.utils import combine_expressions
from plugincode.post_scan import PostScanPlugin
from plugincode.post_scan import post_scan_impl
from summarycode import copyright_summary
from summarycode import copyright_tallies

# Tracing flags
TRACE = False
Expand Down Expand Up @@ -289,10 +289,10 @@ def get_consolidated_packages(codebase):
c = Consolidation(
core_license_expression=package_license_expression,
# Sort holders by holder key
core_holders=[h for h, _ in sorted(copyright_summary.cluster(package_holders), key=lambda t: t[0].key)],
core_holders=[h for h, _ in sorted(copyright_tallies.cluster(package_holders), key=lambda t: t[0].key)],
other_license_expression=simplified_discovered_license_expression,
# Sort holders by holder key
other_holders=[h for h, _ in sorted(copyright_summary.cluster(discovered_holders), key=lambda t: t[0].key)],
other_holders=[h for h, _ in sorted(copyright_tallies.cluster(discovered_holders), key=lambda t: t[0].key)],
files_count=len([package_resource for package_resource in package_resources if package_resource.is_file]),
resources=package_resources,
)
Expand All @@ -310,12 +310,12 @@ def get_consolidated_packages(codebase):


def process_holders(holders):
holders = [copyright_summary.Text(key=holder, original=holder) for holder in holders]
holders = [copyright_tallies.Text(key=holder, original=holder) for holder in holders]

for holder in holders:
holder.normalize()

holders = list(copyright_summary.filter_junk(holders))
holders = list(copyright_tallies.filter_junk(holders))

for holder in holders:
holder.normalize()
Expand Down
7 changes: 5 additions & 2 deletions src/summarycode/summarizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ class ScanSummary(PostScanPlugin):

options = [
PluggableCommandLineOption(('--summary',),
is_flag=True, default=False,
help='Summarize license, copyright and other scans at the codebase level.',
is_flag=True,
default=False,
help='Summarize scans by providing declared origin '
'information and other detected origin info at the '
'codebase attribute level.',
help_group=POST_SCAN_GROUP,
required_options=['classify']
)
Expand Down
46 changes: 23 additions & 23 deletions tests/cluecode/cluecode_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class CopyrightTest(object):
holders = attr.ib(default=attr.Factory(list))
authors = attr.ib(default=attr.Factory(list))

holders_summary = attr.ib(default=attr.Factory(list))
copyrights_summary = attr.ib(default=attr.Factory(list))
authors_summary = attr.ib(default=attr.Factory(list))
holders_tallies = attr.ib(default=attr.Factory(list))
copyrights_tallies = attr.ib(default=attr.Factory(list))
authors_tallies = attr.ib(default=attr.Factory(list))

expected_failures = attr.ib(default=attr.Factory(list))
notes = attr.ib(default=None)
Expand All @@ -83,14 +83,14 @@ def __attrs_post_init__(self, *args, **kwargs):
raise Exception(msg)

# fix counts to be ints: saneyaml loads everything as string
for holders_sum in self.holders_summary:
holders_sum['count'] = int(holders_sum['count'])
for holders_tally in self.holders_tallies:
holders_tally['count'] = int(holders_tally['count'])

for copyrs_sum in self.copyrights_summary:
copyrs_sum['count'] = int(copyrs_sum['count'])
for copyrs_tally in self.copyrights_tallies:
copyrs_tally['count'] = int(copyrs_tally['count'])

for auths_sum in self.authors_summary:
auths_sum['count'] = int(auths_sum['count'])
for auths_tally in self.authors_tallies:
auths_tally['count'] = int(auths_tally['count'])

def to_dict(self):
"""
Expand Down Expand Up @@ -175,32 +175,32 @@ def make_copyright_test_functions(
name. Create only a single function for multiple tests (e.g. copyrights and
holders together).
"""
from summarycode.copyright_summary import summarize_copyrights
from summarycode.copyright_summary import summarize_persons
from summarycode.copyright_tallies import tally_copyrights
from summarycode.copyright_tallies import tally_persons

def closure_test_function(*args, **kwargs):
detections = detect_copyrights(test_file)
copyrights, holders, authors = Detection.split_values(detections)

holders_summary = []
if 'holders_summary' in test.what:
holders_summary = as_sorted_mapping(summarize_persons(holders))
holders_tallies = []
if 'holders_tallies' in test.what:
holders_tallies = as_sorted_mapping(tally_persons(holders))

copyrights_summary = []
if 'copyrights_summary' in test.what:
copyrights_summary = as_sorted_mapping(summarize_copyrights(copyrights))
copyrights_tallies = []
if 'copyrights_tallies' in test.what:
copyrights_tallies = as_sorted_mapping(tally_copyrights(copyrights))

authors_summary = []
if 'authors_summary' in test.what:
authors_summary = as_sorted_mapping(summarize_persons(authors))
authors_tallies = []
if 'authors_tallies' in test.what:
authors_tallies = as_sorted_mapping(tally_persons(authors))

results = dict(
copyrights=copyrights,
authors=authors,
holders=holders,
holders_summary=holders_summary,
copyrights_summary=copyrights_summary,
authors_summary=authors_summary,
holders_tallies=holders_tallies,
copyrights_tallies=copyrights_tallies,
authors_tallies=authors_tallies,
)

expected_yaml = test.dumps()
Expand Down
4 changes: 2 additions & 2 deletions tests/cluecode/data/authors/author-config.rpath.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Gordon Matzigkeit <gord@gnu.ai.mit.edu>
authors_summary:
authors_tallies:
- value: Gordon Matzigkeit <gord@gnu.ai.mit.edu>
count: 1
4 changes: 2 additions & 2 deletions tests/cluecode/data/authors/author_addr_c-addr_c.c.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- John Doe
authors_summary:
authors_tallies:
- value: John Doe
count: 1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Avinash Kak (kak@purdue.edu)
- Avinash Kak (kak@purdue.edu)
authors_summary:
authors_tallies:
- value: Avinash Kak (kak@purdue.edu)
count: 2
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Avinash Kak (kak@purdue.edu)
- Avinash Kak (kak@purdue.edu)
authors_summary:
authors_tallies:
- value: Avinash Kak (kak@purdue.edu)
count: 2
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- the University of California, Berkeley and its contributors
authors_summary:
authors_tallies:
- value: the University of California, Berkeley and its contributors
count: 1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Gordon Matzigkeit
authors_summary:
authors_tallies:
- value: Gordon Matzigkeit
count: 1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Mohit Agarwal
- Mitsubishi and NTT.
authors_summary:
authors_tallies:
- value: Mitsubishi and NTT.
count: 1
- value: Mohit Agarwal
Expand Down
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_expat-expat_h.h.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Gary O'Neall
authors_summary:
authors_tallies:
- value: Gary O'Neall
count: 1
4 changes: 2 additions & 2 deletions tests/cluecode/data/authors/author_gthomas_c-c.c.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- gthomas, sorin@netappi.com
- gthomas, sorin@netappi.com, andrew.lunn@ascom.ch
authors_summary:
authors_tallies:
- value: gthomas, sorin@netappi.com
count: 1
- value: gthomas, sorin@netappi.com, andrew.lunn@ascom.ch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Scott Violet
authors_summary:
authors_tallies:
- value: Scott Violet
count: 1
4 changes: 2 additions & 2 deletions tests/cluecode/data/authors/author_in_java_tag-java.java.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Apple Banana Car
authors_summary:
authors_tallies:
- value: Apple Banana Car
count: 1
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
4 changes: 2 additions & 2 deletions tests/cluecode/data/authors/author_iproute2.c.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Patrick McHardy <kaber@trash.net>
authors_summary:
authors_tallies:
- value: Patrick McHardy <kaber@trash.net>
count: 1
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_nathan-KEYS.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
what:
- authors
- authors_summary
- authors_tallies
notes: |
name +email is not enough to create an author
hence this is not detected correctly
Expand Down
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_no_author-c.c.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_none-wrong.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_none_c-c.c.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- not attributable
authors_summary:
authors_tallies:
- value: not attributable
count: 1
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_russ_c-c.c.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
what:
- authors
- authors_summary
- authors_tallies
notes: these are detected as copyrights, not authors Russ Dill <Russ.Dill@asu.edu> Vladimir
Oleynik <dzo@simtreas.ru>
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_sample-c.c.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_samplepy-py.py.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
2 changes: 1 addition & 1 deletion tests/cluecode/data/authors/author_snippet.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
what:
- authors
- authors_summary
- authors_tallies
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- faith@dict.org
authors_summary:
authors_tallies:
- value: faith@dict.org
count: 1
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
what:
- authors
- authors_summary
- authors_tallies
authors:
- Philip Milne
- Scott Violet
authors_summary:
authors_tallies:
- value: Philip Milne
count: 1
- value: Scott Violet
Expand Down
Loading

0 comments on commit be6b2a1

Please sign in to comment.