test_lint_requirements.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import pytest
  2. from tools import lint_requirements
  3. def test_ok(tmp_path):
  4. f = tmp_path.joinpath("f.txt")
  5. f.write_text(
  6. "# allow comments\n"
  7. "# and allow pip settings\n"
  8. "--index-url https://pypi.devinfra.sentry.io/simple\n"
  9. "a==1\n"
  10. "b==2\n"
  11. )
  12. assert lint_requirements.main((str(f),)) == 0
  13. def test_not_ok_classic_git_url(tmp_path):
  14. f = tmp_path.joinpath("f.txt")
  15. f.write_text("git+https://github.com/asottile/astpretty@3.0.0#egg=astpretty")
  16. with pytest.raises(SystemExit) as excinfo:
  17. lint_requirements.main((str(f),))
  18. expected = f"""\
  19. You cannot use dependencies that are not on PyPI directly.
  20. See PEP440: https://www.python.org/dev/peps/pep-0440/#direct-references
  21. {f}:1: git+https://github.com/asottile/astpretty@3.0.0#egg=astpretty
  22. """
  23. (msg,) = excinfo.value.args
  24. assert msg == expected.rstrip()
  25. def test_not_ok_new_style_git_url(tmp_path):
  26. f = tmp_path.joinpath("f.txt")
  27. f.write_text("astpretty @ git+https://github.com/asottile/astpretty@3.0.0")
  28. with pytest.raises(SystemExit) as excinfo:
  29. lint_requirements.main((str(f),))
  30. expected = f"""\
  31. You cannot use dependencies that are not on PyPI directly.
  32. See PEP440: https://www.python.org/dev/peps/pep-0440/#direct-references
  33. {f}:1: astpretty @ git+https://github.com/asottile/astpretty@3.0.0
  34. """
  35. (msg,) = excinfo.value.args
  36. assert msg == expected.rstrip()