quizcomp.parser.parse_parsertest
1import glob 2import os 3import re 4import typing 5 6import edq.util.json 7import edq.util.serial 8 9import quizcomp.model.constants 10import quizcomp.parser.common 11import quizcomp.parser.document 12import quizcomp.testing.base 13import quizcomp.util.html 14 15THIS_DIR: str = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) 16TESTDATA_DIR: str = os.path.join(THIS_DIR, 'testdata') 17 18DOCUMENTS_DIR = os.path.join(TESTDATA_DIR, 'documents') 19GOOD_DOCUMENTS_DIR = os.path.join(DOCUMENTS_DIR, "good") 20BAD_DOCUMENTS_DIR = os.path.join(DOCUMENTS_DIR, "bad") 21 22class TestParser(quizcomp.testing.base.BaseTest): 23 """ 24 Test parsing text. 25 Good and bad situations will be loaded from files into individual test methods. 26 """ 27 28def _add_good_parse_questions() -> None: 29 """ Add test cases for parsing valid documents. """ 30 31 paths = sorted(glob.glob(os.path.join(GOOD_DOCUMENTS_DIR, "**", "*.json"), recursive = True)) 32 for path in paths: 33 test_cases = edq.util.json.load_path(path) 34 base_dir = os.path.dirname(path) 35 36 for test_case in test_cases: 37 name = test_case['name'] 38 text = test_case['text'] 39 40 context = quizcomp.parser.common.RenderContext(**test_case.get('context', {})) 41 context.base_dir = base_dir 42 43 for (raw_doc_format, expected) in test_case['formats'].items(): 44 doc_format = quizcomp.model.constants.Format(raw_doc_format) 45 test_name = _make_name('good_parse', path, name, doc_format) 46 options = test_case.get('options', {}).get(doc_format.value, {}) 47 setattr(TestParser, test_name, _get_good_parse_test(text, doc_format, expected, options, context)) 48 49def _get_good_parse_test( 50 text: str, 51 doc_format: quizcomp.model.constants.Format, 52 base_expected: typing.Union[str, typing.List[typing.Dict[str, typing.Any]], typing.Dict[str, typing.Any]], 53 options: typing.Dict[str, typing.Any], 54 context: quizcomp.parser.common.RenderContext, 55 ) -> typing.Callable: 56 """ Get a test method for a valid document. """ 57 58 def __method(self: TestParser) -> None: 59 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 60 result = document.to_format(doc_format, context = context) 61 62 if (doc_format == quizcomp.model.constants.Format.JSON): 63 result = edq.util.json.loads(result) 64 expected: typing.Any = { 65 'text': text.strip(), 66 'ast': { 67 'type': 'root', 68 }, 69 } 70 71 expected_children = [] 72 if (len(base_expected) > 0): 73 if (isinstance(base_expected, list)): 74 expected_children += base_expected 75 elif (isinstance(base_expected, dict)): 76 expected_children.append(base_expected) 77 else: 78 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 79 80 if (len(expected_children) > 0): 81 # If the first node is not the root block, then automatically insert it. 82 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 83 expected_children = [{ 84 'type': 'container_block', 85 'children': expected_children, 86 'attributes': { 87 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 88 }, 89 }] 90 91 expected['ast']['children'] = expected_children 92 93 self.assertJSONDictEqual(expected, result) 94 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 95 # If the HTML does not have a root block, then add one. 96 raw_expected = str(base_expected) 97 if (options.get('strip', True)): 98 raw_expected = raw_expected.strip() 99 100 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 101 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 102 103 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 104 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 105 106 expected, result = _apply_text_options(options, expected, result) 107 self.assertEqual(expected, result) 108 else: 109 expected = str(base_expected).strip() 110 result = result.strip() 111 112 expected, result = _apply_text_options(options, expected, result) 113 self.assertEqual(expected, result) 114 115 return __method 116 117def _add_bad_parse_questions() -> None: 118 """ Add test cases for parsing invalid documents. """ 119 120 paths = sorted(glob.glob(os.path.join(BAD_DOCUMENTS_DIR, "**", "*.json"), recursive = True)) 121 for path in paths: 122 test_cases = edq.util.json.load_path(path) 123 base_dir = os.path.dirname(path) 124 125 for test_case in test_cases: 126 name = test_case['name'] 127 text = test_case['text'] 128 options = test_case.get('options', {}) 129 130 context = quizcomp.parser.common.RenderContext(**test_case.get('context', {})) 131 context.base_dir = base_dir 132 133 test_name = _make_name('bad_parse', path, name) 134 setattr(TestParser, test_name, _get_bad_parse_test(text, options, context)) 135 136def _get_bad_parse_test( 137 text: str, 138 options: typing.Dict[str, typing.Any], 139 context: quizcomp.parser.common.RenderContext, 140 ) -> typing.Callable: 141 """ Get a test method for an invalid document. """ 142 143 def __method(self: TestParser) -> None: 144 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 145 try: 146 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 147 except Exception: 148 # Expected. 149 return 150 151 self.fail("Failed to raise an exception.") 152 153 return __method 154 155def _make_name(prefix: str, path: str, name: str, doc_format: typing.Union[quizcomp.model.constants.Format, None] = None) -> str: 156 """ Create a name for a test case. """ 157 158 clean_name = quizcomp.testing.base.clean_name_part(name) 159 160 filename = os.path.splitext(os.path.basename(path))[0] 161 162 test_name = f"test_{prefix}__{filename}__{clean_name}" 163 164 if (doc_format is not None): 165 test_name += ('__' + doc_format.value) 166 167 return test_name 168 169def _apply_text_options(options: typing.Dict[str, typing.Any], a: str, b: str) -> typing.Tuple[str, str]: 170 """ Apply some custom text options. """ 171 172 if (options.get("ignore-whitespace", False)): 173 a = re.sub(r'\s+', '', a) 174 b = re.sub(r'\s+', '', b) 175 176 return a, b 177 178_add_bad_parse_questions() 179_add_good_parse_questions()
THIS_DIR: str =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/parser'
TESTDATA_DIR: str =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/parser/testdata'
DOCUMENTS_DIR =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/parser/testdata/documents'
GOOD_DOCUMENTS_DIR =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/parser/testdata/documents/good'
BAD_DOCUMENTS_DIR =
'/home/runner/work/quiz-composer/quiz-composer/quizcomp/parser/testdata/documents/bad'
23class TestParser(quizcomp.testing.base.BaseTest): 24 """ 25 Test parsing text. 26 Good and bad situations will be loaded from files into individual test methods. 27 """
Test parsing text. Good and bad situations will be loaded from files into individual test methods.
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
144 def __method(self: TestParser) -> None: 145 serial_context = edq.util.serial.SerializationContext(base_dir = context.base_dir, source_path = context.source_path) 146 try: 147 quizcomp.parser.document.ParsedDocument.parse_text(text, serial_context) 148 except Exception: 149 # Expected. 150 return 151 152 self.fail("Failed to raise an exception.")
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_unescaped_escape_characters__md(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_unescaped_escape_characters__html(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_unescaped_escape_characters__tex(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_unescaped_escape_characters__text(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_unescaped_escape_characters__json(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_terminal_newlines__html(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_terminal_newlines__tex(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_terminal_newlines__text(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__equation__equation_block_with_terminal_newlines__json(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__style_table__table_with_content_and_text_alignment__md(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__style_table__table_with_content_and_text_alignment__html(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__style_table__table_with_content_and_text_alignment__tex(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__style_table__table_with_content_and_text_alignment__text(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
def
test_good_parse__style_table__table_with_content_and_text_alignment__json(self: TestParser) -> None:
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)
59 def __method(self: TestParser) -> None: 60 document = quizcomp.parser.document.ParsedDocument.parse_text(text) 61 result = document.to_format(doc_format, context = context) 62 63 if (doc_format == quizcomp.model.constants.Format.JSON): 64 result = edq.util.json.loads(result) 65 expected: typing.Any = { 66 'text': text.strip(), 67 'ast': { 68 'type': 'root', 69 }, 70 } 71 72 expected_children = [] 73 if (len(base_expected) > 0): 74 if (isinstance(base_expected, list)): 75 expected_children += base_expected 76 elif (isinstance(base_expected, dict)): 77 expected_children.append(base_expected) 78 else: 79 raise ValueError(f"Unkown type for expected children: '{type(base_expected)}'.") 80 81 if (len(expected_children) > 0): 82 # If the first node is not the root block, then automatically insert it. 83 if (not expected_children[0].get('attributes', {}).get(quizcomp.parser.common.TOKEN_META_KEY_ROOT, False)): 84 expected_children = [{ 85 'type': 'container_block', 86 'children': expected_children, 87 'attributes': { 88 quizcomp.parser.common.TOKEN_META_KEY_ROOT: True, 89 }, 90 }] 91 92 expected['ast']['children'] = expected_children 93 94 self.assertJSONDictEqual(expected, result) 95 elif (doc_format in {quizcomp.model.constants.Format.CANVAS, quizcomp.model.constants.Format.HTML}): 96 # If the HTML does not have a root block, then add one. 97 raw_expected = str(base_expected) 98 if (options.get('strip', True)): 99 raw_expected = raw_expected.strip() 100 101 if ((raw_expected != '') and ('qg-root-block' not in raw_expected)): 102 raw_expected = '<div class="qg-root-block qg-block">' + raw_expected + '</div>' 103 104 expected = quizcomp.util.html.clean(raw_expected, pretty = options.get('pretty', True)) 105 result = quizcomp.util.html.clean(result, pretty = options.get('pretty', True)) 106 107 expected, result = _apply_text_options(options, expected, result) 108 self.assertEqual(expected, result) 109 else: 110 expected = str(base_expected).strip() 111 result = result.strip() 112 113 expected, result = _apply_text_options(options, expected, result) 114 self.assertEqual(expected, result)