Skip to content

Commit

Permalink
Fix unit tests for Python <3.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dflook committed May 27, 2023
1 parent cc65432 commit 4fcba07
Showing 1 changed file with 27 additions and 64 deletions.
91 changes: 27 additions & 64 deletions test/test_remove_literal_statements.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ast
import sys

import pytest

Expand All @@ -17,17 +18,24 @@
- function and class docstrings are suppressed by __doc__ attribute references; Test references in module scope, function scope and class scope
"""

if sys.version_info < (3, 3):
CONSTANTS = ''
elif sys.version_info < (3, 4):
CONSTANTS = ['...']
else:
CONSTANTS = ['...', 'True', 'False', 'None']

def insert_constants(indent=0):
indent_str = (' ' * indent)
return ('\n' + indent_str).join(constant for constant in CONSTANTS)

source = '''
"""Module docstring"""
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants() + '''
0.123
1.23e-4
Expand All @@ -36,10 +44,7 @@ def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
Expand All @@ -48,10 +53,7 @@ class Test:
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
Expand All @@ -60,10 +62,7 @@ def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(8) + '''
0.123
1.23e-4
'''
Expand Down Expand Up @@ -155,10 +154,7 @@ def test_remove_module_docstring():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants() + '''
0.123
1.23e-4
Expand All @@ -167,10 +163,7 @@ def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
Expand All @@ -179,10 +172,7 @@ class Test:
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
Expand All @@ -191,10 +181,7 @@ def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(8) + '''
0.123
1.23e-4
'''
Expand Down Expand Up @@ -241,21 +228,15 @@ def test_remove_function_docstring():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants() + '''
0.123
1.23e-4
def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
Expand All @@ -264,21 +245,15 @@ class Test:
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(8) + '''
0.123
1.23e-4
'''
Expand Down Expand Up @@ -326,10 +301,7 @@ def test_remove_class_docstring():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants() + '''
0.123
1.23e-4
Expand All @@ -338,21 +310,15 @@ def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
class Test:
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(4) + '''
0.123
1.23e-4
Expand All @@ -361,10 +327,7 @@ def test():
"Module literal"
b"Module literal"
213
True
False
None
...
''' + insert_constants(8) + '''
0.123
1.23e-4
'''
Expand Down

0 comments on commit 4fcba07

Please sign in to comment.