diff options
| author | Georg Brandl <georg@python.org> | 2019-05-06 18:02:47 +0200 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2019-11-10 10:15:13 +0100 |
| commit | 7827966acdb6431636520d20fc3c148ce52de59b (patch) | |
| tree | 13a9316eb3eb964c22da0a08f046d44cd81470d0 /tests/test_basic.py | |
| parent | a281ff8367a3a5f4cc17c9956e9273593558d336 (diff) | |
| download | pygments-git-7827966acdb6431636520d20fc3c148ce52de59b.tar.gz | |
Remove unittest classes from the test suite.
Diffstat (limited to 'tests/test_basic.py')
| -rw-r--r-- | tests/test_basic.py | 123 |
1 files changed, 61 insertions, 62 deletions
diff --git a/tests/test_basic.py b/tests/test_basic.py index 03d10cd2..e2255f5b 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -3,72 +3,71 @@ Pygments Basic lexers tests ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :copyright: Copyright 2006-2016 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ -import unittest + +import pytest from pygments.lexers.basic import VBScriptLexer from pygments.token import Error, Name, Number, Punctuation, String, Whitespace -class VBScriptLexerTest(unittest.TestCase): - - def setUp(self): - self.lexer = VBScriptLexer() - - def _assert_are_tokens_of_type(self, examples, expected_token_type): - for test_number, example in enumerate(examples.split(), 1): - token_count = 0 - for token_type, token_value in self.lexer.get_tokens(example): - if token_type != Whitespace: - token_count += 1 - self.assertEqual( - token_type, expected_token_type, - 'token_type #%d for %s is be %s but must be %s' % - (test_number, token_value, token_type, expected_token_type)) - self.assertEqual( - token_count, 1, - '%s must yield exactly 1 token instead of %d' % - (example, token_count)) - - def _assert_tokens_match(self, text, expected_tokens_without_trailing_newline): - actual_tokens = tuple(self.lexer.get_tokens(text)) - if (len(actual_tokens) >= 1) and (actual_tokens[-1] == (Whitespace, '\n')): - actual_tokens = tuple(actual_tokens[:-1]) - self.assertEqual( - expected_tokens_without_trailing_newline, actual_tokens, - 'text must yield expected tokens: %s' % text) - - def test_can_lex_float(self): - self._assert_are_tokens_of_type( - '1. 1.e1 .1 1.2 1.2e3 1.2e+3 1.2e-3 1e2', Number.Float) - self._assert_tokens_match( - '1e2.1e2', - ((Number.Float, '1e2'), (Number.Float, '.1e2')) - ) - - def test_can_reject_almost_float(self): - self._assert_tokens_match( - '.e1', - ((Punctuation, '.'), (Name, 'e1'))) - - def test_can_lex_integer(self): - self._assert_are_tokens_of_type( - '1 23 456', Number.Integer) - - def test_can_lex_names(self): - self._assert_are_tokens_of_type( - u'thingy thingy123 _thingy _123', Name) - - def test_can_recover_after_unterminated_string(self): - self._assert_tokens_match( - '"x\nx', - ((String.Double, '"'), (String.Double, 'x'), (Error, '\n'), (Name, 'x')) - ) - - def test_can_recover_from_invalid_character(self): - self._assert_tokens_match( - 'a;bc\nd', - ((Name, 'a'), (Error, ';bc\n'), (Name, 'd')) - ) +@pytest.fixture(scope='module') +def lexer(): + yield VBScriptLexer() + + +def assert_are_tokens_of_type(lexer, examples, expected_token_type): + for test_number, example in enumerate(examples.split(), 1): + token_count = 0 + for token_type, token_value in lexer.get_tokens(example): + if token_type != Whitespace: + token_count += 1 + assert token_type == expected_token_type, \ + 'token_type #%d for %s is be %s but must be %s' % \ + (test_number, token_value, token_type, expected_token_type) + assert token_count == 1, \ + '%s must yield exactly 1 token instead of %d' % (example, token_count) + + +def assert_tokens_match(lexer, text, expected_tokens_without_trailing_newline): + actual_tokens = tuple(lexer.get_tokens(text)) + if (len(actual_tokens) >= 1) and (actual_tokens[-1] == (Whitespace, '\n')): + actual_tokens = tuple(actual_tokens[:-1]) + assert expected_tokens_without_trailing_newline == actual_tokens, \ + 'text must yield expected tokens: %s' % text + + +def test_can_lex_float(lexer): + assert_are_tokens_of_type(lexer, + '1. 1.e1 .1 1.2 1.2e3 1.2e+3 1.2e-3 1e2', + Number.Float) + assert_tokens_match(lexer, + '1e2.1e2', + ((Number.Float, '1e2'), (Number.Float, '.1e2'))) + + +def test_can_reject_almost_float(lexer): + assert_tokens_match(lexer, '.e1', ((Punctuation, '.'), (Name, 'e1'))) + + +def test_can_lex_integer(lexer): + assert_are_tokens_of_type(lexer, '1 23 456', Number.Integer) + + +def test_can_lex_names(lexer): + assert_are_tokens_of_type(lexer, u'thingy thingy123 _thingy _123', Name) + + +def test_can_recover_after_unterminated_string(lexer): + assert_tokens_match(lexer, + '"x\nx', + ((String.Double, '"'), (String.Double, 'x'), + (Error, '\n'), (Name, 'x'))) + + +def test_can_recover_from_invalid_character(lexer): + assert_tokens_match(lexer, + 'a;bc\nd', + ((Name, 'a'), (Error, ';bc\n'), (Name, 'd'))) |
