test_pep8.py 971 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 not issues('asdf = 1\r\n')
  14. assert not issues('asdf = 1\r')
  15. assert_issue('asdf = 1')
  16. assert_issue('asdf = 1\n# foo')
  17. assert_issue('# foobar')
  18. assert_issue('')
  19. assert_issue('foo = 1 # comment')
  20. def test_eof_blankline():
  21. def assert_issue(code):
  22. found = issues(code)
  23. assert len(found) == 1
  24. issue, = found
  25. assert issue.code == 391
  26. assert_issue('asdf = 1\n\n')
  27. assert_issue('# foobar\n\n')
  28. assert_issue('\n\n')
  29. def test_shebang():
  30. assert not issues('#!\n')
  31. assert not issues('#!/foo\n')
  32. assert not issues('#! python\n')