3434
3535git_repo = git .Repo (os .getcwd (), search_parent_directories = True )
3636REPO_PATH = git_repo .git .rev_parse ("--show-toplevel" )
37+ START_YEAR = "2023"
3738
3839
3940def set_up_repo (tmp_path , template_path , template_name , license_path , license_name ):
@@ -143,7 +144,7 @@ def test_custom_start_year(tmp_path: pytest.TempPathFactory):
143144
144145 # Set up git repository in tmp_path with temporary file
145146 repo , tmp_file = set_up_repo (tmp_path , template_path , template_name , license_path , license_name )
146- custom_args = [tmp_file , "--start_year=2023 " ]
147+ custom_args = [tmp_file , f "--start_year={ START_YEAR } " ]
147148
148149 # Assert the hook fails because it added the header
149150 assert add_argv_run (repo , tmp_file , custom_args ) == 1
@@ -155,7 +156,7 @@ def test_custom_start_year(tmp_path: pytest.TempPathFactory):
155156 # Assert the copyright line's time range is
156157 # from 2023 to the current year
157158 if count == 1 :
158- assert f"2023 - { dt .today ().year } " in line
159+ assert f"{ START_YEAR } - { dt .today ().year } " in line
159160 if count > 1 :
160161 break
161162 file .close ()
@@ -282,8 +283,9 @@ def test_main_fails(tmp_path: pytest.TempPathFactory):
282283
283284 # Set up git repository in tmp_path with temporary file
284285 repo , tmp_file = set_up_repo (tmp_path , template_path , template_name , license_path , license_name )
286+ custom_args = [tmp_file , f"--start_year={ START_YEAR } " ]
285287
286- assert add_argv_run (repo , tmp_file , [ tmp_file ] ) == 1
288+ assert add_argv_run (repo , tmp_file , custom_args ) == 1
287289
288290 check_ansys_header (tmp_file )
289291
@@ -292,7 +294,7 @@ def test_main_fails(tmp_path: pytest.TempPathFactory):
292294
293295def test_main_passes ():
294296 """Test all files are compliant."""
295- sys .argv [1 :] = []
297+ sys .argv [1 :] = [f"--start_year= { START_YEAR } " ]
296298
297299 # Assert main runs successfully
298300 assert hook .main () == 0
@@ -442,60 +444,6 @@ def test_update_changed_header(tmp_path: pytest.TempPathFactory):
442444 os .chdir (REPO_PATH )
443445
444446
445- def test_missing_licenses (tmp_path : pytest .TempPathFactory ):
446- """Test that LICENSES folder is required."""
447- # Set template and license names
448- template_name = "test_template.jinja2"
449- license_name = "ECL-1.0.txt"
450- template_path = os .path .join (REPO_PATH , "tests" , "test_reuse_files" , "templates" , template_name )
451- license_path = os .path .join (REPO_PATH , "tests" , "test_reuse_files" , "LICENSES" , license_name )
452-
453- # Set up git repository in tmp_path with temporary file
454- repo , tmp_file = set_up_repo (tmp_path , template_path , template_name , license_path , license_name )
455-
456- # Remove LICENSES/ECL-1.0.txt file from tmp_path
457- os .remove (os .path .join (tmp_path , "LICENSES" , license_name ))
458-
459- custom_args = [
460- tmp_file ,
461- "--custom_template=test_template" ,
462- "--custom_license=ECL-1.0" ,
463- ]
464-
465- # Add header to tmp_file
466- add_argv_run (repo , tmp_file , custom_args )
467-
468- custom_args = [
469- tmp_file ,
470- "--custom_template=test_template" ,
471- "--custom_license=ECL-1.0" ,
472- ]
473-
474- # If LICENSES/license_name.txt file is missing, then it will fail
475- # and add another SPDX line. This shows you need the
476- # license_name.txt (MIT.txt, for example) in LICENSES or else it
477- # will fail
478- assert add_argv_run (repo , tmp_file , custom_args ) == 1
479-
480- # Assert two SPDX-License lines are found in the file if
481- # the LICENSES/ECL-1.0.txt file does not exist.
482- file = open (tmp_file , "r" )
483- count = 0
484- for line in file :
485- count += 1
486- if count == 6 :
487- assert "SPDX-License" in line
488- # Ensure header was updated correctly and didn't add
489- # an extra SPDX-Identifier line
490- if count == 7 :
491- assert "SPDX-License" in line
492- if count > 7 :
493- break
494- file .close ()
495-
496- os .chdir (REPO_PATH )
497-
498-
499447def test_copy_assets (tmp_path : pytest .TempPathFactory ):
500448 """Test .reuse and LICENSES folders are copied."""
501449 # List of files to be git added
@@ -588,7 +536,7 @@ def test_index_exception(tmp_path: pytest.TempPathFactory):
588536 "--custom_copyright=ANSYS, Inc. Unauthorized use, distribution, \
589537 or duplication is prohibited." ,
590538 "--ignore_license_check" ,
591- "--start_year=2023 " ,
539+ f "--start_year={ START_YEAR } " ,
592540 ]
593541
594542 # Assert the hook failed
@@ -652,16 +600,16 @@ def test_license_year_update(tmp_path: pytest.TempPathFactory):
652600 values = {
653601 "copyright" : args .custom_copyright ,
654602 "license" : args .custom_license ,
655- "start_year" : args . start_year ,
603+ "start_year" : START_YEAR ,
656604 "current_year" : dt .today ().year ,
657605 "git_repo" : git_repo ,
658606 }
659607
660608 # Years to update the LICENSE file
661- years = [values [ "start_year" ], " 2022" , dt .today ().year ]
609+ years = [" 2022" , dt .today ().year , values [ "start_year" ] ]
662610
663- # Check the copyright line has "2023 - {current_year}", "2022 - {current_year}",
664- # and "{current_year}"
611+ # Check the copyright line has "2022 - {current_year}", "{current_year}"
612+ # and "2023 - {current_year}"
665613 for year in years :
666614 values ["start_year" ] = year
667615 hook .update_license_file (values )
0 commit comments