@@ -91,10 +91,11 @@ def test_hash_files():
9191
9292 git_resource = GitResource (None )
9393
94+ # when there are no excluded files
9495 with mock .patch ("subprocess.check_output" , subprocess_mock (blobs )) as sp_mock , \
9596 mock .patch ("os.getcwd" , return_value = "/foobar/" ) as getcwd_mock , \
9697 mock .patch ("os.chdir" , return_value = None ) as chdir_mock :
97- files_metadata = git_resource ._hash_files (git_files_metadata , "repo_dir_path" )
98+ files_metadata = git_resource ._hash_files (git_files_metadata , "repo_dir_path" , None )
9899
99100 assert sp_mock .call_count == 3
100101 sp_mock .assert_called_with (['git' , 'cat-file' , '-p' , 'e42f952edc48e2c085c206166bf4f1ead4d4b058' ], shell = False )
@@ -114,11 +115,31 @@ def test_hash_files():
114115 assert files_metadata [1 ][1 ] == "1.2.5"
115116 assert files_metadata [1 ][2 ] == hashlib .sha256 (blobs .get ("e42f952edc48e2c085c206166bf4f1ead4d4b058" )).hexdigest ()
116117
118+ git_resource = GitResource (None )
119+
120+ # When the *.cfg files are excluded
121+ with mock .patch ("subprocess.check_output" , subprocess_mock (blobs )) as sp_mock , \
122+ mock .patch ("os.getcwd" , return_value = "/foobar/" ) as getcwd_mock , \
123+ mock .patch ("os.chdir" , return_value = None ) as chdir_mock :
124+ files_metadata = git_resource ._hash_files (git_files_metadata , "repo_dir_path" , "\\ .cfg$" )
125+
126+ assert sp_mock .call_count == 2
127+
128+ getcwd_mock .assert_called_once ()
129+
130+ assert chdir_mock .call_count == 2
131+ chdir_mock .assert_called_with ("/foobar/" )
132+
133+ assert len (files_metadata ) == 1
134+
135+ assert files_metadata [0 ][0 ] == "LICENSE"
136+ assert files_metadata [0 ][1 ] == "1.2.3"
137+ assert files_metadata [0 ][2 ] == hashlib .sha256 (blobs .get ("d159169d1050894d3ea3b98e1c965c4058208fe1" )).hexdigest ()
117138
118139 with mock .patch ("subprocess.check_output" , subprocess_mock (blobs )) as sp_mock , \
119140 mock .patch ("os.getcwd" , return_value = "/foobar/" ) as getcwd_mock , \
120141 mock .patch ("os.chdir" , return_value = None ) as chdir_mock :
121- files_metadata = git_resource ._hash_files ([["empty" , "1.2.1" , "empty" ]], "repo_dir_path" )
142+ files_metadata = git_resource ._hash_files ([["empty" , "1.2.1" , "empty" ]], "repo_dir_path" , None )
122143
123144 assert sp_mock .call_count == 1
124145 sp_mock .assert_called_with (['git' , 'cat-file' , '-p' , 'empty' ], shell = False )
@@ -134,7 +155,7 @@ def test_hash_files():
134155 with mock .patch .object (subprocess , "check_output" , MagicMock (side_effect = ValueError ("error" ))) as mock_exec , \
135156 mock .patch ("os.getcwd" , return_value = "/foobar/" ) as getcwd_mock , \
136157 mock .patch ("os.chdir" , return_value = None ) as chdir_mock :
137- git_resource ._hash_files (git_files_metadata , "repo_dir_path" )
158+ git_resource ._hash_files (git_files_metadata , "repo_dir_path" , None )
138159
139160 getcwd_mock .assert_called_once ()
140161
@@ -411,7 +432,7 @@ def mock_tmp_dir():
411432 session = MagicMock ()
412433 git_resource = GitResource (DbConnector ())
413434
414- git_resource .compute_hashes (session , repo_url )
435+ git_resource .compute_hashes (session , repo_url , None )
415436
416437 # In this situation, we verify that by giving a good repo_url & a good tmp_dir_path
417438 # we download the tags, calculate hash & store them in the database
@@ -420,7 +441,7 @@ def mock_tmp_dir():
420441 mock_get_tag_files .assert_called_once_with (tags [0 ])
421442 mock_filter_stored_tags .assert_called_once_with ([], tags )
422443 mock_get_diff_files .assert_called_once_with (tags )
423- mock_hash_files .assert_called_once_with ([1 , 2 ], tmp_dir_path )
444+ mock_hash_files .assert_called_once_with ([1 , 2 ], tmp_dir_path , None )
424445 mock_save_hashes .assert_called_once_with (session , "hashed files" , tags , "foobar" )
425446
426447 with patch .object (
@@ -435,7 +456,7 @@ def mock_tmp_dir():
435456 patch .object (GitResource , "_hash_files" , return_value = "hashed files" ) as mock_hash_files , \
436457 patch .object (GitResource , "_save_hashes" ) as mock_save_hashes , \
437458 patch .object (DbConnector , "get_versions" ) as mock_get_versions :
438- git_resource .compute_hashes (MagicMock (), repo_url )
459+ git_resource .compute_hashes (MagicMock (), repo_url , None )
439460 mock_clone_repo .assert_called_once_with (repo_url , tmp_dir_path )
440461
441462 # In this situation, we verify that by giving a wrong repository we stop the function
0 commit comments