mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
import pytest
|
|
|
|
from tools import lint_requirements
|
|
|
|
|
|
def test_ok(tmp_path):
|
|
f = tmp_path.joinpath("f.txt")
|
|
f.write_text(
|
|
"# allow comments\n"
|
|
"# and allow pip settings\n"
|
|
"--index-url https://pypi.devinfra.sentry.io/simple\n"
|
|
"a==1\n"
|
|
"b==2\n"
|
|
)
|
|
assert lint_requirements.main((str(f),)) == 0
|
|
|
|
|
|
def test_not_ok_classic_git_url(tmp_path):
|
|
f = tmp_path.joinpath("f.txt")
|
|
f.write_text("git+https://github.com/asottile/[email protected]#egg=astpretty")
|
|
|
|
with pytest.raises(SystemExit) as excinfo:
|
|
lint_requirements.main((str(f),))
|
|
|
|
expected = f"""\
|
|
You cannot use dependencies that are not on PyPI directly.
|
|
See PEP440: https://www.python.org/dev/peps/pep-0440/#direct-references
|
|
|
|
{f}:1: git+https://github.com/asottile/[email protected]#egg=astpretty
|
|
"""
|
|
(msg,) = excinfo.value.args
|
|
assert msg == expected.rstrip()
|
|
|
|
|
|
def test_not_ok_new_style_git_url(tmp_path):
|
|
f = tmp_path.joinpath("f.txt")
|
|
f.write_text("astpretty @ git+https://github.com/asottile/[email protected]")
|
|
|
|
with pytest.raises(SystemExit) as excinfo:
|
|
lint_requirements.main((str(f),))
|
|
|
|
expected = f"""\
|
|
You cannot use dependencies that are not on PyPI directly.
|
|
See PEP440: https://www.python.org/dev/peps/pep-0440/#direct-references
|
|
|
|
{f}:1: astpretty @ git+https://github.com/asottile/[email protected]
|
|
"""
|
|
(msg,) = excinfo.value.args
|
|
assert msg == expected.rstrip()
|