Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Unified Diff: chrome/common/extensions/docs/server2/integration_test.py

Issue 17816005: Doc server broken link detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: finalization Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/integration_test.py
diff --git a/chrome/common/extensions/docs/server2/integration_test.py b/chrome/common/extensions/docs/server2/integration_test.py
index acd4d44c1e6ce18283581712f6e556148c4f00c7..ea7f305a1e6c81634e4b7df5bdc86b7fc2aeed04 100755
--- a/chrome/common/extensions/docs/server2/integration_test.py
+++ b/chrome/common/extensions/docs/server2/integration_test.py
@@ -8,13 +8,16 @@
import build_server
build_server.main()
-import logging
+from itertools import groupby
+from operator import itemgetter
import optparse
import os
import sys
import time
import unittest
+from link_error_detector import LinkErrorDetector
+from local_file_system import LocalFileSystem
from local_renderer import LocalRenderer
from fake_fetchers import ConfigureFakeFetchers
from handler import Handler
@@ -40,6 +43,24 @@ def _GetPublicFiles():
public_files['/'.join((relative_posix_path, filename))] = f.read()
return public_files
+def _PrintBrokenLinks(broken_links):
+ '''Prints out broken links in a more readable format.
+ '''
+ col_width = max(len(link[0]) for link in broken_links)
+ getter = itemgetter(1)
+
+ def pretty_print(prefix, message):
+ print("%s%s -> %s" % (prefix, (col_width - len(prefix)) * ' ', message))
+
+ for target, links in groupby(sorted(broken_links, key=getter), getter):
+ links = [l[0] for l in links]
+ if len(links) > 50:
+ out = "%s and %d others" % (links[0], len(links) - 1)
+ pretty_print(out, target)
+ else:
+ for link in links:
+ pretty_print(link, target)
+
class IntegrationTest(unittest.TestCase):
def setUp(self):
ConfigureFakeFetchers()
@@ -61,6 +82,33 @@ class IntegrationTest(unittest.TestCase):
finally:
print('Took %s seconds' % (time.time() - start_time))
+ print("Checking for broken links...")
+ start_time = time.time()
+ link_error_detector = LinkErrorDetector(
+ LocalFileSystem(os.path.join(sys.path[0], os.pardir, os.pardir)),
+ lambda path: Handler(Request.ForTest(path)).Get(),
+ 'templates/public',
+ ('extensions/index.html', 'apps/about_apps.html'))
+
+ broken_links, broken_anchors = link_error_detector.GetBrokenLinks()
+ if broken_links or broken_anchors:
+ # TODO(jshumway): Test should fail when broken links are detected.
+ print('Warning: Found %d broken links:' % (
+ len(broken_links + broken_anchors)))
+ _PrintBrokenLinks(broken_links + broken_anchors)
+
+ print('Took %s seconds.' % (time.time() - start_time))
+
+ print('Searching for orphaned pages...')
+ start_time = time.time()
+ orphaned_pages = link_error_detector.GetOrphanedPages()
+ if orphaned_pages:
+ # TODO(jshumway): Test should fail when orphaned pages are detected.
+ print('Warning: Found %d orphaned pages:' % len(orphaned_pages))
+ for page in orphaned_pages:
+ print(page)
+ print('Took %s seconds.' % (time.time() - start_time))
+
public_files = _GetPublicFiles()
print('Rendering %s public files...' % len(public_files.keys()))
@@ -103,6 +151,9 @@ class IntegrationTest(unittest.TestCase):
finally:
print('Took %s seconds' % (time.time() - start_time))
+ # TODO(jshumway): Check page for broken links (currently prohibited by the
+ # time it takes to render the pages).
+
@DisableLogging('warning')
def testFileNotFound(self):
response = Handler(Request.ForTest('/extensions/notfound.html')).Get()
« no previous file with comments | « chrome/common/extensions/docs/server2/handler.py ('k') | chrome/common/extensions/docs/server2/link_error_detector.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698