test_parser.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. import os
  5. import sys
  6. import pytest
  7. from mozlint.parser import Parser
  8. from mozlint.errors import (
  9. LinterNotFound,
  10. LinterParseError,
  11. )
  12. @pytest.fixture(scope='module')
  13. def parse(lintdir):
  14. parser = Parser()
  15. def _parse(name):
  16. path = os.path.join(lintdir, name)
  17. return parser(path)
  18. return _parse
  19. def test_parse_valid_linter(parse):
  20. lintobj = parse('string.lint')
  21. assert isinstance(lintobj, dict)
  22. assert 'name' in lintobj
  23. assert 'description' in lintobj
  24. assert 'type' in lintobj
  25. assert 'payload' in lintobj
  26. @pytest.mark.parametrize('linter', [
  27. 'invalid_type.lint',
  28. 'invalid_extension.lnt',
  29. 'invalid_include.lint',
  30. 'invalid_exclude.lint',
  31. 'missing_attrs.lint',
  32. 'missing_definition.lint',
  33. ])
  34. def test_parse_invalid_linter(parse, linter):
  35. with pytest.raises(LinterParseError):
  36. parse(linter)
  37. def test_parse_non_existent_linter(parse):
  38. with pytest.raises(LinterNotFound):
  39. parse('missing_file.lint')
  40. if __name__ == '__main__':
  41. sys.exit(pytest.main(['--verbose', __file__]))