Skip to content

Commit 9a0da17

Browse files
committed
Use more readable and maintainable multiline strings in py test script
1 parent 5291ca2 commit 9a0da17

File tree

1 file changed

+41
-34
lines changed

1 file changed

+41
-34
lines changed

test/scripts/test_isolate_tests.py

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,68 @@
22

33
import unittest
44

5+
from textwrap import dedent, indent
6+
57
from unittest_helpers import FIXTURE_DIR, load_fixture
68

79
# NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports
810
# pragma pylint: disable=import-error
911
from isolate_tests import extract_docs_cases
1012
# pragma pylint: enable=import-error
1113

12-
1314
CODE_BLOCK_RST_PATH = FIXTURE_DIR / 'code_block.rst'
1415
CODE_BLOCK_RST_CONTENT = load_fixture(CODE_BLOCK_RST_PATH)
1516
CODE_BLOCK_WITH_DIRECTIVES_RST_PATH = FIXTURE_DIR / 'code_block_with_directives.rst'
1617
CODE_BLOCK_WITH_DIRECTIVES_RST_CONTENT = load_fixture(CODE_BLOCK_WITH_DIRECTIVES_RST_PATH)
1718

19+
def formatCase(text):
20+
"""Formats code to contain only one indentation and terminate with a \n"""
21+
return indent(dedent(text.lstrip("\n")), " ") + "\n"
1822

1923
class TestExtractDocsCases(unittest.TestCase):
2024
def setUp(self):
2125
self.maxDiff = 10000
2226

27+
2328
def test_solidity_block(self):
24-
expected_cases = [
25-
" // SPDX-License-Identifier: GPL-3.0\n"
26-
" pragma solidity >=0.7.0 <0.9.0;\n"
27-
"\n"
28-
" contract C {\n"
29-
" function foo() public view {}\n"
30-
" }\n"
31-
"\n"
32-
"\n",
33-
34-
" contract C {}\n"
35-
"\n",
36-
]
29+
expected_cases = [formatCase(case) for case in [
30+
"""
31+
// SPDX-License-Identifier: GPL-3.0
32+
pragma solidity >=0.7.0 <0.9.0;
33+
34+
contract C {
35+
function foo() public view {}
36+
}
37+
38+
""",
39+
"""
40+
contract C {}
41+
""",
42+
]]
3743

3844
self.assertEqual(extract_docs_cases(CODE_BLOCK_RST_PATH), expected_cases)
3945

4046
def test_solidity_block_with_directives(self):
41-
expected_cases = [
42-
" // SPDX-License-Identifier: GPL-3.0\n"
43-
" pragma solidity >=0.7.0 <0.9.0;\n"
44-
"\n"
45-
" contract C {\n"
46-
" function foo() public view {}\n"
47-
" }\n"
48-
"\n"
49-
"\n",
50-
51-
" contract C {}\n"
52-
"\n",
53-
54-
" contract D {}\n"
55-
" :linenos:\n"
56-
"\n",
57-
58-
" contract E {}\n"
59-
"\n",
60-
]
47+
expected_cases = [formatCase(case) for case in [
48+
"""
49+
// SPDX-License-Identifier: GPL-3.0
50+
pragma solidity >=0.7.0 <0.9.0;
51+
52+
contract C {
53+
function foo() public view {}
54+
}
55+
56+
""",
57+
"""
58+
contract C {}
59+
""",
60+
"""
61+
contract D {}
62+
:linenos:
63+
""",
64+
"""
65+
contract E {}
66+
""",
67+
]]
6168

6269
self.assertEqual(extract_docs_cases(CODE_BLOCK_WITH_DIRECTIVES_RST_PATH), expected_cases)

0 commit comments

Comments
 (0)