1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
import re
import pytest
class TestMismatchedBrackets:
def test_it_knows_about_mismatched_square_from_parenthesis(self):
original = """
def wat(self:
pass
things = "]"
def things]self:
pass
"""
expected = re.escape(
"Trying to close the wrong type of bracket. Found ']' (line 6, column 10) instead of closing a '(' (line 1, column 7)"
)
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_mismatched_square_from_curly(self):
original = """
def wat{self:
pass
def things]self:
pass
"""
expected = re.escape(
"Trying to close the wrong type of bracket. Found ']' (line 4, column 10) instead of closing a '{' (line 1, column 7)"
)
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_mismatched_parenthesis_from_square(self):
original = """
def wat[self:
pass
def things)self:
pass
"""
expected = re.escape(
"Trying to close the wrong type of bracket. Found ')' (line 4, column 10) instead of closing a '[' (line 1, column 7)"
)
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_hanging_square(self):
original = """
def wat(self):
pass
def things]self:
pass
"""
expected = re.escape("Found a hanging ']' on line 4, column 10")
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_hanging_parenthesis(self):
original = """
def wat(self)):
pass
"""
expected = re.escape("Found a hanging ')' on line 1, column 13")
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_hanging_curly(self):
original = """
class Wat:
def __init__(self):
self.d = {1: 2}}
"""
expected = re.escape("Found a hanging '}' on line 3, column 23")
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_unclosed_parenthesis(self):
original = """
def thing(self):
pass
def wat(self:
pass
"""
expected = re.escape("Found an open '(' (line 4, column 7) that wasn't closed")
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_unclosed_square(self):
original = """
def thing(self):
pass
things = [1, 2
"""
expected = re.escape("Found an open '[' (line 4, column 9) that wasn't closed")
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
def test_it_knows_about_unclosed_curly(self):
original = """
def thing(self):
pass
things = [1, 2]
stuff = {1: 2
"""
expected = re.escape("Found an open '{' (line 6, column 8) that wasn't closed")
with pytest.raises(SyntaxError, match=expected):
pytest.helpers.assert_conversion(original, "")
|