mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-07 13:41:21 +00:00
7f0f9a966f
Before: 4 E101 indentation contains mixed spaces and tabs 20 E122 continuation line missing indentation or outdented 1 E124 closing bracket does not match visual indentation 12 E127 continuation line over-indented for visual indent 22 E128 continuation line under-indented for visual indent 2 E211 whitespace before '(' 12 E302 expected 2 blank lines, found 1 1 E303 too many blank lines (3) 4 E402 module level import not at top of file 123 E501 line too long (81 > 79 characters) 2 E731 do not assign a lambda expression, use a def 3 W191 indentation contains tabs 20 W291 trailing whitespace 3 W293 blank line contains whitespace 2 W391 blank line at end of file 69 W503 line break before binary operator After: 20 E122 continuation line missing indentation or outdented 12 E127 continuation line over-indented for visual indent 22 E128 continuation line under-indented for visual indent 123 E501 line too long (81 > 79 characters) 2 E731 do not assign a lambda expression, use a def 1 W291 trailing whitespace 68 W503 line break before binary operator
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
import os
|
|
import pytest
|
|
import tarfile
|
|
from thefuck.rules.dirty_untar import match, get_new_command, side_effect
|
|
from tests.utils import Command
|
|
|
|
|
|
@pytest.fixture
|
|
def tar_error(tmpdir):
|
|
def fixture(filename):
|
|
path = os.path.join(str(tmpdir), filename)
|
|
|
|
def reset(path):
|
|
with tarfile.TarFile(path, 'w') as archive:
|
|
for file in ('a', 'b', 'c'):
|
|
with open(file, 'w') as f:
|
|
f.write('*')
|
|
|
|
archive.add(file)
|
|
|
|
os.remove(file)
|
|
|
|
with tarfile.TarFile(path, 'r') as archive:
|
|
archive.extractall()
|
|
|
|
os.chdir(str(tmpdir))
|
|
reset(path)
|
|
|
|
assert(set(os.listdir('.')) == {filename, 'a', 'b', 'c'})
|
|
|
|
return fixture
|
|
|
|
parametrize_filename = pytest.mark.parametrize('filename', [
|
|
'foo.tar',
|
|
'foo.tar.gz',
|
|
'foo.tgz'])
|
|
|
|
parametrize_script = pytest.mark.parametrize('script, fixed', [
|
|
('tar xvf {}', 'mkdir -p foo && tar xvf {} -C foo'),
|
|
('tar -xvf {}', 'mkdir -p foo && tar -xvf {} -C foo'),
|
|
('tar --extract -f {}', 'mkdir -p foo && tar --extract -f {} -C foo')])
|
|
|
|
|
|
@parametrize_filename
|
|
@parametrize_script
|
|
def test_match(tar_error, filename, script, fixed):
|
|
tar_error(filename)
|
|
assert match(Command(script=script.format(filename)), None)
|
|
|
|
|
|
@parametrize_filename
|
|
@parametrize_script
|
|
def test_side_effect(tar_error, filename, script, fixed):
|
|
tar_error(filename)
|
|
side_effect(Command(script=script.format(filename)), None)
|
|
assert(os.listdir('.') == [filename])
|
|
|
|
|
|
@parametrize_filename
|
|
@parametrize_script
|
|
def test_get_new_command(tar_error, filename, script, fixed):
|
|
tar_error(filename)
|
|
assert get_new_command(Command(script=script.format(filename)), None) == fixed.format(filename)
|