mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-27 03:18:39 -06:00
Handle CPU detection errors and running on Travis
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from pre_commit.languages import helpers
|
||||
@@ -28,3 +31,25 @@ def test_failed_setup_command_does_not_unicode_error():
|
||||
# an assertion that this does not raise `UnicodeError`
|
||||
with pytest.raises(CalledProcessError):
|
||||
helpers.run_setup_cmd(Prefix('.'), (sys.executable, '-c', script))
|
||||
|
||||
|
||||
def test_target_concurrency_normal():
|
||||
with mock.patch.object(multiprocessing, 'cpu_count', return_value=123):
|
||||
with mock.patch.dict(os.environ, {}, clear=True):
|
||||
assert helpers.target_concurrency({'require_serial': False}) == 123
|
||||
|
||||
|
||||
def test_target_concurrency_cpu_count_require_serial_true():
|
||||
assert helpers.target_concurrency({'require_serial': True}) == 1
|
||||
|
||||
|
||||
def test_target_concurrency_on_travis():
|
||||
with mock.patch.dict(os.environ, {'TRAVIS': '1'}, clear=True):
|
||||
assert helpers.target_concurrency({'require_serial': False}) == 2
|
||||
|
||||
|
||||
def test_target_concurrency_cpu_count_not_implemented():
|
||||
with mock.patch.object(
|
||||
multiprocessing, 'cpu_count', side_effect=NotImplementedError,
|
||||
):
|
||||
assert helpers.target_concurrency({'require_serial': False}) == 1
|
||||
|
||||
Reference in New Issue
Block a user