def test_identifies_hhmmss_YYYYMMDD_format(self): wikitext = ' in my opinion. [[User:Nahaj|Nahaj]] 01:54:53, 2005-09-08 (UTC) ' wcode = mwpm.parse(wikitext) detected_sigs = signatureutils.extract_signatures(wcode) self.assertEqual(1, len(detected_sigs))
def test_identifies_hhmm_MMM_DD_YYYY_format(self): wikitext = ('the first is also illegible on Netscape, but you can tell' ' what was intended; the second is perfectly legible. ' '[[User:Michael Hardy|Michael Hardy]] 18:45 Mar 10, 2003 (UTC)\n') wcode = mwpm.parse(wikitext) detected_sigs = signatureutils.extract_signatures(wcode) self.assertEqual(1, len(detected_sigs))
def test_identifies_correct_user(self): template = '[[User:{user}|{user}]] ([[User talk:{user}|talk]]) 16:39, 27 April 2012 (UTC)' user = "******" wikitext = template.format(user=user) code = mwpm.parse(wikitext) detected_sigs = signatureutils.extract_signatures(code) self.assertEqual(1, len(detected_sigs)) self.assertEqual(user, detected_sigs[0]['user'])
def test_identifies_correct_time(self): template = '[[User:Some_Person|Some_Person]] ([[User talk:Some_Person|talk]]) 16:39, {timestamp}' timestamp = "16:39, 27 April 2012 (UTC)" wikitext = template.format(timestamp=timestamp) code = mwpm.parse(wikitext) detected_sigs = signatureutils.extract_signatures(code) self.assertEqual(1, len(detected_sigs)) self.assertEqual(timestamp, detected_sigs[0]['timestamp'])
def test_doesnt_give_leadin_subsections(self): wikitext = ("Lead in text\n" "=== Not a subsection ===\n" "Some text\n") wcode = mwpm.parse(wikitext) top_level = section.generate_sections_from_wikicode(wcode) self.assertEqual(len(top_level), 2, top_level) self.assertEqual(len(top_level[0].subsections), 0, top_level[0].subsections)
def test_sections_preserved(self): wikitext_list = [SECTION, SUBSUBSECTION, SECTION, SUBSUBSECTION] wikitext = "".join(wikitext_list) wikicode = mwpm.parse(wikitext) other = mwp.parse(wikitext) detected_sections = wikicode.get_sections(flat=True) other_sections = other.get_sections(flat=True) for i, sect in enumerate(detected_sections): self.assertEqual(sect, str(other_sections[i]))
def test_basic_linear_identification(self): text = ( LEVEL0 + FILLER + EL + LEVEL1 + FILLER + SIGNATURE + EL + LEVEL0 + FILLER + SIGNATURE + EL ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) comments = comment.identify_comments_linear_merge(blocks) self.assertEqual(len(comments), 2)
def test_handles_outdent(self): text = ( LEVEL0 + LEVEL1 + LEVEL2 + OUTDENT + LEVEL0 ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) self.assertEqual(len(blocks), 4) self.assertEqual(blocks[3].indent, 3)
def test_increasing_section_level(self): wikitext = ("= Heading 1 =\n" "Some text\n" "== Heading 2 ==\n" "Some text\n" "=== Heading 3 ===\n" "Some text\n" "==== Heading 4 ====\n" "Some text\n") wcode = mwpm.parse(wikitext) top_level = section.generate_sections_from_wikicode(wcode) self.assertEqual(len(top_level), 1, top_level)
def test_generates_list_from_basic_list_input(self): text = ( LEVEL0 + LIST1 + LIST2 + LIST3 ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) self.assertEqual(len(blocks), 4) self.assertEqual(blocks[0].indent, 0) self.assertEqual(blocks[1].indent, 1) self.assertEqual(blocks[2].indent, 2) self.assertEqual(blocks[3].indent, 3)
def test_generates_list_from_reverse_input(self): text = ( LEVEL3 + LEVEL2 + LEVEL1 + LEVEL0 ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) self.assertEqual(len(blocks), 4) self.assertEqual(blocks[0].indent, 3) self.assertEqual(blocks[1].indent, 2) self.assertEqual(blocks[2].indent, 1) self.assertEqual(blocks[3].indent, 0)
def test_identifies_backwards_signature(self): wikitext = ("Hi i wanted to make sure i didnt plagiarize. What are the rules", " on using others' information on wikipedia. Can i paraphrase it", " as long as I cite the link? Can anyone get sued from ", "paraphrasing with citation01:52, 20 September 2013 (UTC) ", '<small><span class="autosigned">— Preceding ', '[[Wikipedia:Signatures|unsigned]] comment added by ', '[[User:Fishingforspecies|Fishingforspecies]] ', '([[User talk:Fishingforspecies|talk]] • ', '[[Special:Contributions/Fishingforspecies|contribs]]) ', '</span></small>') wcode = mwpm.parse(wikitext) detected_sigs = signatureutils.extract_signatures(wcode) self.assertEqual(1, len(detected_sigs))
def test_linear_identification_hierarchy_with_extra_endlines(self): text = ( LEVEL0 + FILLER + EL + EL + LEVEL0 + FILLER + SIGNATURE + EL + EL + LEVEL1 + FILLER + SIGNATURE + EL + EL + LEVEL2 + FILLER + EL + EL + LEVEL2 + FILLER + SIGNATURE + EL + EL + LEVEL1 + FILLER + SIGNATURE + EL ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) comments = comment.identify_comments_linear_merge(blocks) self.assertEqual(len(comments), 1, comments) self.assertEqual(len(comments[0].comments), 2) self.assertEqual(len(comments[0].comments[0].comments), 1) self.assertEqual(len(comments[0].comments[1].comments), 0)
def test_parses_generic_sections(self): wikitext = ("== Heading 1 ==\n" "Some text\n" "=== Heading 1a ===\n" "Some text\n" "== Heading 2 ==\n" "Some text\n" "==== Heading 2a ====\n" "Some text\n" "=== Heading 2b ===\n" "Some text") wcode = mwpm.parse(wikitext) top_level = section.generate_sections_from_wikicode(wcode) self.assertEqual(len(top_level), 2, str(top_level)) self.assertEqual(len(top_level[0].subsections), 1, top_level[0].subsections) self.assertEqual(len(top_level[1].subsections), 2, top_level[1].subsections)
def test_identifies_multiple_signatures(self): sigs = ['[[User:Dee03z|Dee03z]] ([[User talk:Dee03z|talk]]) 16:39, 27 April 2012 (UTC)\n', '[[User:SarahStierch|Sarah]] ([[User talk:SarahStierch|talk]]) 16:56, 27 April 2012 (UTC)\n', '[[User:AbigailAbernathy|<font color="darkred">''A Wild Abigail Appears!''</font>]] [[User talk:AbigailAbernathy|<font color="slate"><sub>Capture me.</sub></font>]] [[Special:EmailUser/AbigailAbernathy|<font color="seagreen"><sub>Flee.</sub></font>]] 18:51, 27 April 2012 (UTC)\n', '[[User:Nathan2055|Nathan2055]][[User Talk:Nathan2055|<sup>talk</sup>]] 22:21, 27 April 2012 (UTC)\n', '[[User:SarahStierch|Sarah]] ([[User talk:SarahStierch|talk]]) 22:25, 27 April 2012 (UTC)\n', '[[User:Mir Almaat 1 S1|RDF Energia]] [[User talk:Mir Almaat 1 S1||<span style="font-size: 1.2em;color:transparent;text-shadow:gold 0em 0.2em 0.02em;"> ☏</span>]] 05:43, 27 April 2012 (UTC)\n', '[[User:McDoobAU93|<span style="color:#000080">McDoob</span>]][[User talk:McDoobAU93|<span style="color:#cc5500">AU</span>]][[Special:Contributions/McDoobAU93|<span style="color:#000080">93</span>]] 01:31, 29 April 2012 (UTC)\n', '[[User:Charlesdrakew|Charles]] ([[User talk:Charlesdrakew|talk]]) 22:28, 28 April 2012 (UTC)\n', '[[User:Tlqk56|Tlqk56]] ([[User talk:Tlqk56|talk]]) 04:19, 29 April 2012 (UTC)\n'] wikitext = ''.join(sigs) code = mwpm.parse(wikitext) detected_sigs = signatureutils.extract_signatures(code) self.assertEqual(len(sigs), len(detected_sigs)) for sig in detected_sigs: self.assertIn(str(sig['wikicode']), sigs)
def test_breaks_same_level_apart(self): text = ( LEVEL0 + LIST1 + LIST1 + LIST2 + LIST3 ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) self.assertEqual(len(blocks), 5) self.assertEqual(blocks[0].indent, 0) self.assertEqual(blocks[1].indent, 1) self.assertEqual(blocks[2].indent, 1) self.assertEqual(blocks[3].indent, 2) self.assertEqual(blocks[4].indent, 3)
def test_grants_empty_line_previous_indent(self): text = ( LEVEL0 + LIST1 + EMPTY + LIST1 + LIST2 ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) self.assertEqual(len(blocks), 5) self.assertEqual(blocks[0].indent, 0) self.assertEqual(blocks[1].indent, 1) self.assertEqual(blocks[2].indent, 1) self.assertEqual(blocks[3].indent, 1) self.assertEqual(blocks[4].indent, 2)
def test_gives_empty_start_zero_indent(self): text = ( EMPTY + LEVEL0 + LIST1 + LIST1 + LIST2 ) code = mwpm.parse(text) blocks = indentblock.generate_indentblock_list(code) self.assertEqual(len(blocks), 5) self.assertEqual(blocks[0].indent, 0) self.assertEqual(blocks[1].indent, 0) self.assertEqual(blocks[2].indent, 1) self.assertEqual(blocks[3].indent, 1) self.assertEqual(blocks[4].indent, 2)
def test_returns_wikicode(self): wikitext = SECTION wikicode = mwpm.parse(wikitext) self.assertIsInstance(wikicode, mwp.wikicode.Wikicode)
def test_resulting_string_the_same(self): wikitext = SECTION + SUBSUBSECTION + SECTION + SUBSUBSECTION wikicode = mwpm.parse(wikitext) self.assertEqual(wikitext, str(wikicode))