Skip to content

Commit 2de0851

Browse files
committed
The previous implement will cause "Permission denied" for Windows system as try to open a already opened file.
Update the code to use another method to create a tmp file, but this method need to add code to close and remove the file with: os.close() os.remove()
1 parent a1eafce commit 2de0851

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

about_code_tool/tests/test_genabout.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -500,16 +500,18 @@ def test_copy_license_files_test_path_endswith_slash(self):
500500

501501
def test_write_licenses(self):
502502
gen = genabout.GenAbout()
503-
tmp_license = tempfile.NamedTemporaryFile(suffix='.LICENSE', delete=True)
503+
fh, tmp_license_name = tempfile.mkstemp()
504504
tmp_license_context = 'This is a test.'
505-
input_list = [[tmp_license.name, tmp_license_context]]
505+
input_list = [[tmp_license_name, tmp_license_context]]
506506
gen.write_licenses(input_list)
507-
self.assertTrue(os.path.exists(tmp_license.name))
508-
with open(tmp_license.name, "rU") as file_in:
507+
self.assertTrue(os.path.exists(tmp_license_name))
508+
with open(tmp_license_name, "rU") as file_in:
509509
context = ''
510510
for line in file_in.readlines():
511511
context = line
512512
self.assertTrue(context == tmp_license_context)
513+
os.close(fh)
514+
os.remove(tmp_license_name)
513515

514516
def test_process_dje_licenses(self):
515517
gen = genabout.GenAbout()

0 commit comments

Comments
 (0)