3737from deltacode import DeltaCode
3838from deltacode import models
3939from deltacode import test_utils
40+ from deltacode import utils
4041from scancode .resource import VirtualCodebase
4142
4243class TestDeltacode (FileBasedTesting ):
@@ -47,22 +48,19 @@ def test_align_and_index_scans(self):
4748 new_scan = self .get_test_loc ('deltacode/ecos-align-index-new.json' )
4849 old_scan = self .get_test_loc ('deltacode/ecos-align-index-old.json' )
4950
50- new = models . Scan (new_scan )
51- old = models . Scan (old_scan )
51+ new = VirtualCodebase (new_scan )
52+ old = VirtualCodebase (old_scan )
5253
5354 options = OrderedDict ([
5455 ('--all-delta-types' , False )
5556 ])
5657
57- delta = DeltaCode (None , None , options )
58-
59- delta .new = new
60- delta .old = old
58+ delta = DeltaCode (new , old , options )
6159
6260 delta .align_scans ()
6361
64- new_index = delta . new . index_files ()
65- old_index = delta . old . index_files ()
62+ new_index = utils . index_files (delta . new_files )
63+ old_index = utils . index_files (delta . old_files )
6664
6765 new_index_length = 0
6866 for k ,v in new_index .items ():
@@ -618,7 +616,7 @@ def test_score_new_no_lic_info(self):
618616 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [35 ]
619617 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == ['license info removed' ]
620618 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
621- assert [d .to_dict ().get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
619+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
622620 OrderedDict ([
623621 ('key' , 'mit' ),
624622 ('score' , 50.0 ),
@@ -627,7 +625,7 @@ def test_score_new_no_lic_info(self):
627625 ('owner' , None )
628626 ])
629627 ]
630- assert [d .to_dict ().get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
628+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
631629
632630 def test_score_old_no_lic_info (self ):
633631 new_scan = self .get_test_loc ('deltacode/score_old_no_lic_info_new.json' )
@@ -647,8 +645,8 @@ def test_score_old_no_lic_info(self):
647645 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [40 ]
648646 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == ['license info added' , 'permissive added' ]
649647 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
650- assert [d .to_dict ().get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
651- assert [d .to_dict ().get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
648+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
649+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
652650 OrderedDict ([
653651 ('key' , 'mit' ),
654652 ('score' , 50.0 ),
@@ -676,7 +674,7 @@ def test_score_multiple_lic_keys(self):
676674 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [50 ]
677675 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == ['license change' , 'copyleft added' ]
678676 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
679- assert [d .to_dict ().get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
677+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
680678 OrderedDict ([
681679 ('key' , 'mit' ),
682680 ('score' , 50.0 ),
@@ -685,7 +683,7 @@ def test_score_multiple_lic_keys(self):
685683 ('owner' , None )
686684 ])
687685 ]
688- assert [d .to_dict ().get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
686+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
689687 OrderedDict ([
690688 ('key' , 'gpl-2.0' ),
691689 ('score' , 100.0 ),
@@ -757,7 +755,7 @@ def test_score_new_multiple_keys_same_lic(self):
757755 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [20 ]
758756 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
759757 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
760- assert [d .to_dict ().get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
758+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
761759 OrderedDict ([
762760 ('key' , 'mit' ),
763761 ('score' , 100.0 ),
@@ -766,7 +764,7 @@ def test_score_new_multiple_keys_same_lic(self):
766764 ('owner' , None )
767765 ])
768766 ]
769- assert [d .to_dict ().get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
767+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('licenses' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
770768 OrderedDict ([
771769 ('key' , 'mit' ),
772770 ('score' , 75.0 ),
@@ -801,13 +799,13 @@ def test_score_single_copyright_change(self):
801799 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [25 ]
802800 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == ['copyright change' ]
803801 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
804- assert [d .to_dict ().get ('old' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
802+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
805803 OrderedDict ([
806804 ('statements' , ['Copyright (c) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler' ]),
807805 ('holders' , ['Jean-loup Gailly, Mark Adler' ])
808806 ])
809807 ]
810- assert [d .to_dict ().get ('new' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
808+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
811809 OrderedDict ([
812810 ('statements' , ['Copyright (c) 2016 Mark Adler' ]),
813811 ('holders' , ['Mark Adler' ])
@@ -836,8 +834,8 @@ def test_score_copyright_info_added(self):
836834 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [30 ]
837835 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == ['copyright info added' ]
838836 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
839- assert [d .to_dict ().get ('old' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
840- assert [d .to_dict ().get ('new' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
837+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
838+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
841839 OrderedDict ([
842840 ('statements' , ['Copyright (c) 2016 Mark Adler' ]),
843841 ('holders' , ['Mark Adler' ])
@@ -866,13 +864,13 @@ def test_score_copyright_info_removed(self):
866864 assert [d .score for d in deltas_object if d .new_file .path == 'path.txt' ] == [30 ]
867865 assert [d .factors for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == ['copyright info removed' ]
868866 assert [d .status for d in deltas_object if d .new_file .path == 'path.txt' ] == ['modified' ]
869- assert [d .to_dict ().get ('old' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
867+ assert [d .to_dict (deltacode_object ).get ('old' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == [
870868 OrderedDict ([
871869 ('statements' , ['Copyright (c) 2016 Mark Adler' ]),
872870 ('holders' , ['Mark Adler' ])
873871 ])
874872 ]
875- assert [d .to_dict ().get ('new' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
873+ assert [d .to_dict (deltacode_object ).get ('new' ).get ('copyrights' ) for d in deltas_object if d .new_file .path == 'path.txt' ].pop () == []
876874
877875 assert len ([i for i in deltas_object if i .score == 30 ]) == 1
878876 assert len ([i for i in deltas_object if i .score == 20 ]) == 0
0 commit comments