mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	Fix #363
This commit is contained in:
		| @@ -11,8 +11,9 @@ def tar_error(tmpdir): | ||||
|         path = os.path.join(str(tmpdir), filename) | ||||
|  | ||||
|         def reset(path): | ||||
|             os.mkdir('d') | ||||
|             with tarfile.TarFile(path, 'w') as archive: | ||||
|                 for file in ('a', 'b', 'c'): | ||||
|                 for file in ('a', 'b', 'c', 'd/e'): | ||||
|                     with open(file, 'w') as f: | ||||
|                         f.write('*') | ||||
|  | ||||
| @@ -26,7 +27,8 @@ def tar_error(tmpdir): | ||||
|         os.chdir(str(tmpdir)) | ||||
|         reset(path) | ||||
|  | ||||
|         assert(set(os.listdir('.')) == {filename, 'a', 'b', 'c'}) | ||||
|         assert set(os.listdir('.')) == {filename, 'a', 'b', 'c', 'd'} | ||||
|         assert set(os.listdir('./d')) == {'e'} | ||||
|  | ||||
|     return fixture | ||||
|  | ||||
| @@ -53,7 +55,7 @@ def test_match(tar_error, filename, script, fixed): | ||||
| def test_side_effect(tar_error, filename, script, fixed): | ||||
|     tar_error(filename) | ||||
|     side_effect(Command(script=script.format(filename)), None, None) | ||||
|     assert(os.listdir('.') == [filename]) | ||||
|     assert set(os.listdir('.')) == {filename, 'd'} | ||||
|  | ||||
|  | ||||
| @parametrize_filename | ||||
|   | ||||
| @@ -15,12 +15,15 @@ def zip_error(tmpdir): | ||||
|             archive.writestr('b', '2') | ||||
|             archive.writestr('c', '3') | ||||
|  | ||||
|             archive.writestr('d/e', '4') | ||||
|  | ||||
|             archive.extractall() | ||||
|  | ||||
|     os.chdir(str(tmpdir)) | ||||
|     reset(path) | ||||
|  | ||||
|     assert(set(os.listdir('.')) == {'foo.zip', 'a', 'b', 'c'}) | ||||
|     assert set(os.listdir('.')) == {'foo.zip', 'a', 'b', 'c', 'd'} | ||||
|     assert set(os.listdir('./d')) == {'e'} | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script', [ | ||||
| @@ -35,7 +38,7 @@ def test_match(zip_error, script): | ||||
|     'unzip foo.zip']) | ||||
| def test_side_effect(zip_error, script): | ||||
|     side_effect(Command(script=script), None, None) | ||||
|     assert(os.listdir('.') == ['foo.zip']) | ||||
|     assert set(os.listdir('.')) == {'foo.zip', 'd'} | ||||
|  | ||||
|  | ||||
| @pytest.mark.parametrize('script,fixed', [ | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| import os | ||||
| import tarfile | ||||
| import os | ||||
| from thefuck import shells | ||||
| from thefuck.utils import for_app | ||||
|  | ||||
| @@ -39,4 +39,9 @@ def get_new_command(command, settings): | ||||
| def side_effect(old_cmd, command, settings): | ||||
|     with tarfile.TarFile(_tar_file(old_cmd.script)[0]) as archive: | ||||
|         for file in archive.getnames(): | ||||
|             os.remove(file) | ||||
|             try: | ||||
|                 os.remove(file) | ||||
|             except OSError: | ||||
|                 # does not try to remove directories as we cannot know if they | ||||
|                 # already existed before | ||||
|                 pass | ||||
|   | ||||
| @@ -34,7 +34,12 @@ def get_new_command(command, settings): | ||||
| def side_effect(old_cmd, command, settings): | ||||
|     with zipfile.ZipFile(_zip_file(old_cmd), 'r') as archive: | ||||
|         for file in archive.namelist(): | ||||
|             os.remove(file) | ||||
|             try: | ||||
|                 os.remove(file) | ||||
|             except OSError: | ||||
|                 # does not try to remove directories as we cannot know if they | ||||
|                 # already existed before | ||||
|                 pass | ||||
|  | ||||
|  | ||||
| requires_output = False | ||||
|   | ||||
		Reference in New Issue
	
	Block a user