addon-sdk/source/python-lib/cuddlefish/tests/test_licenses.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/addon-sdk/source/python-lib/cuddlefish/tests/test_licenses.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,88 @@
     1.4 +
     1.5 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.8 +
     1.9 +import unittest
    1.10 +import os.path
    1.11 +
    1.12 +parent = os.path.dirname
    1.13 +test_dir = parent(os.path.abspath(__file__))
    1.14 +sdk_root = parent(parent(parent(test_dir)))
    1.15 +
    1.16 +def from_sdk_top(fn):
    1.17 +    return os.path.abspath(os.path.join(sdk_root, fn))
    1.18 +
    1.19 +MPL2_URL = "http://mozilla.org/MPL/2.0/"
    1.20 +
    1.21 +# These files all come with their own license headers
    1.22 +skip = [
    1.23 +    "python-lib/cuddlefish/_version.py", # generated, public domain
    1.24 +    "doc/static-files/js/jquery.js", # MIT/GPL dual
    1.25 +    "examples/annotator/data/jquery-1.4.2.min.js", # MIT/GPL dual
    1.26 +    "examples/reddit-panel/data/jquery-1.4.4.min.js", # MIT/GPL dual
    1.27 +    "examples/library-detector/data/library-detector.js", # MIT
    1.28 +    "python-lib/mozrunner/killableprocess.py", # MIT? BSDish?
    1.29 +    "python-lib/mozrunner/winprocess.py", # MIT
    1.30 +    "packages/api-utils/tests/test-querystring.js", # MIT
    1.31 +    "packages/api-utils/lib/promise.js", # MIT
    1.32 +    "packages/api-utils/tests/test-promise.js", # MIT
    1.33 +    ]
    1.34 +absskip = [from_sdk_top(os.path.join(*fn.split("/"))) for fn in skip]
    1.35 +
    1.36 +class Licenses(unittest.TestCase):
    1.37 +    def test(self):
    1.38 +        # Examine most SDK files to check if they've got an MPL2 license
    1.39 +        # header. We exclude some files that are known to include different
    1.40 +        # licenses.
    1.41 +        self.missing = []
    1.42 +        self.scan_file(from_sdk_top(os.path.join("python-lib", "jetpack_sdk_env.py")))
    1.43 +        self.scan(os.path.join("python-lib", "cuddlefish"), [".js", ".py"],
    1.44 +                  skipdirs=["sdk-docs"], # test_generate.py makes this
    1.45 +                  )
    1.46 +        self.scan(os.path.join("python-lib", "mozrunner"), [".py"])
    1.47 +
    1.48 +        for sdk_package in ["addon-kit", "api-utils", "test-harness"]:
    1.49 +            self.scan(os.path.join("packages", sdk_package),
    1.50 +                      [".js", ".py", ".md"])
    1.51 +        self.scan("examples", [".js", ".css", ".html", ".md"])
    1.52 +        self.scan("bin", [".bat", ".ps1"])
    1.53 +        for fn in [os.path.join("bin", "activate"),
    1.54 +                   os.path.join("bin", "cfx"),
    1.55 +                   os.path.join("bin", "integration-scripts", "buildbot-run-cfx-helper"),
    1.56 +                   os.path.join("bin", "integration-scripts", "integration-check"),
    1.57 +                   ]:
    1.58 +            self.scan_file(from_sdk_top(fn))
    1.59 +        self.scan("doc", [".js", ".css", ".md"], skipdirs=["syntaxhighlighter"])
    1.60 +
    1.61 +        if self.missing:
    1.62 +            print
    1.63 +            print "The following files are missing an MPL2 header:"
    1.64 +            for fn in sorted(self.missing):
    1.65 +                print " "+fn
    1.66 +            self.fail("%d files are missing an MPL2 header" % len(self.missing))
    1.67 +
    1.68 +    def scan(self, start, extensions=[], skipdirs=[]):
    1.69 +        # scan a whole subdirectory
    1.70 +        start = from_sdk_top(start)
    1.71 +        for root, dirs, files in os.walk(start):
    1.72 +            for d in skipdirs:
    1.73 +                if d in dirs:
    1.74 +                    dirs.remove(d)
    1.75 +            for fn in files:
    1.76 +                ext = os.path.splitext(fn)[1]
    1.77 +                if extensions and ext not in extensions:
    1.78 +                    continue
    1.79 +                absfn = os.path.join(root, fn)
    1.80 +                if absfn in absskip:
    1.81 +                    continue
    1.82 +                self.scan_file(absfn)
    1.83 +
    1.84 +    def scan_file(self, fn):
    1.85 +        # scan a single file
    1.86 +        if not MPL2_URL in open(fn, "r").read():
    1.87 +            relfile = fn[len(sdk_root)+1:]
    1.88 +            self.missing.append(relfile)
    1.89 +
    1.90 +if __name__ == '__main__':
    1.91 +    unittest.main()

mercurial