From b04b50bd634e2bf1d717b40636bf3889a67dd22f Mon Sep 17 00:00:00 2001
From: Henrik Levkowetz <henrik@levkowetz.com>
Date: Fri, 15 Jun 2007 13:29:50 +0000
Subject: [PATCH] Refined the handling of sorted comparison tests  - Legacy-Id:
 405

---
 ietf/tests.py | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/ietf/tests.py b/ietf/tests.py
index ae905bd88..df669f4b6 100644
--- a/ietf/tests.py
+++ b/ietf/tests.py
@@ -21,14 +21,17 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
     # during the search for a 'tests' module ...
     return django.test.simple.run_tests(module_list, verbosity, extra_tests)
 
-def reduce(html):
+def reduce(html, pre=False, fill=True):
     html = re.sub(" :", ":", html)
     if html.count("<li>") > 5*html.count("</li>"):
         html = html.replace("<li>", "</li><li>")
-    text = html2text(html)
+    text = html2text(html, pre=pre, fill=fill)
     text = text.replace('."', '".')
     text = text.replace(',"', '",')
-    text = [ line.strip() for line in text.split("\n") ]
+    if pre:
+        text = text.split("\n")
+    else:
+        text = [ line.strip() for line in text.split("\n") ]
     return text
 
 def get_patterns(module):
@@ -139,7 +142,11 @@ class UrlTestCase(TestCase):
         #self.assertEqual(set(patterns), set(covered), "Not all the
         #application URLs has test cases.  The missing are: %s" % (list(set(patterns) - set(covered))))        
         if not set(self.patterns) == set(covered):
-            print "Not all the application URLs has test cases.  The missing are: \n   %s" % ("\n   ".join(list(set(self.patterns) - set(covered))))
+            missing = list(set(self.patterns) - set(covered))
+            print "Not all the application URLs has test cases, there are %d missing." % (len(missing))
+            print "The ones missing are: "
+            for pattern in missing:
+                print "Miss", pattern
         else:
             print "All the application URL patterns seem to have test cases."
             #print "Not all the application URLs has test cases."
@@ -175,18 +182,19 @@ class UrlTestCase(TestCase):
                     try:
                         mfile.close()
                         if goodhtml and response.content:
-                            testtext = reduce(response.content)
-                            goodtext = reduce(goodhtml)
                             if "sort" in codes:
-                                try:
-                                    def sorted(l):
-                                        l.sort()
-                                        return l
-                                    testtext = sorted(testtext)
-                                    goodtext = sorted(goodtext)
-                                except:
-                                    print "Exception occurred when trying to do sorted comparison"
-                                    traceback.print_exc()
+                                def sorted(l):
+                                    l.sort()
+                                    return l
+                                testtext = sorted(reduce(response.content, fill=False))
+                                while testtext and not testtext[0]:
+                                    del testtext[0]
+                                goodtext = sorted(reduce(goodhtml, fill=False))
+                                while goodtext and not goodtext[0]:
+                                    del goodtext[0]
+                            else:
+                                testtext = reduce(response.content)
+                                goodtext = reduce(goodhtml)
                             if testtext == goodtext:
                                 print "OK   cmp %s" % (url)
                             else: