Bug 1253189 part 2 - Update import-tests.py script to work on the current repo. r=dbaron draft
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 03 Mar 2016 18:24:46 +0800
changeset 340443 0a0530a881207af87a82ef64cde3f80fa19bbd13
parent 340442 461609bee3f7dfe086629dfbd1f8da42c65ed6d7
child 340444 940bc5d26d31dc0b1bc4ac2d96d7146b7e658443
push id12962
push userxquan@mozilla.com
push dateTue, 15 Mar 2016 08:22:36 +0000
reviewersdbaron
bugs1253189
milestone48.0a1
Bug 1253189 part 2 - Update import-tests.py script to work on the current repo. r=dbaron 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-3"),
+    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()
 
@@ -155,63 +157,60 @@ def map_file(fn, spec):
     filemap[fn] = destname
     load_flags_for(fn, spec)
     copy_file(destname, fn, destname, False)
     copy_support_files(destname, os.path.dirname(fn), spec)
     return destname
 
 def load_flags_for(fn, spec):
     global gTestFlags
-    document = get_document_for(fn, spec)
+    document = get_document_for(fn)
     destname = os.path.join(spec, os.path.basename(fn))
     gTestFlags[destname] = []
 
     for meta in document.getElementsByTagName("meta"):
         name = meta.getAttribute("name")
         if name == "flags":
             gTestFlags[destname] = meta.getAttribute("content").split()
 
-def get_document_for(fn, spec):
+def get_document_for(fn):
     document = None # an xml.dom.minidom document
     if fn.endswith(".htm") or fn.endswith(".html"):
         # An HTML file
         f = open(fn, "r")
         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
 
 def add_test_items(fn, spec):
-    document = get_document_for(fn, spec)
+    document = get_document_for(fn)
     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])
         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")
+        for subtree in gSubtrees:
+            if fn.startswith(subtree):
+                spec = os.path.basename(subtree)
+                break
+        else:
+            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: