test_pep8.py 896 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import parso
  2. def issues(code):
  3. grammar = parso.load_grammar()
  4. module = parso.parse(code)
  5. return grammar._get_normalizer_issues(module)
  6. def test_eof_newline():
  7. def assert_issue(code):
  8. found = issues(code)
  9. assert len(found) == 1
  10. issue, = found
  11. assert issue.code == 292
  12. assert not issues('asdf = 1\n')
  13. assert_issue('asdf = 1')
  14. assert_issue('asdf = 1\n# foo')
  15. assert_issue('# foobar')
  16. assert_issue('')
  17. assert_issue('foo = 1 # comment')
  18. def test_eof_blankline():
  19. def assert_issue(code):
  20. found = issues(code)
  21. assert len(found) == 1
  22. issue, = found
  23. assert issue.code == 391
  24. assert_issue('asdf = 1\n\n')
  25. assert_issue('# foobar\n\n')
  26. assert_issue('\n\n')
  27. def test_shebang():
  28. assert not issues('#!\n')
  29. assert not issues('#!/foo\n')
  30. assert not issues('#! python\n')