commit21-06_19:15-dima
33
README.md
@ -20,3 +20,36 @@
|
||||
|
||||
.png)
|
||||
.png)
|
||||
|
||||
## Tasks
|
||||
|
||||
Dmitri Bespalii
|
||||
### Function 1: get_new_command in /rules/cd_correction.py
|
||||
#### 1. Function Instrumentation
|
||||
|
||||
- **Before instrumentation:**
|
||||
|
||||
.png)
|
||||
|
||||
- **After instrumentation:**
|
||||
|
||||
.png)
|
||||
.png)
|
||||
|
||||
- **Write all information about conditional branches to console:**
|
||||
|
||||
.png)
|
||||
|
||||
#### 2. Coverage Improvement
|
||||
|
||||
- **Coverage before adding new tests to the corresponding test file: /tests/rules/test_cd_correction.py**
|
||||
|
||||
.png)
|
||||
|
||||
- **Creating new tests to cover the function**
|
||||
|
||||
.png)
|
||||
|
||||
- **Coverage aftering adding new tests to the corresponding test file: /tests/rules/test_cd_correction.py**
|
||||
|
||||
.png)
|
After Width: | Height: | Size: 54 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 7.9 KiB |
BIN
screenshots/dima-function1-newtestadded(2024-06-21_18-43-27).png
Normal file
After Width: | Height: | Size: 43 KiB |
After Width: | Height: | Size: 14 KiB |
@ -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('', '')])
|
||||
|
@ -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)
|
||||
|