Commits

Yu-Jie Lin committed eefa87c

fix #1: url not checked when same url with fragment also being checked

  • Participants
  • Parent commits 62935fc

Comments (0)

Files changed (3)

  * [html] use `local_html` to check local fragment
  * add `print_toplist` for a list of worse post/entry/etc
  * add HTML attribute `name` to search list of fragment and use regular expression to match
+ * fix #1: url not checked when same url with fragment also being checked
 
 ## Version 0.1.1 (2013-02-15T12:07:09Z)
 

File lnkckr/checkers/base.py

 
     >>> c = Checker()
     >>> f = c._check_url_frag
+    >>> f(('', 'blah'))
+    '200'
     >>> f(('foo', 'id="foo"'))
     '200'
     >>> f(('foo', 'id="nofoo"'))
     '200'
     """
     frag, body = data
+    if frag == '':
+      return '200'
     for m in self.RE_ID_NAME.finditer(body):
       if frag == m.group(2):
         return '200'
           if frags:
             statuses, rurl = self.check_url(url, frags, local_html=local_html)
             for frag, status in zip(frags, statuses):
-              data = (url + '#' + frag, (status, rurl))
+              data = (url + '#' + frag if frag else url, (status, rurl))
               while data:
                 try:
                   r.put(data, False, 0.01)
     >>> c = Checker()
     >>> urls = ['http://example.com']
     >>> list(c._check_groupby(urls))
-    [('http://example.com', ())]
+    [('http://example.com', ('',))]
     >>> urls = [
     ...   'http://example.com',
     ...   'http://example.com/foo#bar1',
     ...   'http://example.com/foo#bar2',
+    ...   'http://example.com/foobar',
+    ...   'http://example.com/foobar#blah',
     ... ]
     >>> list(c._check_groupby(urls)) # doctest: +NORMALIZE_WHITESPACE
-    [('http://example.com', ()),
-     ('http://example.com/foo', ('bar1', 'bar2'))]
+    [('http://example.com', ('',)),
+     ('http://example.com/foo', ('bar1', 'bar2')),
+     ('http://example.com/foobar', ('', 'blah'))]
     >>> urls = ['#foo1', '#foo2']
     >>> list(c._check_groupby(urls))
     [('', ('foo1', 'foo2'))]
     """
     key = lambda item: item[0]
     for url, g in groupby(sorted(map(urldefrag, urls), key=key), key):
-      yield url, tuple(filter(None, (item[1] for item in g)))
+      yield url, tuple(item[1] for item in g)
 
   def check(self, f=None):
     """Check links

File tests/test_lnkckr_checkers_base.py

     self.assertEqual(checker.links, expect)
     self.assertEqual(self.httpd_requests.value, req_count + 1)
 
+  def test_check_fragments_1(self):
+    """Test same url with and without fragments and only make HTTP request
+    once.
+    """
+    checker = self.checker
+
+    req_count = self.httpd_requests.value
+    checker.add_link(H + '200')
+    checker.add_link(H + '200#foobar')
+    checker.HEADERS['X-Echo'] = '<h1 id="foobar">blah</h1>'
+    checker.check()
+
+    expect = {
+      H + '200': {'status': '200', 'redirection': None},
+      H + '200#foobar': {'status': '200', 'redirection': None},
+    }
+    self.assertEqual(checker.links, expect)
+    self.assertEqual(self.httpd_requests.value, req_count + 1)
+
   def test_check_local_fragments(self):
     """Test local fragments and if make no HTTP requests"""
     checker = self.checker