Example #1
0
 def test_wikipedia_rev_139992(self):
     """Test html_comparator with revision 139992 in en:wikipedia."""
     site = self.get_site()
     diff_html = site.compare(139992, 139993)
     output = html_comparator(diff_html)
     self.assertEqual(len(output['added-context']), 1)
     self.assertEqual(len(output['deleted-context']), 1)
Example #2
0
 def test_wikipedia_rev_139992(self):
     """Test html_comparator with revision 139992 in en:wikipedia."""
     site = self.get_site()
     diff_html = site.compare(139992, 139993)
     output = html_comparator(diff_html)
     self.assertEqual(len(output['added-context']), 1)
     self.assertEqual(len(output['deleted-context']), 1)
Example #3
0
    def test_deleted_context(self):
        """Test html_comparator's detection of deleted-context."""
        output = html_comparator("""
<tr>
  <td class="diff-deletedline">line 1a</td>
  <td class="diff-deletedline">line \n2a</td>
</tr>
<tr>
  <td class="diff-deletedline"><span>line 1b</span></td>
  <td class="diff-deletedline">line 2b<i><span></i></span></td>
</tr>""")
        self.assertEqual(output['deleted-context'],
                         ['line 1a', 'line \n2a', 'line 1b', 'line 2b'])
Example #4
0
    def test_deleted_context(self):
        """Test html_comparator's detection of deleted-context."""
        output = html_comparator('''
<tr>
  <td class="diff-deletedline">line 1a</td>
  <td class="diff-deletedline">line \n2a</td>
</tr>
<tr>
  <td class="diff-deletedline"><span>line 1b</span></td>
  <td class="diff-deletedline">line 2b<i><span></i></span></td>
</tr>''')
        self.assertEqual(output['deleted-context'],
                         ['line 1a', 'line \n2a', 'line 1b', 'line 2b'])
Example #5
0
 def test_run(self):
     """Test html_comparator using examples given in mw-api docs."""
     with open(join_html_data_path('diff.html')) as filed:
         diff_html = filed.read()
     output = html_comparator(diff_html)
     self.assertEqual(
         output,
         {'added-context': ['#REDIRECT [[Template:Unsigned IP]]'],
          'deleted-context': [
             '<small><span class="autosigned">\\u2014&nbsp;Preceding '
             '[[Wikipedia:Signatures|unsigned]] comment added by '
             '[[User:{{{1}}}|{{{1}}}]] ([[User talk:{{{1}}}|talk]] \\u2022 '
             '[[Special:Contributions/{{{1}}}|contribs]]) {{{2|}}}</span>'
             '</small><!-- Template:Unsigned --><noinclude>',
             '{{documentation}} <!-- add categories to the /doc page, '
             'not here --></noinclude>']})
Example #6
0
 def test_run(self):
     """Test html_comparator using examples given in mw-api docs."""
     with open(join_html_data_path('diff.html')) as filed:
         diff_html = filed.read()
     output = html_comparator(diff_html)
     self.assertEqual(
         output,
         {'added-context': ['#REDIRECT [[Template:Unsigned IP]]'],
          'deleted-context': [
             '<small><span class="autosigned">\\u2014&nbsp;Preceding '
             '[[Wikipedia:Signatures|unsigned]] comment added by '
             '[[User:{{{1}}}|{{{1}}}]] ([[User talk:{{{1}}}|talk]] \\u2022 '
             '[[Special:Contributions/{{{1}}}|contribs]]) {{{2|}}}</span>'
             '</small><!-- Template:Unsigned --><noinclude>',
             '{{documentation}} <!-- add categories to the /doc page, '
             'not here --></noinclude>']})
Example #7
0
 def test_html_comparator(self, mocked_import):
     """Test html_comparator when bs4 not installed."""
     with self.assertRaises(ImportError):
         html_comparator('')
     self.assertEqual(mocked_import.call_count, 1)
     self.assertIn('bs4', mocked_import.call_args[0])
def compare_latest(page):
    from pywikibot import diff

    html_diff = _site.compare(page.checked_revision, page.latest_revision)
    changes = diff.html_comparator(html_diff)
    return changes['added-context'], changes['deleted-context']