addon-sdk/source/python-lib/cuddlefish/tests/test_packaging.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_packaging.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     1.4 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 +
     1.8 +import os
     1.9 +import unittest
    1.10 +
    1.11 +from cuddlefish import packaging
    1.12 +from cuddlefish.bunch import Bunch
    1.13 +
    1.14 +tests_path = os.path.abspath(os.path.dirname(__file__))
    1.15 +static_files_path = os.path.join(tests_path, 'static-files')
    1.16 +
    1.17 +def get_configs(pkg_name, dirname='static-files'):
    1.18 +    root_path = os.path.join(tests_path, dirname)
    1.19 +    pkg_path = os.path.join(root_path, 'packages', pkg_name)
    1.20 +    if not (os.path.exists(pkg_path) and os.path.isdir(pkg_path)):
    1.21 +        raise Exception('path does not exist: %s' % pkg_path)
    1.22 +    target_cfg = packaging.get_config_in_dir(pkg_path)
    1.23 +    pkg_cfg = packaging.build_config(root_path, target_cfg)
    1.24 +    deps = packaging.get_deps_for_targets(pkg_cfg, [pkg_name])
    1.25 +    build = packaging.generate_build_for_target(
    1.26 +        pkg_cfg=pkg_cfg,
    1.27 +        target=pkg_name,
    1.28 +        deps=deps,
    1.29 +        is_running_tests=True,
    1.30 +        )
    1.31 +    return Bunch(target_cfg=target_cfg, pkg_cfg=pkg_cfg, build=build)
    1.32 +
    1.33 +class PackagingTests(unittest.TestCase):
    1.34 +    def test_bug_588661(self):
    1.35 +        configs = get_configs('foo', 'bug-588661-files')
    1.36 +        self.assertEqual(configs.build.loader,
    1.37 +                         'foo/lib/foo-loader.js')
    1.38 +
    1.39 +    def test_bug_614712(self):
    1.40 +        configs = get_configs('commonjs-naming', 'bug-614712-files')
    1.41 +        packages = configs.pkg_cfg.packages
    1.42 +        base = os.path.join(tests_path, 'bug-614712-files', 'packages')
    1.43 +        self.assertEqual(packages['original-naming'].tests,
    1.44 +                         [os.path.join(base, 'original-naming', 'tests')])
    1.45 +        self.assertEqual(packages['commonjs-naming'].tests,
    1.46 +                         [os.path.join(base, 'commonjs-naming', 'test')])
    1.47 +
    1.48 +    def test_basic(self):
    1.49 +        configs = get_configs('aardvark')
    1.50 +        packages = configs.pkg_cfg.packages
    1.51 +
    1.52 +        self.assertTrue('addon-sdk' in packages)
    1.53 +        self.assertTrue('aardvark' in packages)
    1.54 +        self.assertTrue('addon-sdk' in packages.aardvark.dependencies)
    1.55 +        self.assertEqual(packages['addon-sdk'].loader, 'lib/sdk/loader/cuddlefish.js')
    1.56 +        self.assertTrue(packages.aardvark.main == 'main')
    1.57 +        self.assertTrue(packages.aardvark.version == "1.0")
    1.58 +
    1.59 +class PackagePath(unittest.TestCase):
    1.60 +    def test_packagepath(self):
    1.61 +        root_path = os.path.join(tests_path, 'static-files')
    1.62 +        pkg_path = os.path.join(root_path, 'packages', 'minimal')
    1.63 +        target_cfg = packaging.get_config_in_dir(pkg_path)
    1.64 +        pkg_cfg = packaging.build_config(root_path, target_cfg)
    1.65 +        base_packages = set(pkg_cfg.packages.keys())
    1.66 +        ppath = [os.path.join(tests_path, 'bug-611495-files')]
    1.67 +        pkg_cfg2 = packaging.build_config(root_path, target_cfg, packagepath=ppath)
    1.68 +        all_packages = set(pkg_cfg2.packages.keys())
    1.69 +        self.assertEqual(sorted(["jspath-one"]),
    1.70 +                         sorted(all_packages - base_packages))
    1.71 +
    1.72 +class Directories(unittest.TestCase):
    1.73 +    # for bug 652227
    1.74 +    packages_path = os.path.join(tests_path, "bug-652227-files", "packages")
    1.75 +    def get_config(self, pkg_name):
    1.76 +        pkg_path = os.path.join(tests_path, "bug-652227-files", "packages",
    1.77 +                                pkg_name)
    1.78 +        return packaging.get_config_in_dir(pkg_path)
    1.79 +
    1.80 +    def test_explicit_lib(self):
    1.81 +        # package.json provides .lib
    1.82 +        p = self.get_config('explicit-lib')
    1.83 +        self.assertEqual(os.path.abspath(p.lib[0]),
    1.84 +                         os.path.abspath(os.path.join(self.packages_path,
    1.85 +                                                      "explicit-lib",
    1.86 +                                                      "alt2-lib")))
    1.87 +
    1.88 +    def test_directories_lib(self):
    1.89 +        # package.json provides .directories.lib
    1.90 +        p = self.get_config('explicit-dir-lib')
    1.91 +        self.assertEqual(os.path.abspath(p.lib[0]),
    1.92 +                         os.path.abspath(os.path.join(self.packages_path,
    1.93 +                                                      "explicit-dir-lib",
    1.94 +                                                      "alt-lib")))
    1.95 +
    1.96 +    def test_lib(self):
    1.97 +        # package.json is empty, but lib/ exists
    1.98 +        p = self.get_config("default-lib")
    1.99 +        self.assertEqual(os.path.abspath(p.lib[0]),
   1.100 +                         os.path.abspath(os.path.join(self.packages_path,
   1.101 +                                                      "default-lib",
   1.102 +                                                      "lib")))
   1.103 +
   1.104 +    def test_root(self):
   1.105 +        # package.json is empty, no lib/, so files are in root
   1.106 +        p = self.get_config('default-root')
   1.107 +        self.assertEqual(os.path.abspath(p.lib[0]),
   1.108 +                         os.path.abspath(os.path.join(self.packages_path,
   1.109 +                                                      "default-root")))
   1.110 +
   1.111 +    def test_locale(self):
   1.112 +        # package.json is empty, but locale/ exists and should be used
   1.113 +        p = self.get_config("default-locale")
   1.114 +        self.assertEqual(os.path.abspath(p.locale),
   1.115 +                         os.path.abspath(os.path.join(self.packages_path,
   1.116 +                                                      "default-locale",
   1.117 +                                                      "locale")))
   1.118 +
   1.119 +if __name__ == "__main__":
   1.120 +    unittest.main()

mercurial