[py-svn] r10787 - py/dist/py/documentation

hpk at codespeak.net hpk at codespeak.net
Sun Apr 17 20:50:12 CEST 2005


Author: hpk
Date: Sun Apr 17 20:50:11 2005
New Revision: 10787

Modified:
   py/dist/py/documentation/conftest.py
Log:
implement "anchor" checking (in a hackish but working way it seems) 


Modified: py/dist/py/documentation/conftest.py
==============================================================================
--- py/dist/py/documentation/conftest.py	(original)
+++ py/dist/py/documentation/conftest.py	Sun Apr 17 20:50:11 2005
@@ -99,11 +99,12 @@
                 if option.checkremote: 
                     yield urlcheck, tryfn, path, lineno 
             else: 
-                s = tryfn 
-                i = s.find('#') 
+                i = tryfn.find('#') 
                 if i != -1: 
-                    tryfn = tryfn[:i]
-                if tryfn.endswith('.html'): 
+                    checkfn = tryfn[:i]
+                else: 
+                    checkfn = tryfn 
+                if checkfn.endswith('.html'): 
                     yield localrefcheck, tryfn, path, lineno 
 
 def urlcheck(tryfn, path, lineno): 
@@ -116,12 +117,30 @@
 
 def localrefcheck(tryfn, path, lineno): 
     # assume it should be a file 
+    i = tryfn.find('#')
+    if i != -1: 
+        anchor = tryfn[i+1:]
+        tryfn = tryfn[:i]
+    else: 
+        anchor = ''
     fn = path.dirpath(tryfn) 
     fn = fn.new(ext='.txt')
     if not fn.check(file=1): 
         py.test.fail("reference error %r in %s:%d" %(
                       tryfn, path.basename, lineno+1))
-    
-            
-
+    if anchor: 
+        source = unicode(fn.read(), 'latin1')
+        source = source.lower().replace('-', ' ') # aehem
 
+        anchor = anchor.replace('-', ' ') 
+        match2 = ".. _`%s`:" % anchor 
+        match3 = ".. _%s:" % anchor 
+        candidates = (anchor, match2, match3)
+        print "candidates", repr(candidates)
+        for line in source.split('\n'): 
+            line = line.strip()
+            if line in candidates: 
+                break 
+        else: 
+            py.test.fail("anchor reference error %s#%s in %s:%d" %(
+                tryfn, anchor, path.basename, lineno+1))



More information about the pytest-commit mailing list