11from __future__ import absolute_import
22from __future__ import unicode_literals
33
4+ import multiprocessing
5+ import os
46import sys
57
8+ import mock
69import pytest
710
811from pre_commit .languages import helpers
@@ -28,3 +31,25 @@ def test_failed_setup_command_does_not_unicode_error():
2831 # an assertion that this does not raise `UnicodeError`
2932 with pytest .raises (CalledProcessError ):
3033 helpers .run_setup_cmd (Prefix ('.' ), (sys .executable , '-c' , script ))
34+
35+
36+ def test_target_concurrency_normal ():
37+ with mock .patch .object (multiprocessing , 'cpu_count' , return_value = 123 ):
38+ with mock .patch .dict (os .environ , {}, clear = True ):
39+ assert helpers .target_concurrency ({'require_serial' : False }) == 123
40+
41+
42+ def test_target_concurrency_cpu_count_require_serial_true ():
43+ assert helpers .target_concurrency ({'require_serial' : True }) == 1
44+
45+
46+ def test_target_concurrency_on_travis ():
47+ with mock .patch .dict (os .environ , {'TRAVIS' : '1' }, clear = True ):
48+ assert helpers .target_concurrency ({'require_serial' : False }) == 2
49+
50+
51+ def test_target_concurrency_cpu_count_not_implemented ():
52+ with mock .patch .object (
53+ multiprocessing , 'cpu_count' , side_effect = NotImplementedError ,
54+ ):
55+ assert helpers .target_concurrency ({'require_serial' : False }) == 1
0 commit comments