dom/imptests/parseManifest.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/imptests/parseManifest.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,69 @@
     1.4 +# Copyright (C) 2011-2013 Ms2ger
     1.5 +#
     1.6 +# Permission is hereby granted, free of charge, to any person obtaining a copy
     1.7 +# of this software and associated documentation files (the "Software"), to deal
     1.8 +# in the Software without restriction, including without limitation the rights
     1.9 +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    1.10 +# copies of the Software, and to permit persons to whom the Software is
    1.11 +# furnished to do so, subject to the following conditions:
    1.12 +#
    1.13 +# The above copyright notice and this permission notice shall be included in
    1.14 +# all copies or substantial portions of the Software.
    1.15 +#
    1.16 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.17 +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.18 +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    1.19 +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.20 +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    1.21 +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    1.22 +# THE SOFTWARE.
    1.23 +
    1.24 +
    1.25 +def parseManifest(fd):
    1.26 +    def parseReftestLine(chunks):
    1.27 +        assert len(chunks) % 2 == 0
    1.28 +        reftests = []
    1.29 +        for i in range(2, len(chunks), 2):
    1.30 +            if not chunks[i] in ["==", "!="]:
    1.31 +                raise Exception("Misformatted reftest line " + line)
    1.32 +            reftests.append([chunks[i], chunks[1], chunks[i + 1]])
    1.33 +        return reftests
    1.34 +
    1.35 +    dirs = []
    1.36 +    autotests = []
    1.37 +    reftests = []
    1.38 +    othertests = []
    1.39 +    supportfiles = []
    1.40 +    for fullline in fd:
    1.41 +        line = fullline.strip()
    1.42 +        if not line:
    1.43 +            continue
    1.44 +
    1.45 +        chunks = line.split(" ")
    1.46 +
    1.47 +        if chunks[0] == "MANIFEST":
    1.48 +            raise Exception("MANIFEST listed on line " + line)
    1.49 +
    1.50 +        if chunks[0] == "dir":
    1.51 +            dirs.append(chunks[1])
    1.52 +        elif chunks[0] == "support" and chunks[1] == "dir":
    1.53 +            dirs.append(chunks[1])
    1.54 +        elif chunks[0] == "ref":
    1.55 +            if len(chunks) % 2:
    1.56 +                raise Exception("Missing chunk in line " + line)
    1.57 +            reftests.extend(parseReftestLine(chunks))
    1.58 +        elif chunks[0] == "support":
    1.59 +            supportfiles.append(chunks[1])
    1.60 +        elif chunks[0] in ["manual", "parser", "http"]:
    1.61 +            othertests.append(chunks[1])
    1.62 +        else:
    1.63 +            # automated
    1.64 +            autotests.append(chunks[0])
    1.65 +    return dirs, autotests, reftests, othertests, supportfiles
    1.66 +
    1.67 +
    1.68 +def parseManifestFile(path):
    1.69 +    fp = open(path)
    1.70 +    dirs, autotests, reftests, othertests, supportfiles = parseManifest(fp)
    1.71 +    fp.close()
    1.72 +    return dirs, autotests, reftests, othertests, supportfiles

mercurial