Remove a unittest.TestCase usage and replace it with pytest tests.

This commit is contained in:
Dave Halter
2017-05-17 14:15:57 -04:00
parent a1675dfe2e
commit b8005a4908

View File

@@ -9,14 +9,11 @@ from parso import tokenize
from parso.python import parse from parso.python import parse
from parso.tokenize import TokenInfo from parso.tokenize import TokenInfo
from .helpers import unittest
def _get_token_list(string): def _get_token_list(string):
return list(tokenize.source_tokens(string)) return list(tokenize.source_tokens(string))
class TokenTest(unittest.TestCase): def test_end_pos_one_line():
def test_end_pos_one_line(self):
parsed = parse(dedent(''' parsed = parse(dedent('''
def testit(): def testit():
a = "huhu" a = "huhu"
@@ -25,7 +22,7 @@ class TokenTest(unittest.TestCase):
string = simple_stmt.children[0].get_rhs() string = simple_stmt.children[0].get_rhs()
assert string.end_pos == (3, 14) assert string.end_pos == (3, 14)
def test_end_pos_multi_line(self): def test_end_pos_multi_line():
parsed = parse(dedent(''' parsed = parse(dedent('''
def testit(): def testit():
a = """huhu a = """huhu
@@ -35,7 +32,7 @@ class TokenTest(unittest.TestCase):
string_leaf = expr_stmt.get_rhs().children[0] string_leaf = expr_stmt.get_rhs().children[0]
assert string_leaf.end_pos == (4, 11) assert string_leaf.end_pos == (4, 11)
def test_simple_no_whitespace(self): def test_simple_no_whitespace():
# Test a simple one line string, no preceding whitespace # Test a simple one line string, no preceding whitespace
simple_docstring = '"""simple one line docstring"""' simple_docstring = '"""simple one line docstring"""'
tokens = tokenize.source_tokens(simple_docstring) tokens = tokenize.source_tokens(simple_docstring)
@@ -44,7 +41,7 @@ class TokenTest(unittest.TestCase):
assert prefix == '' assert prefix == ''
assert value == '"""simple one line docstring"""' assert value == '"""simple one line docstring"""'
def test_simple_with_whitespace(self): def test_simple_with_whitespace():
# Test a simple one line string with preceding whitespace and newline # Test a simple one line string with preceding whitespace and newline
simple_docstring = ' """simple one line docstring""" \r\n' simple_docstring = ' """simple one line docstring""" \r\n'
tokens = tokenize.source_tokens(simple_docstring) tokens = tokenize.source_tokens(simple_docstring)
@@ -58,7 +55,7 @@ class TokenTest(unittest.TestCase):
assert prefix == ' ' assert prefix == ' '
assert typ == NEWLINE assert typ == NEWLINE
def test_function_whitespace(self): def test_function_whitespace():
# Test function definition whitespace identification # Test function definition whitespace identification
fundef = dedent(''' fundef = dedent('''
def test_whitespace(*args, **kwargs): def test_whitespace(*args, **kwargs):
@@ -82,7 +79,7 @@ class TokenTest(unittest.TestCase):
if value == 'if': if value == 'if':
assert prefix == ' ' assert prefix == ' '
def test_tokenize_multiline_I(self): def test_tokenize_multiline_I():
# Make sure multiline string having newlines have the end marker on the # Make sure multiline string having newlines have the end marker on the
# next line # next line
fundef = '''""""\n''' fundef = '''""""\n'''
@@ -91,7 +88,7 @@ class TokenTest(unittest.TestCase):
assert token_list == [TokenInfo(ERRORTOKEN, '""""\n', (1, 0), ''), assert token_list == [TokenInfo(ERRORTOKEN, '""""\n', (1, 0), ''),
TokenInfo(ENDMARKER , '', (2, 0), '')] TokenInfo(ENDMARKER , '', (2, 0), '')]
def test_tokenize_multiline_II(self): def test_tokenize_multiline_II():
# Make sure multiline string having no newlines have the end marker on # Make sure multiline string having no newlines have the end marker on
# same line # same line
fundef = '''""""''' fundef = '''""""'''
@@ -100,7 +97,7 @@ class TokenTest(unittest.TestCase):
assert token_list == [TokenInfo(ERRORTOKEN, '""""', (1, 0), ''), assert token_list == [TokenInfo(ERRORTOKEN, '""""', (1, 0), ''),
TokenInfo(ENDMARKER, '', (1, 4), '')] TokenInfo(ENDMARKER, '', (1, 4), '')]
def test_tokenize_multiline_III(self): def test_tokenize_multiline_III():
# Make sure multiline string having newlines have the end marker on the # Make sure multiline string having newlines have the end marker on the
# next line even if several newline # next line even if several newline
fundef = '''""""\n\n''' fundef = '''""""\n\n'''
@@ -109,7 +106,7 @@ class TokenTest(unittest.TestCase):
assert token_list == [TokenInfo(ERRORTOKEN, '""""\n\n', (1, 0), ''), assert token_list == [TokenInfo(ERRORTOKEN, '""""\n\n', (1, 0), ''),
TokenInfo(ENDMARKER, '', (3, 0), '')] TokenInfo(ENDMARKER, '', (3, 0), '')]
def test_identifier_contains_unicode(self): def test_identifier_contains_unicode():
fundef = dedent(''' fundef = dedent('''
def 我あφ(): def 我あφ():
pass pass
@@ -124,8 +121,7 @@ class TokenTest(unittest.TestCase):
# They will be ignored in the parser, that's ok. # They will be ignored in the parser, that's ok.
assert unicode_token[0] == OP assert unicode_token[0] == OP
def test_quoted_strings(self): def test_quoted_strings():
string_tokens = [ string_tokens = [
'u"test"', 'u"test"',
'u"""test"""', 'u"""test"""',