diff --git a/README.md b/README.md index 98dd71e1..22ece0b8 100644 --- a/README.md +++ b/README.md @@ -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) \ No newline at end of file diff --git a/screenshots/dima-function1-after_instrumentation_1(2024-06-21_17-48-32).png b/screenshots/dima-function1-after_instrumentation_1(2024-06-21_17-48-32).png new file mode 100644 index 00000000..e487e4a7 Binary files /dev/null and b/screenshots/dima-function1-after_instrumentation_1(2024-06-21_17-48-32).png differ diff --git a/screenshots/dima-function1-after_instrumentation_2(2024-06-21_17-53-14).png b/screenshots/dima-function1-after_instrumentation_2(2024-06-21_17-53-14).png new file mode 100644 index 00000000..e602a4d5 Binary files /dev/null and b/screenshots/dima-function1-after_instrumentation_2(2024-06-21_17-53-14).png differ diff --git a/screenshots/dima-function1-before_instrumentation(2024-06-21_17-35-56).png b/screenshots/dima-function1-before_instrumentation(2024-06-21_17-35-56).png new file mode 100644 index 00000000..bdac3ce3 Binary files /dev/null and b/screenshots/dima-function1-before_instrumentation(2024-06-21_17-35-56).png differ diff --git a/screenshots/dima-function1-coverage_after_improv(2024-06-21_19-11-59).png b/screenshots/dima-function1-coverage_after_improv(2024-06-21_19-11-59).png new file mode 100644 index 00000000..d702f8ea Binary files /dev/null and b/screenshots/dima-function1-coverage_after_improv(2024-06-21_19-11-59).png differ diff --git a/screenshots/dima-function1-coverage_before_improvement(2024-06-21_19-07-47).png b/screenshots/dima-function1-coverage_before_improvement(2024-06-21_19-07-47).png new file mode 100644 index 00000000..a949d2b3 Binary files /dev/null and b/screenshots/dima-function1-coverage_before_improvement(2024-06-21_19-07-47).png differ diff --git a/screenshots/dima-function1-newtestadded(2024-06-21_18-43-27).png b/screenshots/dima-function1-newtestadded(2024-06-21_18-43-27).png new file mode 100644 index 00000000..2cfe1d38 Binary files /dev/null and b/screenshots/dima-function1-newtestadded(2024-06-21_18-43-27).png differ diff --git a/screenshots/dima-function1-write_info_branch_coverage(2024-06-21_18-14-39).png b/screenshots/dima-function1-write_info_branch_coverage(2024-06-21_18-14-39).png new file mode 100644 index 00000000..916a13a6 Binary files /dev/null and b/screenshots/dima-function1-write_info_branch_coverage(2024-06-21_18-14-39).png differ diff --git a/tests/rules/test_cd_correction.py b/tests/rules/test_cd_correction.py index d2576584..ab5165c8 100644 --- a/tests/rules/test_cd_correction.py +++ b/tests/rules/test_cd_correction.py @@ -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('', '')]) diff --git a/thefuck/rules/cd_correction.py b/thefuck/rules/cd_correction.py index dc45636a..ad45f5ca 100644 --- a/thefuck/rules/cd_correction.py +++ b/thefuck/rules/cd_correction.py @@ -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)