def test_raises_on_error(popen_mock, makedirs_mock):
    popen_mock.return_value.returncode = 1
    with pytest.raises(CalledProcessError):
        instance = PrefixedCommandRunner(
            '.', popen=popen_mock, makedirs=makedirs_mock,
        )
        instance.run(['foo'])
Ejemplo n.º 2
0
def test_raises_on_error(popen_mock, makedirs_mock):
    popen_mock.return_value.returncode = 1
    with pytest.raises(CalledProcessError):
        instance = PrefixedCommandRunner(
            '.',
            popen=popen_mock,
            makedirs=makedirs_mock,
        )
        instance.run(['echo'])
Ejemplo n.º 3
0
 def _cmd_runner_from_deps(self, language_name, deps):
     """local repositories have a cmd runner per hook"""
     language = languages[language_name]
     # pcre / script / system do not have environments so they work out
     # of the current directory
     if language.ENVIRONMENT_DIR is None:
         return PrefixedCommandRunner(git.get_root())
     else:
         return PrefixedCommandRunner(self.store.make_local(deps))
def test_run_substitutes_prefix(popen_mock, makedirs_mock):
    instance = PrefixedCommandRunner(
        'prefix', popen=popen_mock, makedirs=makedirs_mock,
    )
    ret = instance.run(['{prefix}bar', 'baz'], retcode=None)
    popen_mock.assert_called_once_with(
        ['prefix/bar', 'baz'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    assert ret == (popen_mock.return_value.returncode, 'stdout', 'stderr')
Ejemplo n.º 5
0
def test_run_substitutes_prefix(popen_mock, makedirs_mock):
    instance = PrefixedCommandRunner(
        'prefix',
        popen=popen_mock,
        makedirs=makedirs_mock,
    )
    ret = instance.run(['{prefix}bar', 'baz'], retcode=None)
    popen_mock.assert_called_once_with(
        ('prefix/bar', 'baz'),
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    assert ret == (popen_mock.return_value.returncode, 'stdout', 'stderr')
Ejemplo n.º 6
0
def test_from_command_runner_preserves_popen(popen_mock, makedirs_mock):
    first = PrefixedCommandRunner(
        'foo',
        popen=popen_mock,
        makedirs=makedirs_mock,
    )
    second = PrefixedCommandRunner.from_command_runner(first, 'bar')
    second.run(['foo/bar/baz'], retcode=None)
    popen_mock.assert_called_once_with(
        ('foo/bar/baz', ),
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    makedirs_mock.assert_called_once_with('foo/bar/')
def test_from_command_runner_preserves_popen(popen_mock, makedirs_mock):
    first = PrefixedCommandRunner(
        'foo', popen=popen_mock, makedirs=makedirs_mock,
    )
    second = PrefixedCommandRunner.from_command_runner(first, 'bar')
    second.run(['foo/bar/baz'], retcode=None)
    popen_mock.assert_called_once_with(
        ['foo/bar/baz'],
        stdin=subprocess.PIPE,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    makedirs_mock.assert_called_once_with('foo/bar/')
def test_from_command_runner(prefix, path_end, expected_output):
    first = PrefixedCommandRunner(prefix)
    second = PrefixedCommandRunner.from_command_runner(first, path_end)
    assert second.prefix_dir == expected_output
def test_path_multiple_args():
    instance = PrefixedCommandRunner('foo')
    ret = instance.path('bar', 'baz')
    assert ret == os.path.join('foo', 'bar', 'baz')
def test_path(prefix, path_end, expected_output):
    instance = PrefixedCommandRunner(prefix)
    ret = instance.path(path_end)
    assert ret == expected_output
Ejemplo n.º 11
0
 def cmd_runner(self):
     return PrefixedCommandRunner(self.repo_path_getter.repo_path)
Ejemplo n.º 12
0
def test_exists_does_exist(in_tmpdir):
    os.mkdir('foo')
    assert PrefixedCommandRunner('.').exists('foo')
Ejemplo n.º 13
0
def test_exists_does_not_exist(in_tmpdir):
    assert not PrefixedCommandRunner('.').exists('foo')
Ejemplo n.º 14
0
def test_create_path_if_not_exists(in_tmpdir):
    instance = PrefixedCommandRunner('foo')
    assert not os.path.exists('foo')
    instance._create_path_if_not_exists()
    assert os.path.exists('foo')
Ejemplo n.º 15
0
def test_path_multiple_args():
    instance = PrefixedCommandRunner('foo')
    ret = instance.path('bar', 'baz')
    assert ret == os.path.join('foo', 'bar', 'baz')
Ejemplo n.º 16
0
 def _cmd_runner(self):
     return PrefixedCommandRunner(self._repo_path)
def test_create_path_if_not_exists(in_tmpdir):
    instance = PrefixedCommandRunner('foo')
    assert not os.path.exists('foo')
    instance._create_path_if_not_exists()
    assert os.path.exists('foo')
Ejemplo n.º 18
0
 def cmd_runner(self):
     return PrefixedCommandRunner(self.directory)
Ejemplo n.º 19
0
def test_init_normalizes_path_endings(input, expected_prefix):
    input = input.replace('/', os.sep)
    expected_prefix = expected_prefix.replace('/', os.sep)
    instance = PrefixedCommandRunner(input)
    assert instance.prefix_dir == expected_prefix
Ejemplo n.º 20
0
def test_init_normalizes_path_endings(input, expected_prefix):
    instance = PrefixedCommandRunner(input)
    assert instance.prefix_dir == expected_prefix
Ejemplo n.º 21
0
 def cmd_runner(self):
     return PrefixedCommandRunner(git.get_root())
Ejemplo n.º 22
0
def test_path(prefix, path_end, expected_output):
    instance = PrefixedCommandRunner(prefix)
    ret = instance.path(path_end)
    assert ret == expected_output
Ejemplo n.º 23
0
def cmd_runner(tempdir_factory):
    yield PrefixedCommandRunner(tempdir_factory.get())
Ejemplo n.º 24
0
def test_from_command_runner(prefix, path_end, expected_output):
    first = PrefixedCommandRunner(prefix)
    second = PrefixedCommandRunner.from_command_runner(first, path_end)
    assert second.prefix_dir == expected_output