Bug 1253189 part 2 - Update import-tests.py script to work on the current repo. draft
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 03 Mar 2016 18:24:46 +0800
changeset 336846 360fb50a309633c8d2c9fee95772f56af7ff765e
parent 336845 91383b0122750405d7ee39a7f2996751cfb0dc49
child 336847 17f11134f1a31261dac7c874122dd1fd8b195fab
push id12191
push userxquan@mozilla.com
push dateFri, 04 Mar 2016 08:09:09 +0000
bugs1253189
milestone47.0a1
Bug 1253189 part 2 - Update import-tests.py script to work on the current repo. MozReview-Commit-ID: 7u2tzEEOQSg
layout/reftests/w3c-css/import-tests.py
--- a/layout/reftests/w3c-css/import-tests.py
+++ b/layout/reftests/w3c-css/import-tests.py
@@ -24,20 +24,18 @@ import re
 # least for a subset of secs.  And we probably want to organize the
 # directory structure by spec to avoid constant file moves when files
 # move in the W3C repository.  And we probably also want to import each
 # test only once, even if it covers more than one spec.)
 
 # But for now, let's just import a few sets of tests.
 
 gSubtrees = [
-    os.path.join("approved", "css3-namespace", "src"),
-    #os.path.join("approved", "css3-multicol", "src"),
-    os.path.join("contributors", "opera", "submitted", "css3-conditional"),
-    #os.path.join("contributors", "opera", "submitted", "multicol")
+    os.path.join("css-namespaces-1"),
+    os.path.join("css-conditional-3"),
 ]
 
 gPrefixedProperties = [
     "column-count",
     "column-fill",
     "column-gap",
     "column-rule",
     "column-rule-color",
@@ -106,16 +104,20 @@ def remove_existing_dirs():
 def populate_test_files():
     global gSubtrees, gTestfiles
     for subtree in gSubtrees:
         for dirpath, dirnames, filenames in os.walk(subtree, topdown=True):
             if "support" in dirnames:
                dirnames.remove("support")
             if "reftest" in dirnames:
                dirnames.remove("reftest")
+            if "reference" in dirnames:
+               dirnames.remove("reference")
+            if "reports" in dirnames:
+               dirnames.remove("reports")
             for f in filenames:
                 if f == "README" or \
                    f.find("-ref.") != -1:
                     continue
                 gTestfiles.append(os.path.join(dirpath, f))
 
     gTestfiles.sort()
 
@@ -177,41 +179,44 @@ def get_document_for(fn, spec):
         parser = html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("dom"))
         document = parser.parse(f)
         f.close()
     else:
         # An XML file
         document = xml.dom.minidom.parse(fn)
     return document
 
+SPEC_URL_PATS = [
+        re.compile(r"https://drafts\.csswg\.org/([a-zA-Z0-9-]+)/"),
+        re.compile(r"http://www\.w3\.org/TR/([a-zA-Z0-9-]+)/"),
+        ]
+
 def add_test_items(fn, spec):
     document = get_document_for(fn, spec)
     refs = []
     notrefs = []
     for link in document.getElementsByTagName("link"):
         rel = link.getAttribute("rel")
         if rel == "help" and spec == None:
             specurl = link.getAttribute("href")
-            startidx = specurl.find("/TR/")
-            if startidx != -1:
-                startidx = startidx + 4
-                endidx = specurl.find("/", startidx)
-                if endidx != -1:
-                    spec = str(specurl[startidx:endidx])
+            for pat in SPEC_URL_PATS:
+                match = pat.match(specurl)
+                if match:
+                    spec = match.group(1)
         if rel == "match":
             arr = refs
         elif rel == "mismatch":
             arr = notrefs
         else:
             continue
         arr.append(os.path.join(os.path.dirname(fn), str(link.getAttribute("href"))))
     if len(refs) > 1:
         raise StandardError("Need to add code to specify which reference we want to match.")
     if spec is None:
-        raise StandardError("Could not associate test with specification")
+        raise StandardError("Could not associate test " + fn + " with specification")
     for ref in refs:
         tests.append(["==", map_file(fn, spec), map_file(ref, spec)])
     for notref in notrefs:
         tests.append(["!=", map_file(fn, spec), map_file(notref, spec)])
     # Add chained references too
     for ref in refs:
         add_test_items(ref, spec=spec)
     for notref in notrefs: