mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Use more readable and maintainable multiline strings in py test script
This commit is contained in:
parent
5291ca2dd4
commit
9a0da17a6d
@ -2,6 +2,8 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from textwrap import dedent, indent
|
||||
|
||||
from unittest_helpers import FIXTURE_DIR, load_fixture
|
||||
|
||||
# NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports
|
||||
@ -9,54 +11,59 @@ from unittest_helpers import FIXTURE_DIR, load_fixture
|
||||
from isolate_tests import extract_docs_cases
|
||||
# pragma pylint: enable=import-error
|
||||
|
||||
|
||||
CODE_BLOCK_RST_PATH = FIXTURE_DIR / 'code_block.rst'
|
||||
CODE_BLOCK_RST_CONTENT = load_fixture(CODE_BLOCK_RST_PATH)
|
||||
CODE_BLOCK_WITH_DIRECTIVES_RST_PATH = FIXTURE_DIR / 'code_block_with_directives.rst'
|
||||
CODE_BLOCK_WITH_DIRECTIVES_RST_CONTENT = load_fixture(CODE_BLOCK_WITH_DIRECTIVES_RST_PATH)
|
||||
|
||||
def formatCase(text):
|
||||
"""Formats code to contain only one indentation and terminate with a \n"""
|
||||
return indent(dedent(text.lstrip("\n")), " ") + "\n"
|
||||
|
||||
class TestExtractDocsCases(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.maxDiff = 10000
|
||||
|
||||
def test_solidity_block(self):
|
||||
expected_cases = [
|
||||
" // SPDX-License-Identifier: GPL-3.0\n"
|
||||
" pragma solidity >=0.7.0 <0.9.0;\n"
|
||||
"\n"
|
||||
" contract C {\n"
|
||||
" function foo() public view {}\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"\n",
|
||||
|
||||
" contract C {}\n"
|
||||
"\n",
|
||||
]
|
||||
def test_solidity_block(self):
|
||||
expected_cases = [formatCase(case) for case in [
|
||||
"""
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.7.0 <0.9.0;
|
||||
|
||||
contract C {
|
||||
function foo() public view {}
|
||||
}
|
||||
|
||||
""",
|
||||
"""
|
||||
contract C {}
|
||||
""",
|
||||
]]
|
||||
|
||||
self.assertEqual(extract_docs_cases(CODE_BLOCK_RST_PATH), expected_cases)
|
||||
|
||||
def test_solidity_block_with_directives(self):
|
||||
expected_cases = [
|
||||
" // SPDX-License-Identifier: GPL-3.0\n"
|
||||
" pragma solidity >=0.7.0 <0.9.0;\n"
|
||||
"\n"
|
||||
" contract C {\n"
|
||||
" function foo() public view {}\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"\n",
|
||||
expected_cases = [formatCase(case) for case in [
|
||||
"""
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity >=0.7.0 <0.9.0;
|
||||
|
||||
" contract C {}\n"
|
||||
"\n",
|
||||
contract C {
|
||||
function foo() public view {}
|
||||
}
|
||||
|
||||
" contract D {}\n"
|
||||
" :linenos:\n"
|
||||
"\n",
|
||||
|
||||
" contract E {}\n"
|
||||
"\n",
|
||||
]
|
||||
""",
|
||||
"""
|
||||
contract C {}
|
||||
""",
|
||||
"""
|
||||
contract D {}
|
||||
:linenos:
|
||||
""",
|
||||
"""
|
||||
contract E {}
|
||||
""",
|
||||
]]
|
||||
|
||||
self.assertEqual(extract_docs_cases(CODE_BLOCK_WITH_DIRECTIVES_RST_PATH), expected_cases)
|
||||
|
Loading…
Reference in New Issue
Block a user