class TestTextFormatting(unittest.TestCase): """Test text formatting parser elements. :cvar ParserElement wiki_markup: wiki markup parser element """ WIKI_MARKUP = (fundamental.get_plaintext() | fundamental.get_special()) WIKI_MARKUP.setName("wiki_markup") WIKI_MARKUP.parseWithTabs() @hypothesis.given( hypothesis.strategies.data(), strategies.text_formatting.text(1, 16, 32) ) def test_italics_00(self, data, text): """Test italics parser element. :param str text: text italics = ( "''", text, "''" ) | ( "<i>", text, "</i>" ); """ italics = data.draw(strategies.text_formatting.italics(text)) parser_element = text_formatting.get_italics(self.WIKI_MARKUP) parse_results = parser_element.parseString(italics) self.assertEqual(text, parse_results[0]) return @hypothesis.given( hypothesis.strategies.data(), strategies.text_formatting.text(1, 16, 32) ) def test_bold_00(self, data, text): """Test bold parser element. :param str text: text bold = ( "'''", text, "'''" ) | ( "<b>", text, "</b>" ); """ bold = data.draw(strategies.text_formatting.bold(text)) parser_element = text_formatting.get_bold(self.WIKI_MARKUP) parse_results = parser_element.parseString(bold) self.assertEqual(text, parse_results[0]) return @hypothesis.given( strategies.text_formatting.text(1, 16, 32) ) def test_bold_italics_00(self, text): """Test bold/italics parser element. :param str text: text bold_italics = "'''''", text, "'''''"; """ bold_italics = strategies.text_formatting.bold_italics(text) parser_element = text_formatting.get_bold_italics(self.WIKI_MARKUP) parse_results = parser_element.parseString(bold_italics) self.assertEqual(text, parse_results[0]) return
def test_plaintext_00(self, plaintext): """Test plaintext parser element. :param str plaintext: plaintext plaintext = { ( any of a-zA-Z0-9 or '!"$%&()+,-./?@\^_`~', any of "[]*#:;='", any Unicode character without "|[]*#:;<>='{}" ) | any Unicode character without "|[]*#:;<>='{}" }-; """ parser_element = fundamental.get_plaintext() parse_results = parser_element.parseString(plaintext) self.assertEqual(plaintext, parse_results[0]) return
class TestTextFormatting(unittest.TestCase): """Test text formatting parse actions.""" WIKI_MARKUP = (fundamental.get_plaintext() | fundamental.get_special()) WIKI_MARKUP.setName("wiki_markup") WIKI_MARKUP.parseWithTabs() @hypothesis.given(hypothesis.strategies.data(), strategies.text_formatting.text(1, 16, 32)) def test_sub_italics_00(self, data, text): """Test italics parse action (transformString). :param str text: text """ italics = data.draw(strategies.text_formatting.italics(text)) parser_element = text_formatting.get_italics(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(italics) self.assertEqual(text, transformed) return @hypothesis.given(hypothesis.strategies.data(), strategies.text_formatting.text(1, 16, 32)) def test_sub_bold_00(self, data, text): """Test bold parse action (transformString). :param str text: text """ bold = data.draw(strategies.text_formatting.bold(text)) parser_element = text_formatting.get_bold(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(bold) self.assertEqual(text, transformed) return @hypothesis.given(strategies.text_formatting.text(1, 16, 32)) def test_bold_italics_00(self, text): """Test bold/italics parse action (transformString). :param str text: text """ bold_italics = strategies.text_formatting.bold_italics(text) parser_element = text_formatting.get_bold_italics(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(bold_italics) self.assertEqual(text, transformed) return
class TestSections(unittest.TestCase): """Test sections parse actions.""" WIKI_MARKUP = (fundamental.get_plaintext() | fundamental.get_special()) WIKI_MARKUP.setName("wiki_markup") WIKI_MARKUP.parseWithTabs() @hypothesis.given(hypothesis.strategies.data()) def test_header6_00(self, data): """Test header parse action (transform string).""" heading = data.draw(strategies.sections.heading(1, 8, 16)) header6 = data.draw(strategies.sections.header6(heading)) parser_element = sections.get_header6(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(header6) heading = "\n{}\n".format(heading.strip()) self.assertEqual(heading, transformed) return @hypothesis.given(hypothesis.strategies.data()) def test_header5_00(self, data): """Test header parse action (transform string).""" heading = data.draw(strategies.sections.heading(1, 8, 16)) header5 = data.draw(strategies.sections.header5(heading)) parser_element = sections.get_header5(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(header5) heading = "\n{}\n".format(heading.strip()) self.assertEqual(heading, transformed) return @hypothesis.given(hypothesis.strategies.data()) def test_header4_00(self, data): """Test header parse action (transform string).""" heading = data.draw(strategies.sections.heading(1, 8, 16)) header4 = data.draw(strategies.sections.header4(heading)) parser_element = sections.get_header4(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(header4) heading = "\n{}\n".format(heading.strip()) self.assertEqual(heading, transformed) return @hypothesis.given(hypothesis.strategies.data()) def test_header3_00(self, data): """Test header parse action (transform string).""" heading = data.draw(strategies.sections.heading(1, 8, 16)) header3 = data.draw(strategies.sections.header3(heading)) parser_element = sections.get_header3(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(header3) heading = "\n{}\n".format(heading.strip()) self.assertEqual(heading, transformed) return @hypothesis.given(hypothesis.strategies.data()) def test_header2_00(self, data): """Test header parse action (transform string).""" heading = data.draw(strategies.sections.heading(1, 8, 16)) header2 = data.draw(strategies.sections.header2(heading)) parser_element = sections.get_header2(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(header2) heading = "\n{}\n".format(heading.strip()) self.assertEqual(heading, transformed) return @hypothesis.given(hypothesis.strategies.data()) def test_header1_00(self, data): """Test header parse action (transform string).""" heading = data.draw(strategies.sections.heading(1, 8, 16)) header1 = data.draw(strategies.sections.header1(heading)) parser_element = sections.get_header1(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(header1) heading = "\n{}\n".format(heading.strip()) self.assertEqual(heading, transformed) return @hypothesis.given(strategies.fundamental.plaintext(1, 8, 16)) def test_p_tag_00(self, content): """Test p_tag parse action (transformString). :param str content: content """ p_tag = strategies.sections.p_tag(content) parser_element = sections.get_p_tag(self.WIKI_MARKUP, parse_actions=True) transformed = parser_element.transformString(p_tag) p_tag = "\n{}".format(content.strip()) self.assertEqual(p_tag, transformed) return @hypothesis.given(strategies.sections.br_tag()) def test_br_tag_00(self, br_tag): """Test br_tag parse action (transformString). :param str br_tag: br_tag """ parser_element = sections.get_br_tag(parse_actions=True) transformed = parser_element.transformString(br_tag) br_tag = "\n" self.assertEqual(br_tag, transformed) return @hypothesis.given(strategies.sections.horizontal()) def test_horizontal_00(self, horizontal): """Test horizontal parse action (transformString). :param str horizontal: horizontal """ parser_element = sections.get_horizontal(parse_actions=True) transformed = parser_element.transformString(horizontal) horizontal = "" self.assertEqual(horizontal, transformed) return
class TestSections(unittest.TestCase): """Test section parser elements. :cvar ParserElement WIKI_MARKUP: wiki_markup """ WIKI_MARKUP = (fundamental.get_plaintext() | fundamental.get_special()) WIKI_MARKUP.setName("wiki_markup") WIKI_MARKUP.parseWithTabs() @hypothesis.given( hypothesis.strategies.data(), strategies.sections.heading(1, 16, 32) ) def test_header6_00(self, data, heading): """Test header6 parser element. :param str heading: heading header6 = ( "<h6>", heading, "</h6>" ) | ( 6*"=", heading, 6*"=" ); """ header6 = data.draw(strategies.sections.header6(heading)) parser_element = sections.get_header6(self.WIKI_MARKUP) parse_results = parser_element.parseString(header6) self.assertEqual(heading, "".join(parse_results[0])) return @hypothesis.given( hypothesis.strategies.data(), strategies.sections.heading(1, 16, 32) ) def test_header5_00(self, data, heading): """Test header5 parser element. :param str heading: heading header5 = ( "<h5>", heading, "</h5>" ) | ( 5*"=", heading, 5*"=" ); """ header5 = data.draw(strategies.sections.header5(heading)) parser_element = sections.get_header5(self.WIKI_MARKUP) parse_results = parser_element.parseString(header5) self.assertEqual(heading, "".join(parse_results[0])) return @hypothesis.given( hypothesis.strategies.data(), strategies.sections.heading(1, 16, 32) ) def test_header4_00(self, data, heading): """Test heading4 parser element. :param str heading: heading header4 = ( "<h4>", heading, "</h4>" ) | ( 4*"=", heading, 4*"=" ); """ header4 = data.draw(strategies.sections.header4(heading)) parser_element = sections.get_header4(self.WIKI_MARKUP) parse_results = parser_element.parseString(header4) self.assertEqual(heading, "".join(parse_results[0])) return @hypothesis.given( hypothesis.strategies.data(), strategies.sections.heading(1, 16, 32) ) def test_header3_00(self, data, heading): """Test header3 parser element. :param str heading: heading header3 = ( "<h3>", heading, "</h3>" ) | ( 3*"=", heading, 3*"=" ); """ header3 = data.draw(strategies.sections.header3(heading)) parser_element = sections.get_header3(self.WIKI_MARKUP) parse_results = parser_element.parseString(header3) self.assertEqual(heading, "".join(parse_results[0])) return @hypothesis.given( hypothesis.strategies.data(), strategies.sections.heading(1, 16, 32) ) def test_heading2_00(self, data, heading): """Test heading2 parser element. :param str heading: heading header2 = ( "<h2>", heading, "</h2>" ) | ( 2*"=", heading, 2*"=" ); """ header2 = data.draw(strategies.sections.header2(heading)) parser_element = sections.get_header2(self.WIKI_MARKUP) parse_results = parser_element.parseString(header2) self.assertEqual(heading, "".join(parse_results[0])) return @hypothesis.given( hypothesis.strategies.data(), strategies.sections.heading(1, 16, 32) ) def test_heading1_00(self, data, heading): """Test heading1 parser element. :param str heading: heading header1 = ( "<h1>", heading, "</h1>" ) | ( 1*"=", heading, 1*"=" ); """ header1 = data.draw(strategies.sections.header1(heading)) parser_element = sections.get_header1(self.WIKI_MARKUP) parse_results = parser_element.parseString(header1) self.assertEqual(heading, "".join(parse_results[0])) return @hypothesis.given( strategies.fundamental.plaintext(1, 16, 32) ) def test_p_tag_00(self, content): """Test p_tag parser element. :param str content: content p_tag = "<p>", content, "</p>"; """ p_tag = strategies.sections.p_tag(content) parser_element = sections.get_p_tag(self.WIKI_MARKUP) parse_results = parser_element.parseString(p_tag) self.assertEqual(content, "".join(parse_results[0])) return @hypothesis.given( strategies.sections.br_tag() ) def test_br_tag_00(self, br_tag): """Test br_tag parser element. :param str br_tag: br_tag br_tag = "<br>" | "<br />"; """ parser_element = sections.get_br_tag() parse_results = parser_element.parseString(br_tag) self.assertEqual(br_tag, parse_results[0]) return @hypothesis.given( strategies.sections.horizontal() ) def test_horizontal_00(self, horizontal): """Test horizontal parser element. :param str horizontal: horizontal horizontal = "<hr>" | "----"; """ parser_element = sections.get_horizontal() parse_results = parser_element.parseString(horizontal) self.assertEqual(horizontal, parse_results[0]) return
def _set_parser_elements(self): """Set parser elements.""" # wiki markup parser element self.wiki_markup = pyparsing.Forward() self.wiki_markup.setName("wiki_markup") self.wiki_markup.parseWithTabs() # behavior switch parser element behavior_switches = self._get_behavior_switches() behavior_switch = magic_words.get_behaviour_switch(behavior_switches, parse_actions=True) # param parser element param = template.get_param(self.wiki_markup) # noinclude parser element noinclude = tags.get_noinclude(parse_actions=True) # comment parser element comment = tags.get_comment(parse_actions=True) # parser extension parser element parser_extensions = self._get_parser_extensions() parser_extension = tags.get_parser_extension(parser_extensions, parse_actions=True) # basic table parser element basic_table = table.get_basic_table(parse_actions=True) # br tag parser element br_tag = sections.get_br_tag(parse_actions=True) # horizontal parser element horizontal = sections.get_horizontal(parse_actions=True) # internal link parser element language_codes = self._get_language_codes() projects = self._get_projects() namespaces = self._get_namespaces() internal_link = link.get_link(language_codes, projects, namespaces) # abbr tag parser element abbr_tag = text_formatting.get_abbr_tag() # URL parser element url = link.get_url() # external link parser element external_link = link.get_external_link(parse_actions=True) # list item parser element list_item = lists.get_list_item(parse_actions=True) # indent parser element indent = lists.get_indent(parse_actions=True) # plaintext parser element plaintext = fundamental.get_plaintext() # special parser element special = fundamental.get_special() # magic words variable parser element variables = self._get_variables() mw_variable = magic_words.get_mw_variable(variables, self.wiki_markup, parse_actions=True) # magic words parser function parser element parser_functions = self._get_parser_functions() mw_parser_function = magic_words.get_mw_parser_function( parser_functions, self.wiki_markup, parse_actions=True) # inclusion parser element modifiers = self._get_modifiers() inclusion = template.get_inclusion(modifiers, namespaces, self.wiki_markup, parse_actions=True) # header6 parser element header6 = sections.get_header6(self.wiki_markup, parse_actions=True) # header5 parser element header5 = sections.get_header5(self.wiki_markup, parse_actions=True) # header4 parser element header4 = sections.get_header4(self.wiki_markup, parse_actions=True) # header3 parser element header3 = sections.get_header3(self.wiki_markup, parse_actions=True) # header2 parser element header2 = sections.get_header2(self.wiki_markup, parse_actions=True) # header1 parser element header1 = sections.get_header1(self.wiki_markup, parse_actions=True) # paragraph tag parser element p_tag = sections.get_p_tag(self.wiki_markup, parse_actions=True) # italics parser element italics = text_formatting.get_italics(self.wiki_markup, parse_actions=True) # bold parser element bold = text_formatting.get_bold(self.wiki_markup, parse_actions=True) # bold italics parser element bold_italics = text_formatting.get_bold_italics(self.wiki_markup, parse_actions=True) # cite parser element cite = text_formatting.get_cite_tag(self.wiki_markup) # assign parser element(s) self.wiki_markup << ( # terminal magic words parser element(s) behavior_switch # terminal inclusion parser element(s) | param # terminal tag parser element(s) | noinclude | comment | parser_extension # terminal table parser element(s) | basic_table # terminal section parser element(s) | br_tag | horizontal # terminal link parser element(s) | internal_link # terminal text formatting parser element(s) | abbr_tag # terminal external link parser element(s) | url | external_link # terminal lists parser element(s) | list_item | indent # non-terminal magic words parser element(s) | mw_variable | mw_parser_function # non-terminal inclusion parser element(s) | inclusion # non-terminal section parser element(s) | header6 | header5 | header4 | header3 | header2 | header1 | p_tag # non-terminal text formatting parser element(s) | italics | bold | bold_italics | cite # terminal fundamental parser element(s) | plaintext | special) return
class TestTemplate(unittest.TestCase): """Test template parser elements. :cvar ParserElement WIKI_MARKUP: wiki markup parser element :cvar list MODIFIERS: modifiers :cvar list NAMESPACES: namespaces """ WIKI_MARKUP = (fundamental.get_plaintext() | fundamental.get_special()) WIKI_MARKUP.setName("wiki_markup") WIKI_MARKUP.parseWithTabs() MODIFIERS = tests.wpdata.MODIFIERS NAMESPACES = [ namespace for value in tests.wpdata.NAMESPACES.values() for namespace in value ] @hypothesis.given(strategies.template.modifier()) def test_modifier_00(self, modifier): """Test modifier parser element. :param str modifier: modifier modifier = any modifier; """ parser_element = template._get_modifier(self.MODIFIERS) parse_results = parser_element.parseString(modifier) self.assertEqual(modifier, parse_results["modifier"]) return @hypothesis.given(strategies.template.modifier()) def test_modifier_prefix_00(self, modifier): """Test modifier_prefix parser element. :param str modifier: modifier modifier_prefix = modifier, ":"; """ modifier_prefix = strategies.template.modifier_prefix(modifier) parser_element = template._get_modifier_prefix(self.MODIFIERS) parse_results = parser_element.parseString(modifier_prefix) self.assertEqual(modifier, parse_results["modifier"]) return @hypothesis.given(strategies.template.namespace()) def test_namespace_00(self, namespace): """Test namespace parser element. :param str namespace: namespace namespace = any namespace; """ parser_element = template._get_namespace(self.NAMESPACES) parse_results = parser_element.parseString(namespace) self.assertEqual(namespace, parse_results["namespace"]) return @hypothesis.given(strategies.template.namespace()) def test_namespace_prefix_00(self, namespace): """Test namespace_prefix parser element. :param str namespace: namespace namespace_prefix = namespace, ":"; """ namespace_prefix = strategies.template.namespace_prefix(namespace) parser_element = template._get_namespace_prefix(self.NAMESPACES) parse_results = parser_element.parseString(namespace_prefix) self.assertEqual(namespace, parse_results["namespace"]) return @hypothesis.given(strategies.template.template(1, 8, 16)) def test_template_00(self, template_): """Test template parser element. :param str template_: template template = { any Unicode character without "|[]#<>{}" }-; """ parser_element = fundamental.get_pagename() parse_results = parser_element.parseString(template_) self.assertEqual(template_, parse_results["pagename"]) return @hypothesis.given(strategies.template.template(1, 8, 16)) def test_full_template_00(self, template_): """Test full_template parser element. :param str template_: template full_template = template; """ full_template = strategies.template.full_template(template_) parser_element = template._get_full_template(self.MODIFIERS, self.NAMESPACES) parse_results = parser_element.parseString(full_template) self.assertEqual(template_, parse_results["pagename"]) return @hypothesis.given(strategies.template.namespace(), strategies.template.template(1, 8, 16)) def test_full_template_01(self, namespace, template_): """Test full_template parser element. :param str namespace: namespace :param str template_: template full_template = namespace_prefix, template; """ namespace_prefix = strategies.template.namespace_prefix(namespace) full_template = strategies.template.full_template( template_, namespace_prefix_=namespace_prefix) parser_element = template._get_full_template(self.MODIFIERS, self.NAMESPACES) parse_results = parser_element.parseString(full_template) self.assertEqual(namespace, parse_results["namespace"]) self.assertEqual(template_, parse_results["pagename"]) return @hypothesis.given(strategies.template.modifier(), strategies.template.template(1, 8, 16)) def test_full_template_02(self, modifier, template_): """Test full_template parser element. :param str modifier: modifier :param str template_: template full_template = modifier_prefix, template; """ modifier_prefix = strategies.template.modifier_prefix(modifier) full_template = strategies.template.full_template( template_, modifier_prefix_=modifier_prefix) parser_element = template._get_full_template(self.MODIFIERS, self.NAMESPACES) parse_results = parser_element.parseString(full_template) self.assertEqual(modifier, parse_results["modifier"]) self.assertEqual(template_, parse_results["pagename"]) return @hypothesis.given(strategies.template.modifier(), strategies.template.namespace(), strategies.template.template(1, 8, 16)) def test_full_template_03(self, modifier, namespace, template_): """Test full_template parser element. :param str modifier: modifier :param str namespace: namespace :param str template_: template full_template = modifier_prefix, namespace_prefix, template; """ modifier_prefix = strategies.template.modifier_prefix(modifier) namespace_prefix = strategies.template.namespace_prefix(namespace) full_template = strategies.template.full_template( template_, modifier_prefix_=modifier_prefix, namespace_prefix_=namespace_prefix) parser_element = template._get_full_template(self.MODIFIERS, self.NAMESPACES) parse_results = parser_element.parseString(full_template) self.assertEqual(modifier, parse_results["modifier"]) self.assertEqual(namespace, parse_results["namespace"]) self.assertEqual(template_, parse_results["pagename"]) return @hypothesis.given(strategies.template.value(1, 8, 16)) def test_value_00(self, value): """Test value parser element. :param str value: value value = plaintext; """ parser_element = template._get_value(self.WIKI_MARKUP) parse_results = parser_element.parseString(value) self.assertEqual(value, parse_results["value"]) return @hypothesis.given(strategies.template.name(1, 4, 8), strategies.template.value(1, 8, 16)) def test_named_arg_00(self, name, value): """Test named_arg parser element. :param str name: name :param str value: value named_arg = { any Unicode character without "|=" }-, "=", value; """ named_arg = strategies.template.named_arg(name, value) parser_element = template._get_named_arg(self.WIKI_MARKUP) parse_results = parser_element.parseString(named_arg) self.assertEqual(name, parse_results["name"]) self.assertEqual(value, parse_results["value"]) return @hypothesis.given(strategies.template.value(1, 8, 16)) def test_named_arg_01(self, value): """Test named_arg parser element. :param str name: name :param str value: value named_arg = "=", value; """ named_arg = strategies.template.named_arg("", value) parser_element = template._get_named_arg(self.WIKI_MARKUP) parse_results = parser_element.parseString(named_arg) self.assertNotIn("name", parse_results) self.assertEqual(value, parse_results["value"]) return @hypothesis.given(hypothesis.strategies.data()) def test_arg_00(self, data): """Test arg parser element. arg = "|", named_arg; """ name = data.draw(strategies.template.name(0, 4, 8)) value = data.draw(strategies.template.value(1, 8, 16)) named_arg = strategies.template.named_arg(name, value) arg = strategies.template.arg(named_arg) parser_element = template._get_arg(self.WIKI_MARKUP) parse_results = parser_element.parseString(arg) if len(name): self.assertEqual(name, parse_results["arg"][0]["name"]) else: self.assertNotIn("name", parse_results["arg"][0]) self.assertEqual(value, parse_results["arg"][0]["value"]) return @hypothesis.given(hypothesis.strategies.data()) def test_arg_01(self, data): """Test arg parser element. arg = "|", unnamed_arg; """ value = data.draw(strategies.template.value(1, 8, 16)) arg = strategies.template.arg(value) parser_element = template._get_arg(self.WIKI_MARKUP) parse_results = parser_element.parseString(arg) self.assertEqual(value, parse_results["arg"][0]["value"]) return # inclusion = "{{", full_template, { arg }, "}}"; # inclusion = "{{", ( modifier_prefix | namespace_prefix | template ) ...; # inclusion = ..., template, ( "}}" | named_arg | unnamed_arg ) ...; # inclusion = ..., ( template | value ), "}}"; # inclusion = "{{", template, "}}"; # inclusion = "{{", modifier_prefix, template, # named_arg, unnamed_arg, "}}"; # inclusion = "{{", namespace_prefix, template, unnamed_arg, # named_arg, "}}"; @hypothesis.given(hypothesis.strategies.data()) def test_inclusion_00(self, data): """Test inclusion parser element. inclusion = "{{", template, "}}"; """ template_ = data.draw(strategies.template.template(1, 8, 16)) full_template = strategies.template.full_template(template_) inclusion = strategies.template.inclusion(full_template) parser_element = template.get_inclusion(self.MODIFIERS, self.NAMESPACES, self.WIKI_MARKUP) parse_results = parser_element.parseString(inclusion) self.assertEqual(template_, parse_results[0]["pagename"]) return @hypothesis.given(hypothesis.strategies.data()) def test_inclusion_01(self, data): """Test inclusion parser element. inclusion = "{{", modifier_prefix, template, named_arg, unnamed_arg, "}}"; """ modifier = data.draw(strategies.template.modifier()) modifier_prefix = strategies.template.modifier_prefix(modifier) template_ = data.draw(strategies.template.template(1, 8, 16)) full_template = strategies.template.full_template( template_, modifier_prefix_=modifier_prefix) name = data.draw(strategies.template.name(1, 4, 8)) value0 = data.draw(strategies.template.value(1, 8, 16)) named_arg = strategies.template.named_arg(name, value0) value1 = data.draw(strategies.template.value(1, 8, 16)) arg = (strategies.template.arg(named_arg) + strategies.template.arg(value1)) inclusion = strategies.template.inclusion(full_template, arg_=arg) parser_element = template.get_inclusion(self.MODIFIERS, self.NAMESPACES, self.WIKI_MARKUP) parse_results = parser_element.parseString(inclusion) self.assertEqual(modifier, parse_results[0]["modifier"]) self.assertEqual(template_, parse_results[0]["pagename"]) self.assertEqual(name, parse_results[0]["arg"][0]["name"]) self.assertEqual(value0, parse_results[0]["arg"][0]["value"]) self.assertEqual(value1, parse_results[0]["arg"][1]["value"]) return @hypothesis.given(hypothesis.strategies.data()) def test_inclusion_02(self, data): """Test inclusion parser element. inclusion = "{{", namespace_prefix, template, unnamed_arg, named_arg, "}}"; """ namespace = data.draw(strategies.template.namespace()) namespace_prefix = strategies.template.namespace_prefix(namespace) template_ = data.draw(strategies.template.template(1, 8, 16)) full_template = strategies.template.full_template( template_, namespace_prefix_=namespace_prefix) value0 = data.draw(strategies.template.value(1, 8, 16)) name = data.draw(strategies.template.name(1, 4, 8)) value1 = data.draw(strategies.template.value(1, 8, 16)) named_arg = strategies.template.named_arg(name, value1) arg = (strategies.template.arg(value0) + strategies.template.arg(named_arg)) inclusion = strategies.template.inclusion(full_template, arg_=arg) parser_element = template.get_inclusion(self.MODIFIERS, self.NAMESPACES, self.WIKI_MARKUP) parse_results = parser_element.parseString(inclusion) self.assertEqual(namespace, parse_results[0]["namespace"]) self.assertEqual(template_, parse_results[0]["pagename"]) self.assertEqual(value0, parse_results[0]["arg"][0]["value"]) self.assertEqual(name, parse_results[0]["arg"][1]["name"]) self.assertEqual(value1, parse_results[0]["arg"][1]["value"]) return @hypothesis.given(strategies.template.param_name(1, 4, 8)) def test_param_00(self, param_name): """Test param parser element. param = "{{{", { any Unicode character without "|={}" }-, "}}}"; """ param = strategies.template.param(param_name) parser_element = template.get_param(self.WIKI_MARKUP) parse_results = parser_element.parseString(param) self.assertEqual(param_name, parse_results[0]["name"]) return @hypothesis.given(strategies.template.param_name(1, 4, 8), strategies.template.default(0, 8, 16)) def test_param_01(self, param_name, default): """Test param parser_element. param = "{{{", { any Unicode character without "|={}" }-, default, "}}}"; """ param = strategies.template.param(param_name, default_=default) parser_element = template.get_param(self.WIKI_MARKUP) parse_results = parser_element.parseString(param) self.assertEqual(param_name, parse_results[0]["name"]) if len(default) > 1: self.assertEqual(default[1:], parse_results[0]["value"]) else: self.assertNotIn("value", parse_results[0]) return