@@ -654,6 +654,73 @@ def test_determine_license_diff_copyleft_to_copyleft_limited(self):
654654 assert len (test_delta .factors ) == 1
655655 assert 'license change' in test_delta .factors
656656
657+ def test_determine_license_diff_file_added_permissive_license (self ):
658+ test_file_new = models .File ({
659+ 'path' :'/test/path.txt' ,
660+ 'name' : 'path.txt' ,
661+ 'sha1' : 'a' ,
662+ 'original_path' : '' ,
663+ "licenses" : [
664+ {
665+ "key" : "mit" ,
666+ "score" : 80.0 ,
667+ "short_name" : "MIT License" ,
668+ "category" : "Permissive"
669+ }
670+ ]
671+ })
672+
673+ test_delta = deltacode .Delta (100 , test_file_new , None )
674+
675+ utils .determine_license_diff (test_delta , unique_categories )
676+
677+ assert test_delta .score == 120
678+ assert len (test_delta .factors ) == 1
679+
680+ assert 'license info added' in test_delta .factors
681+
682+ def test_determine_license_diff_file_added_commercial_and_copyleft_licenses (self ):
683+ test_file_new = models .File ({
684+ 'path' :'/test/path.txt' ,
685+ 'name' : 'path.txt' ,
686+ 'sha1' : 'a' ,
687+ 'original_path' : '' ,
688+ "licenses" : [
689+ {
690+ "key" : "commercial-license" ,
691+ "score" : 55.0 ,
692+ "short_name" : "Commercial License" ,
693+ "category" : "Commercial" ,
694+ "owner" : "Unspecified"
695+ },
696+ {
697+ "key" : "adapt-1.0" ,
698+ "score" : 15.0 ,
699+ "short_name" : "APL 1.0" ,
700+ "category" : "Copyleft" ,
701+ "owner" : "OSI - Open Source Initiative"
702+ }
703+ ]
704+ })
705+
706+ test_delta = deltacode .Delta (100 , test_file_new , None )
707+
708+ utils .determine_license_diff (test_delta , unique_categories )
709+
710+ assert test_delta .score == 160
711+ assert len (test_delta .factors ) == 3
712+
713+ assert 'license info added' in test_delta .factors
714+
715+ expected_factors = [
716+ 'license info added' ,
717+ 'commercial added' ,
718+ 'copyleft added'
719+ ]
720+
721+ for factor in expected_factors :
722+ assert factor in test_delta .factors
723+
657724 def test_determine_copyright_diff_empty (self ):
658725 test_delta = deltacode .Delta ()
659726
@@ -1016,6 +1083,32 @@ def test_determine_copyright_diff_one_copyright_removed(self):
10161083 assert len (test_delta .factors ) == 1
10171084 assert 'copyright change' in test_delta .factors
10181085
1086+ def test_determine_copyright_diff_file_added_one_copyright (self ):
1087+ test_file_new = models .File ({
1088+ 'path' :'/test/path.txt' ,
1089+ 'name' : 'path.txt' ,
1090+ 'sha1' : 'a' ,
1091+ 'original_path' : '' ,
1092+ "copyrights" : [
1093+ {
1094+ "statements" : [
1095+ "Copyright (c) 2017-2018 Francois Hennebique and others."
1096+ ],
1097+ "holders" : [
1098+ "Francois Hennebique and others."
1099+ ]
1100+ }
1101+ ]
1102+ })
1103+
1104+ test_delta = deltacode .Delta (100 , test_file_new , None )
1105+
1106+ utils .determine_copyright_diff (test_delta )
1107+
1108+ assert test_delta .score == 110
1109+ assert len (test_delta .factors ) == 1
1110+ assert 'copyright info added' in test_delta .factors
1111+
10191112 def test_determine_lic_copy_diffs_copyright_and_license_info_added (self ):
10201113 test_file_new = models .File ({
10211114 'path' :'/test/path.txt' ,
@@ -1352,6 +1445,98 @@ def test_determine_lic_copy_diffs_license_change_no_copyright_change(self):
13521445 for factor in expected_factors :
13531446 assert factor in test_delta .factors
13541447
1448+ def test_determine_lic_copy_diffs_file_added_copyright_and_permissive_license (self ):
1449+ test_file_new = models .File ({
1450+ 'path' :'/test/path.txt' ,
1451+ 'name' : 'path.txt' ,
1452+ 'sha1' : 'a' ,
1453+ 'original_path' : '' ,
1454+ "licenses" : [
1455+ {
1456+ "key" : "mit" ,
1457+ "score" : 80.0 ,
1458+ "short_name" : "MIT License" ,
1459+ "category" : "Permissive"
1460+ }
1461+ ],
1462+ "copyrights" : [
1463+ {
1464+ "statements" : [
1465+ "Copyright (c) 2017-2018 Francois Hennebique and others."
1466+ ],
1467+ "holders" : [
1468+ "Francois Hennebique and others."
1469+ ]
1470+ }
1471+ ]
1472+ })
1473+
1474+ test_delta = deltacode .Delta (100 , test_file_new , None )
1475+
1476+ utils .determine_license_diff (test_delta , unique_categories )
1477+ utils .determine_copyright_diff (test_delta )
1478+
1479+ expected_factors = [
1480+ 'license info added' ,
1481+ 'copyright info added'
1482+ ]
1483+
1484+ assert test_delta .score == 130
1485+ assert len (test_delta .factors ) == 2
1486+ for factor in expected_factors :
1487+ assert factor in test_delta .factors
1488+
1489+ def test_determine_lic_copy_diffs_file_added_copyright_and_commercial_and_copyleft_licenses (self ):
1490+ test_file_new = models .File ({
1491+ 'path' :'/test/path.txt' ,
1492+ 'name' : 'path.txt' ,
1493+ 'sha1' : 'a' ,
1494+ 'original_path' : '' ,
1495+ "licenses" : [
1496+ {
1497+ "key" : "commercial-license" ,
1498+ "score" : 55.0 ,
1499+ "short_name" : "Commercial License" ,
1500+ "category" : "Commercial" ,
1501+ "owner" : "Unspecified"
1502+ },
1503+ {
1504+ "key" : "adapt-1.0" ,
1505+ "score" : 15.0 ,
1506+ "short_name" : "APL 1.0" ,
1507+ "category" : "Copyleft" ,
1508+ "owner" : "OSI - Open Source Initiative"
1509+ }
1510+ ],
1511+ "copyrights" : [
1512+ {
1513+ "statements" : [
1514+ "Copyright (c) 2017-2018 Francois Hennebique and others."
1515+ ],
1516+ "holders" : [
1517+ "Francois Hennebique and others."
1518+ ]
1519+ }
1520+ ]
1521+ })
1522+
1523+ test_delta = deltacode .Delta (100 , test_file_new , None )
1524+
1525+ utils .determine_license_diff (test_delta , unique_categories )
1526+ utils .determine_copyright_diff (test_delta )
1527+
1528+ expected_factors = [
1529+ 'license info added' ,
1530+ 'commercial added' ,
1531+ 'copyleft added' ,
1532+ 'copyright info added'
1533+ ]
1534+
1535+ assert test_delta .score == 170
1536+ assert len (test_delta .factors ) == 4
1537+ for factor in expected_factors :
1538+ assert factor in test_delta .factors
1539+
13551540 def test_align_trees_simple (self ):
13561541 test_scan_new = self .get_test_loc ('utils/align-trees-simple-new.json' )
13571542 # Our old scan uses --full-root option in scancode
0 commit comments