test_load_grammar.py 979 B

12345678910111213141516171819202122232425262728293031
  1. import pytest
  2. from parso.grammar import load_grammar
  3. from parso import utils
  4. def test_load_inexisting_grammar():
  5. # This version shouldn't be out for a while, but if we ever do, wow!
  6. with pytest.raises(NotImplementedError):
  7. load_grammar(version='15.8')
  8. # The same is true for very old grammars (even though this is probably not
  9. # going to be an issue.
  10. with pytest.raises(NotImplementedError):
  11. load_grammar(version='1.5')
  12. @pytest.mark.parametrize(('string', 'result'), [
  13. ('2', (2, 7)), ('3', (3, 6)), ('1.1', (1, 1)), ('1.1.1', (1, 1)), ('300.1.31', (300, 1))
  14. ])
  15. def test_parse_version(string, result):
  16. assert utils._parse_version(string) == result
  17. @pytest.mark.parametrize('string', ['1.', 'a', '#', '1.3.4.5'])
  18. def test_invalid_grammar_version(string):
  19. with pytest.raises(ValueError):
  20. load_grammar(version=string)
  21. def test_grammar_int_version():
  22. with pytest.raises(TypeError):
  23. load_grammar(version=3.8)