1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 06:38:32 +00:00

commit21-06_19:15-dima

This commit is contained in:
dimalarcon 2024-06-21 19:14:05 +02:00
parent 468db2a754
commit 5f31a6131f
10 changed files with 64 additions and 2 deletions

View File

@ -20,3 +20,36 @@
![Coverage.py-Coverage-Measurement](/screenshots/coverage-py-2(2024-06-21_17-09-11).png)
![Coverage.py-Coverage-Measurement](/screenshots/coverage-py-1(21-06-2024_17-06-39).png)
## Tasks
Dmitri Bespalii
### Function 1: get_new_command in /rules/cd_correction.py
#### 1. Function Instrumentation
- **Before instrumentation:**
![Function1-BeforeInstrumentation](/screenshots/dima-function1-before_instrumentation(2024-06-21_17-35-56).png)
- **After instrumentation:**
![Function1-AfterInstrumentation-1](/screenshots/dima-function1-after_instrumentation_1(2024-06-21_17-48-32).png)
![Function1-AfterInstrumentation-2](/screenshots/dima-function1-after_instrumentation_2(2024-06-21_17-53-14).png)
- **Write all information about conditional branches to console:**
![Function1-WriteInformation](/screenshots/dima-function1-write_info_branch_coverage(2024-06-21_18-14-39).png)
#### 2. Coverage Improvement
- **Coverage before adding new tests to the corresponding test file: /tests/rules/test_cd_correction.py**
![Function1-CoverageBeforeImprov](/screenshots/dima-function1-coverage_before_improvement(2024-06-21_19-07-47).png)
- **Creating new tests to cover the function**
![Function1-NewTestsAdded](/screenshots/dima-function1-newtestadded(2024-06-21_18-43-27).png)
- **Coverage aftering adding new tests to the corresponding test file: /tests/rules/test_cd_correction.py**
![Function-CoverageAfterImprov](/screenshots/dima-function1-coverage_after_improv(2024-06-21_19-11-59).png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -1,5 +1,5 @@
import pytest
from thefuck.rules.cd_correction import match
from thefuck.rules.cd_correction import match, get_new_command, branch_coverage
from thefuck.types import Command
@ -12,6 +12,16 @@ from thefuck.types import Command
def test_match(command):
assert match(command)
@pytest.mark.parametrize('command', [
Command('cd foo', 'cd: foo: No such file or directory'),
Command('cd foo/bar/baz',
'cd: foo: No such file or directory'),
Command('cd foo/bar/baz', 'cd: can\'t cd to foo/bar/baz'),
Command('cd /foo/bar/', 'cd: The directory "/foo/bar/" does not exist')])
def test_gew_new_command(command):
print(branch_coverage)
assert get_new_command(command)
print(branch_coverage)
@pytest.mark.parametrize('command', [
Command('cd foo', ''), Command('', '')])

View File

@ -27,6 +27,17 @@ def match(command):
'does not exist' in command.output.lower()
)))
# Initialize coverage tracking global variable
branch_coverage = {
"get_new_command_1": False, #if dest[-1] == '':
"get_new_command_2": False, #if dest[-1] == '':
"get_new_command_3": False, #elif six.PY2:
"get_new_command_4": False, #else:
"get_new_command_5": False, #if directory == ".":
"get_new_command_6": False, #elif directory == "..":
"get_new_command_7": False, #if best_matches:
"get_new_command_8": False #else:
}
@sudo_support
def get_new_command(command):
@ -38,24 +49,32 @@ def get_new_command(command):
"""
dest = command.script_parts[1].split(os.sep)
if dest[-1] == '':
branch_coverage["get_new_command_1"] = True
dest = dest[:-1]
if dest[0] == '':
if dest[-1] == '':
branch_coverage["get_new_command_2"] = True
cwd = os.sep
dest = dest[1:]
elif six.PY2:
branch_coverage["get_new_command_3"] = True
cwd = os.getcwdu()
else:
branch_coverage["get_new_command_4"] = True
cwd = os.getcwd()
for directory in dest:
if directory == ".":
branch_coverage["get_new_command_5"] = True
continue
elif directory == "..":
branch_coverage["get_new_command_6"] = True
cwd = os.path.split(cwd)[0]
continue
best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF)
if best_matches:
branch_coverage["get_new_command_7"] = True
cwd = os.path.join(cwd, best_matches[0])
else:
branch_coverage["get_new_command_8"] = True
return cd_mkdir.get_new_command(command)
return u'cd "{0}"'.format(cwd)