Skip to content

Commit

Permalink
Merge pull request #325 from pre-commit/use_subprocess
Browse files Browse the repository at this point in the history
Use subprocess directly
  • Loading branch information
asottile authored Oct 13, 2018
2 parents 08e2918 + 69f2da6 commit dbf7de0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/forbid_new_submodules_test.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from __future__ import absolute_import

import subprocess

import pytest
from pre_commit.util import cmd_output

from pre_commit_hooks.forbid_new_submodules import main


@pytest.fixture
def git_dir_with_git_dir(tmpdir):
with tmpdir.as_cwd():
cmd_output('git', 'init', '.')
cmd_output(
'git', 'commit', '-m', 'init', '--allow-empty', '--no-gpg-sign',
)
cmd_output('git', 'init', 'foo')
cmd_output(
subprocess.check_call(('git', 'init', '.'))
subprocess.check_call((
'git', 'commit', '-m', 'init', '--allow-empty', '--no-gpg-sign',
))
subprocess.check_call(('git', 'init', 'foo'))
subprocess.check_call(
('git', 'commit', '-m', 'init', '--allow-empty', '--no-gpg-sign'),
cwd=tmpdir.join('foo').strpath,
)
yield
Expand All @@ -31,13 +32,13 @@ def git_dir_with_git_dir(tmpdir):
),
)
def test_main_new_submodule(git_dir_with_git_dir, capsys, cmd):
cmd_output(*cmd)
subprocess.check_call(cmd)
assert main() == 1
out, _ = capsys.readouterr()
assert out.startswith('foo: new submodule introduced\n')


def test_main_no_new_submodule(git_dir_with_git_dir):
open('test.py', 'a+').close()
cmd_output('git', 'add', 'test.py')
subprocess.check_call(('git', 'add', 'test.py'))
assert main() == 0

0 comments on commit dbf7de0

Please sign in to comment.