better no-cover for windows

This commit is contained in:
Anthony Sottile 2018-12-27 17:31:25 -08:00
parent 8c550d0157
commit 2af0b0b4f3
6 changed files with 11 additions and 15 deletions

View file

@ -41,14 +41,14 @@ try: # pragma: no cover (windows)
# "Regions should be locked only briefly and should be unlocked # "Regions should be locked only briefly and should be unlocked
# before closing a file or exiting the program." # before closing a file or exiting the program."
msvcrt.locking(fileno, msvcrt.LK_UNLCK, _region) msvcrt.locking(fileno, msvcrt.LK_UNLCK, _region)
except ImportError: # pragma: no cover (posix) except ImportError: # pragma: windows no cover
import fcntl import fcntl
@contextlib.contextmanager @contextlib.contextmanager
def _locked(fileno, blocked_cb): def _locked(fileno, blocked_cb):
try: try:
fcntl.flock(fileno, fcntl.LOCK_EX | fcntl.LOCK_NB) fcntl.flock(fileno, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError: except IOError: # pragma: no cover (tests are single-threaded)
blocked_cb() blocked_cb()
fcntl.flock(fileno, fcntl.LOCK_EX) fcntl.flock(fileno, fcntl.LOCK_EX)
try: try:

View file

@ -28,7 +28,7 @@ def get_env_patch(venv):
install_prefix = r'{}\bin'.format(win_venv.strip()) install_prefix = r'{}\bin'.format(win_venv.strip())
elif sys.platform == 'win32': # pragma: no cover elif sys.platform == 'win32': # pragma: no cover
install_prefix = bin_dir(venv) install_prefix = bin_dir(venv)
else: else: # pragma: windows no cover
install_prefix = venv install_prefix = venv
return ( return (
('NODE_VIRTUAL_ENV', venv), ('NODE_VIRTUAL_ENV', venv),

View file

@ -84,7 +84,7 @@ def test_install_refuses_core_hookspath(in_git_dir, store):
assert install(C.CONFIG_FILE, store) assert install(C.CONFIG_FILE, store)
@xfailif_no_symlink # pragma: no cover (non-windows) @xfailif_no_symlink # pragma: windows no cover
def test_install_hooks_dead_symlink(in_git_dir, store): def test_install_hooks_dead_symlink(in_git_dir, store):
hook = in_git_dir.join('.git/hooks').ensure_dir().join('pre-commit') hook = in_git_dir.join('.git/hooks').ensure_dir().join('pre-commit')
os.symlink('/fake/baz', hook.strpath) os.symlink('/fake/baz', hook.strpath)

View file

@ -781,8 +781,8 @@ def test_include_exclude_base_case(some_filenames):
] ]
@xfailif_no_symlink @xfailif_no_symlink # pragma: windows no cover
def test_matches_broken_symlink(tmpdir): # pragma: no cover (non-windows) def test_matches_broken_symlink(tmpdir):
with tmpdir.as_cwd(): with tmpdir.as_cwd():
os.symlink('does-not-exist', 'link') os.symlink('does-not-exist', 'link')
ret = _filter_by_include_exclude({'link'}, '', '^$') ret = _filter_by_include_exclude({'link'}, '', '^$')

View file

@ -11,7 +11,7 @@ def test_norm_version_expanduser():
if os.name == 'nt': # pragma: no cover (nt) if os.name == 'nt': # pragma: no cover (nt)
path = r'~\python343' path = r'~\python343'
expected_path = r'{}\python343'.format(home) expected_path = r'{}\python343'.format(home)
else: # pragma: no cover (non-nt) else: # pragma: windows no cover
path = '~/.pyenv/versions/3.4.3/bin/python' path = '~/.pyenv/versions/3.4.3/bin/python'
expected_path = home + '/.pyenv/versions/3.4.3/bin/python' expected_path = home + '/.pyenv/versions/3.4.3/bin/python'
result = python.norm_version(path) result = python.norm_version(path)

View file

@ -502,10 +502,8 @@ def test_additional_dependencies_roll_forward(tempdir_factory, store):
assert 'mccabe' not in cmd_output('pip', 'freeze', '-l')[1] assert 'mccabe' not in cmd_output('pip', 'freeze', '-l')[1]
@xfailif_windows_no_ruby @xfailif_windows_no_ruby # pragma: windows no cover
def test_additional_ruby_dependencies_installed( def test_additional_ruby_dependencies_installed(tempdir_factory, store):
tempdir_factory, store,
): # pragma: no cover (non-windows)
path = make_repo(tempdir_factory, 'ruby_hooks_repo') path = make_repo(tempdir_factory, 'ruby_hooks_repo')
config = make_config_from_repo(path) config = make_config_from_repo(path)
config['hooks'][0]['additional_dependencies'] = ['thread_safe', 'tins'] config['hooks'][0]['additional_dependencies'] = ['thread_safe', 'tins']
@ -518,10 +516,8 @@ def test_additional_ruby_dependencies_installed(
assert 'tins' in output assert 'tins' in output
@xfailif_broken_deep_listdir @xfailif_broken_deep_listdir # pragma: windows no cover
def test_additional_node_dependencies_installed( def test_additional_node_dependencies_installed(tempdir_factory, store):
tempdir_factory, store,
): # pragma: no cover (non-windows)
path = make_repo(tempdir_factory, 'node_hooks_repo') path = make_repo(tempdir_factory, 'node_hooks_repo')
config = make_config_from_repo(path) config = make_config_from_repo(path)
# Careful to choose a small package that's not depped by npm # Careful to choose a small package that's not depped by npm