2024-06-27 15:10:12 +02:00
|
|
|
# Report for Assignment 1 - Group 82
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
## Project Information
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Name:** TheFuck - Magnificent app which corrects your previous console command
|
|
|
|
- **URL:** https://github.com/dimalarcon/SEP2024-Group82-thefuck
|
|
|
|
- **Programming Language:** Python
|
2018-04-01 13:25:09 -07:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
## Code Metrics
|
2017-08-26 13:31:09 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Number of lines of code:** 547801 (54.7 KLOC)
|
|
|
|
- **Tool used to measure the number of lines of code:** lizard
|
2015-07-19 21:53:08 +03:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
.png)
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
## Coverage Measurement
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Existing tool used to measure the coverage:** coverage.py
|
|
|
|
- **Coverage result:** 94%
|
2015-04-21 05:30:15 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
.png)
|
|
|
|
.png)
|
2016-05-03 22:50:14 -03:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
## Tasks
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
### Luca De Nobili
|
2018-01-10 15:31:38 -05:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
### Function 1 (property): in thefuck/types.py
|
2018-05-09 19:35:46 -04:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
#### 1. Function Instrumentation
|
2022-08-31 15:42:41 -03:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Before instrumentation:**
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|

|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **After instrumentation:**
|
2015-04-23 09:00:18 +12:00
|
|
|
|
2024-06-27 15:16:41 +02:00
|
|
|

|
2015-04-08 18:15:49 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
#### 2. Coverage Improvement
|
2015-05-01 00:13:08 +05:30
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Coverage before adding new tests to the corresponding test file: /tests/test_types.py**
|
2015-04-20 15:11:29 +10:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|

|
2015-04-18 22:58:53 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Creating new tests to cover the function**
|
2015-07-27 23:23:26 +03:00
|
|
|
|
2015-07-20 21:08:46 +02:00
|
|
|
```python
|
2024-06-27 15:10:12 +02:00
|
|
|
def test_script_parts_exception(self, mocker, caplog):
|
|
|
|
mocker.patch('thefuck.shells.shell.split_command', side_effect=Exception('Mocked exception'))
|
|
|
|
command = Command('invalid command', 'output')
|
|
|
|
|
|
|
|
with caplog.at_level('DEBUG'):
|
|
|
|
parts = command.script_parts
|
|
|
|
assert parts == []
|
2015-08-19 11:00:09 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
print(f"Branch coverage: {sum(branch_coverage.values())/len(branch_coverage) * 100}%\n")
|
2015-08-19 11:00:09 +02:00
|
|
|
```
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Coverage after adding new tests to the corresponding test file: /tests/types.py**
|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|

|
2016-10-08 12:18:33 +02:00
|
|
|
|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 16:14:14 +02:00
|
|
|
### Function 2: getch in utils.py
|
2019-10-08 17:47:04 -04:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
#### 1. Function Instrumentation
|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Before instrumentation:**
|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 16:14:14 +02:00
|
|
|

|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **After instrumentation:**
|
2015-05-08 00:16:50 +05:30
|
|
|
|
2024-06-27 16:14:14 +02:00
|
|
|

|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
#### 2. Coverage Improvement
|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 16:14:14 +02:00
|
|
|
- **Coverage before adding new tests to the corresponding test file: /tests/test_utils.py**
|
2021-03-13 05:28:10 +05:30
|
|
|
|
2024-06-27 16:14:14 +02:00
|
|
|

|
2015-04-17 17:01:30 +02:00
|
|
|
|
2024-06-27 15:10:12 +02:00
|
|
|
- **Creating new tests to cover the function**
|
2015-04-29 04:47:15 +02:00
|
|
|
|
|
|
|
```python
|
2024-06-27 16:14:14 +02:00
|
|
|
class TestGetInstallationVersion(unittest.TestCase):
|
|
|
|
|
|
|
|
@patch('importlib.metadata.version', unittest.mock.MagicMock(return_value='1.2.3'))
|
|
|
|
def test_get_installation_version_with_importlib(self):
|
|
|
|
version = get_installation_version()
|
|
|
|
self.assertEqual(version,'1.2.3')
|
|
|
|
|
|
|
|
@patch('importlib.metadata.version', side_effect=ImportError)
|
|
|
|
@patch('pkg_resources.require', return_value=[unittest.mock.MagicMock(version='4.5.6')])
|
|
|
|
def test_get_installation_version_with_pkg_resources(self, mock_require, mock_version):
|
|
|
|
version = get_installation_version()
|
|
|
|
self.assertEqual(version, '4.5.6')
|
|
|
|
print(f"Branch coverage: {sum(branch_coverage.values())/len(branch_coverage) * 100}% ")
|
|
|
|
|
2017-08-26 13:31:09 +02:00
|
|
|
```
|
2024-06-27 16:14:14 +02:00
|
|
|
- **Coverage after adding new tests to the corresponding test file: /tests/test_utils.py**
|
2017-08-26 13:31:09 +02:00
|
|
|
|
2024-06-27 16:14:14 +02:00
|
|
|

|
2021-03-13 05:28:10 +05:30
|
|
|
|