|
2 | 2 |
|
3 | 3 | import unittest
|
4 | 4 |
|
| 5 | +from textwrap import dedent, indent |
| 6 | + |
5 | 7 | from unittest_helpers import FIXTURE_DIR, load_fixture
|
6 | 8 |
|
7 | 9 | # NOTE: This test file file only works with scripts/ added to PYTHONPATH so pylint can't find the imports
|
8 | 10 | # pragma pylint: disable=import-error
|
9 | 11 | from isolate_tests import extract_docs_cases
|
10 | 12 | # pragma pylint: enable=import-error
|
11 | 13 |
|
12 |
| - |
13 | 14 | CODE_BLOCK_RST_PATH = FIXTURE_DIR / 'code_block.rst'
|
14 | 15 | CODE_BLOCK_RST_CONTENT = load_fixture(CODE_BLOCK_RST_PATH)
|
15 | 16 | CODE_BLOCK_WITH_DIRECTIVES_RST_PATH = FIXTURE_DIR / 'code_block_with_directives.rst'
|
16 | 17 | CODE_BLOCK_WITH_DIRECTIVES_RST_CONTENT = load_fixture(CODE_BLOCK_WITH_DIRECTIVES_RST_PATH)
|
17 | 18 |
|
| 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" |
18 | 22 |
|
19 | 23 | class TestExtractDocsCases(unittest.TestCase):
|
20 | 24 | def setUp(self):
|
21 | 25 | self.maxDiff = 10000
|
22 | 26 |
|
| 27 | + |
23 | 28 | 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 | + ]] |
37 | 43 |
|
38 | 44 | self.assertEqual(extract_docs_cases(CODE_BLOCK_RST_PATH), expected_cases)
|
39 | 45 |
|
40 | 46 | 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 | + ]] |
61 | 68 |
|
62 | 69 | self.assertEqual(extract_docs_cases(CODE_BLOCK_WITH_DIRECTIVES_RST_PATH), expected_cases)
|
0 commit comments