@@ -1483,6 +1483,7 @@ def test_Delta_create_object_removed(self):
14831483 assert type (delta .new_file ) == type (models .File ())
14841484 assert delta .old_file .path == 'path/removed.txt'
14851485 assert delta .category == 'removed'
1486+ assert delta .score == 25
14861487
14871488 def test_Delta_create_object_added (self ):
14881489 new = models .File ({'path' : 'path/added.txt' })
@@ -1493,6 +1494,7 @@ def test_Delta_create_object_added(self):
14931494 assert delta .new_file .path == 'path/added.txt'
14941495 assert type (delta .old_file ) == type (models .File ())
14951496 assert delta .category == 'added'
1497+ assert delta .score == 75
14961498
14971499 def test_Delta_create_object_modified (self ):
14981500 new = models .File ({'path' : 'path/modified.txt' , 'sha1' : 'a' })
@@ -1505,6 +1507,7 @@ def test_Delta_create_object_modified(self):
15051507 assert delta .old_file .path == 'path/modified.txt'
15061508 assert delta .old_file .sha1 == 'b'
15071509 assert delta .category == 'modified'
1510+ assert delta .score == 50
15081511
15091512 def test_Delta_create_object_unmodified (self ):
15101513 new = models .File ({'path' : 'path/unmodified.txt' , 'sha1' : 'a' })
@@ -1517,6 +1520,7 @@ def test_Delta_create_object_unmodified(self):
15171520 assert delta .old_file .path == 'path/unmodified.txt'
15181521 assert delta .old_file .sha1 == 'a'
15191522 assert delta .category == 'unmodified'
1523+ assert delta .score == 0
15201524
15211525 def test_Delta_create_object_moved (self ):
15221526 new = models .File ({'path' : 'path_new/moved.txt' , 'sha1' : 'a' })
@@ -1529,10 +1533,56 @@ def test_Delta_create_object_moved(self):
15291533 assert delta .old_file .path == 'path_old/moved.txt'
15301534 assert delta .old_file .sha1 == 'a'
15311535 assert delta .category == 'moved'
1536+ assert delta .score == 0
15321537
15331538 def test_Delta_create_object_empty (self ):
15341539 delta = deltacode .Delta ()
15351540
15361541 assert type (delta .new_file ) == type (models .File ())
15371542 assert type (delta .old_file ) == type (models .File ())
15381543 assert delta .category == ''
1544+
1545+ def test_Delta_determine_score_new_no_license_info (self ):
1546+ new_file = models .File ({'path' : 'new/path.txt' })
1547+ old_file = models .File ({'path' : 'old/path.txt' , 'licenses' : [{'key' : 'mit' , 'score' : 50.0 }]})
1548+
1549+ result = deltacode .Delta (new_file , old_file , 'modified' )
1550+
1551+ assert result .category == 'license info removed'
1552+ assert result .score == 65
1553+
1554+ def test_Delta_determine_score_new_no_license_info_below_cutoff_score (self ):
1555+ new_file = models .File ({'path' : 'new/path.txt' })
1556+ old_file = models .File ({'path' : 'old/path.txt' , 'licenses' : [{'key' : 'mit' , 'score' : 49.0 }]})
1557+
1558+ result = deltacode .Delta (new_file , old_file , 'modified' )
1559+
1560+ assert result .category == 'license info removed'
1561+ assert result .score == 65
1562+
1563+ def test_Delta_determine_score_old_no_license_info (self ):
1564+ new_file = models .File ({'path' : 'new/path.txt' , 'licenses' : [{'key' : 'mit' , 'score' : 50.0 }]})
1565+ old_file = models .File ({'path' : 'old/path.txt' })
1566+
1567+ result = deltacode .Delta (new_file , old_file , 'modified' )
1568+
1569+ assert result .category == 'license info added'
1570+ assert result .score == 70
1571+
1572+ def test_Delta_determine_score_old_no_license_info_below_cutoff_score (self ):
1573+ new_file = models .File ({'path' : 'new/path.txt' , 'licenses' : [{'key' : 'mit' , 'score' : 49.0 }]})
1574+ old_file = models .File ({'path' : 'old/path.txt' })
1575+
1576+ result = deltacode .Delta (new_file , old_file , 'modified' )
1577+
1578+ assert result .category == 'license info added'
1579+ assert result .score == 70
1580+
1581+ def test_Delta_determine_score_single_diff_multiple_keys (self ):
1582+ new_file = models .File ({'path' : 'new/path.txt' , 'licenses' : [{'key' : 'gpl-2.0' , 'score' : 100.0 }, {'key' : 'mit' , 'score' :30.0 }]})
1583+ old_file = models .File ({'path' : 'old/path.txt' , 'licenses' : [{'key' : 'mit' , 'score' : 50.0 }]})
1584+
1585+ result = deltacode .Delta (new_file , old_file , 'modified' )
1586+
1587+ assert result .category == 'license change'
1588+ assert result .score == 60
0 commit comments