Update project setup.

This commit is contained in:
Anthony Sottile 2014-04-13 22:09:14 -07:00
parent 13b4ca54cf
commit b80ca9e84a
23 changed files with 186 additions and 112 deletions

View file

@ -1,4 +1,3 @@
import pytest
from pre_commit_hooks.check_yaml import check_yaml

View file

@ -1,11 +0,0 @@
import __builtin__
import mock
import pytest
@pytest.yield_fixture
def print_mock():
with mock.patch.object(__builtin__, 'print', autospec=True) as mock_print:
yield mock_print

View file

@ -1,4 +1,3 @@
import ast
import pytest

View file

@ -1,5 +1,4 @@
import cStringIO
import io
import os.path
import pytest
@ -9,19 +8,19 @@ from pre_commit_hooks.end_of_file_fixer import fix_file
# Input, expected return value, expected output
TESTS = (
('foo\n', 0, 'foo\n'),
('', 0, ''),
('\n\n', 1, ''),
('\n\n\n\n', 1, ''),
('foo', 1, 'foo\n'),
('foo\n\n\n', 1, 'foo\n'),
('\xe2\x98\x83', 1, '\xe2\x98\x83\n'),
(b'foo\n', 0, b'foo\n'),
(b'', 0, b''),
(b'\n\n', 1, b''),
(b'\n\n\n\n', 1, b''),
(b'foo', 1, b'foo\n'),
(b'foo\n\n\n', 1, b'foo\n'),
(b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n'),
)
@pytest.mark.parametrize(('input', 'expected_retval', 'output'), TESTS)
def test_fix_file(input, expected_retval, output):
file_obj = cStringIO.StringIO()
file_obj = io.BytesIO()
file_obj.write(input)
ret = fix_file(file_obj)
assert file_obj.getvalue() == output
@ -32,11 +31,11 @@ def test_fix_file(input, expected_retval, output):
def test_integration(input, expected_retval, output, tmpdir):
file_path = os.path.join(tmpdir.strpath, 'file.txt')
with open(file_path, 'w') as file_obj:
with open(file_path, 'wb') as file_obj:
file_obj.write(input)
ret = end_of_file_fixer([file_path])
file_output = open(file_path, 'r').read()
file_output = open(file_path, 'rb').read()
assert file_output == output
assert ret == expected_retval

View file

@ -1,14 +1,11 @@
from pre_commit_hooks.tests_should_end_in_test import validate_files
def test_validate_files_all_pass(print_mock):
def test_validate_files_all_pass():
ret = validate_files(['foo_test.py', 'bar_test.py'])
assert ret == 0
assert print_mock.call_count == 0
def test_validate_files_one_fails(print_mock):
def test_validate_files_one_fails():
ret = validate_files(['not_test_ending.py', 'foo_test.py'])
assert ret == 1
assert print_mock.call_count == 1

View file

@ -1,4 +1,3 @@
import mock
import pytest
import sys