mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-20 01:28:56 +00:00
add function 2 coverage information
This commit is contained in:
parent
507d8f5bf7
commit
2df4bd5cfa
65
README.md
65
README.md
@ -61,70 +61,43 @@
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
### Function 2: getch in system/unix.py
|
### Function 2: getch in utils.py
|
||||||
|
|
||||||
#### 1. Function Instrumentation
|
#### 1. Function Instrumentation
|
||||||
|
|
||||||
- **Before instrumentation:**
|
- **Before instrumentation:**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- **After instrumentation:**
|
- **After instrumentation:**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
#### 2. Coverage Improvement
|
#### 2. Coverage Improvement
|
||||||
|
|
||||||
- **Coverage before adding new tests to the corresponding test file: /tests/rules/test_yarn_help.py**
|
- **Coverage before adding new tests to the corresponding test file: /tests/test_utils.py**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
- **Creating new tests to cover the function**
|
- **Creating new tests to cover the function**
|
||||||
|
|
||||||
```python
|
```python
|
||||||
def test_getch():
|
class TestGetInstallationVersion(unittest.TestCase):
|
||||||
with patch('thefuck.system.sys.stdin', MagicMock()):
|
|
||||||
# Mock termios functions used in getch()
|
|
||||||
mock_tcgetattr = MagicMock()
|
|
||||||
mock_tcsetattr = MagicMock()
|
|
||||||
mock_tcgetattr.return_value = [0] * 6 # Mocking a typical return value for tcgetattr
|
|
||||||
|
|
||||||
with patch('thefuck.system.termios.tcgetattr', mock_tcgetattr):
|
@patch('importlib.metadata.version', unittest.mock.MagicMock(return_value='1.2.3'))
|
||||||
with patch('thefuck.system.termios.tcsetattr', mock_tcsetattr):
|
def test_get_installation_version_with_importlib(self):
|
||||||
# Mock fileno() to return a valid integer
|
version = get_installation_version()
|
||||||
sys.stdin.fileno = MagicMock(return_value=0)
|
self.assertEqual(version,'1.2.3')
|
||||||
|
|
||||||
# Mock setraw() to bypass actual terminal setup
|
@patch('importlib.metadata.version', side_effect=ImportError)
|
||||||
tty.setraw = MagicMock()
|
@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):
|
||||||
# Mock read() to return values for getch() calls
|
version = get_installation_version()
|
||||||
sys.stdin.read = MagicMock(side_effect=['a', 'b', 'c', '', '\x1b', '\x03'])
|
self.assertEqual(version, '4.5.6')
|
||||||
|
print(f"Branch coverage: {sum(branch_coverage.values())/len(branch_coverage) * 100}% ")
|
||||||
# Test reading multiple characters
|
|
||||||
assert getch() == 'a'
|
|
||||||
assert getch() == 'b'
|
|
||||||
assert getch() == 'c'
|
|
||||||
|
|
||||||
# Test handling of empty input
|
|
||||||
assert getch() == ''
|
|
||||||
|
|
||||||
# Test handling of special characters
|
|
||||||
assert getch() == '\x1b'
|
|
||||||
assert getch() == '\x03'
|
|
||||||
|
|
||||||
# Ensure read(1) is called exactly once per getch() call
|
|
||||||
assert sys.stdin.read.call_count == 6 # 3 normal chars + 1 empty + 2 special chars
|
|
||||||
|
|
||||||
print(branch_coverage)
|
|
||||||
|
|
||||||
# print percentage of branch coverage
|
|
||||||
covered = 0
|
|
||||||
for key in branch_coverage:
|
|
||||||
if branch_coverage[key]:
|
|
||||||
covered += 1
|
|
||||||
print("Branch coverage: " + str(covered / len(branch_coverage) * 100) + "%")
|
|
||||||
```
|
```
|
||||||
- **Coverage after adding new tests to the corresponding test file: /tests/rules/test_yarn_help.py**
|
- **Coverage after adding new tests to the corresponding test file: /tests/test_utils.py**
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user