Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
kavigupta committed Feb 13, 2024
1 parent c9a264f commit a0e1ed7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/types_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class TypeAnnotationTest(DisplayAnnotatedTestCase):
def test_basic_assignment(self):
annotated_code = """
@{g}f
{g}class A:
@{g}f{<3.8!g}
{>=3.8!g}class A:
pass
{g}class B({g}A, x={g}A):
Expand Down
9 changes: 5 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sys
import ast
import re
Expand Down Expand Up @@ -106,10 +105,12 @@ def _check_nodes(self, mapping, *scopes):

def assertAnnotationWorks(self, annotated_code, code=None, *, class_binds_near=False):
# directives of the form {>version!scope} are removed unless the version is satisfied
regex = r"\{>=(\d+\.\d+)!([^\}]+)\}"
regex = r"\{(<|>=)(\d+\.\d+)!([^\}]+)\}"
def replacer(match):
version, scope = match.groups()
if sys.version_info >= tuple(map(int, version.split("."))):
comparator, version, scope = match.groups()
geq_expected = comparator == ">="
geq_actual = sys.version_info >= tuple(map(int, version.split(".")))
if geq_actual == geq_expected:
return "{" + scope + "}"
return ""
annotated_code = re.sub(regex, replacer, annotated_code)
Expand Down

0 comments on commit a0e1ed7

Please sign in to comment.