1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00
pip/tests/unit/test_compat.py
2014-05-14 13:10:06 +10:00

37 lines
1 KiB
Python

import os
from pip.compat import get_path_uid
import pytest
def test_get_path_uid():
path = os.getcwd()
assert get_path_uid(path) == os.stat(path).st_uid
@pytest.mark.skipif("not hasattr(os, 'O_NOFOLLOW')")
def test_get_path_uid_without_NOFOLLOW(monkeypatch):
monkeypatch.delattr("os.O_NOFOLLOW")
path = os.getcwd()
assert get_path_uid(path) == os.stat(path).st_uid
@pytest.mark.skipif("not hasattr(os, 'symlink')")
def test_get_path_uid_symlink(tmpdir):
f = tmpdir.mkdir("symlink").join("somefile")
f.write("content")
fs = f + '_link'
os.symlink(f, fs)
with pytest.raises(OSError):
get_path_uid(fs)
@pytest.mark.skipif("not hasattr(os, 'O_NOFOLLOW')")
@pytest.mark.skipif("not hasattr(os, 'symlink')")
def test_get_path_uid_symlink_without_NOFOLLOW(tmpdir, monkeypatch):
monkeypatch.delattr("os.O_NOFOLLOW")
f = tmpdir.mkdir("symlink").join("somefile")
f.write("content")
fs = f + '_link'
os.symlink(f, fs)
with pytest.raises(OSError):
get_path_uid(fs)