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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4
michael@0 5 import os
michael@0 6 import unittest
michael@0 7
michael@0 8 from cuddlefish import packaging
michael@0 9 from cuddlefish.bunch import Bunch
michael@0 10
michael@0 11 tests_path = os.path.abspath(os.path.dirname(__file__))
michael@0 12 static_files_path = os.path.join(tests_path, 'static-files')
michael@0 13
michael@0 14 def get_configs(pkg_name, dirname='static-files'):
michael@0 15 root_path = os.path.join(tests_path, dirname)
michael@0 16 pkg_path = os.path.join(root_path, 'packages', pkg_name)
michael@0 17 if not (os.path.exists(pkg_path) and os.path.isdir(pkg_path)):
michael@0 18 raise Exception('path does not exist: %s' % pkg_path)
michael@0 19 target_cfg = packaging.get_config_in_dir(pkg_path)
michael@0 20 pkg_cfg = packaging.build_config(root_path, target_cfg)
michael@0 21 deps = packaging.get_deps_for_targets(pkg_cfg, [pkg_name])
michael@0 22 build = packaging.generate_build_for_target(
michael@0 23 pkg_cfg=pkg_cfg,
michael@0 24 target=pkg_name,
michael@0 25 deps=deps,
michael@0 26 is_running_tests=True,
michael@0 27 )
michael@0 28 return Bunch(target_cfg=target_cfg, pkg_cfg=pkg_cfg, build=build)
michael@0 29
michael@0 30 class PackagingTests(unittest.TestCase):
michael@0 31 def test_bug_588661(self):
michael@0 32 configs = get_configs('foo', 'bug-588661-files')
michael@0 33 self.assertEqual(configs.build.loader,
michael@0 34 'foo/lib/foo-loader.js')
michael@0 35
michael@0 36 def test_bug_614712(self):
michael@0 37 configs = get_configs('commonjs-naming', 'bug-614712-files')
michael@0 38 packages = configs.pkg_cfg.packages
michael@0 39 base = os.path.join(tests_path, 'bug-614712-files', 'packages')
michael@0 40 self.assertEqual(packages['original-naming'].tests,
michael@0 41 [os.path.join(base, 'original-naming', 'tests')])
michael@0 42 self.assertEqual(packages['commonjs-naming'].tests,
michael@0 43 [os.path.join(base, 'commonjs-naming', 'test')])
michael@0 44
michael@0 45 def test_basic(self):
michael@0 46 configs = get_configs('aardvark')
michael@0 47 packages = configs.pkg_cfg.packages
michael@0 48
michael@0 49 self.assertTrue('addon-sdk' in packages)
michael@0 50 self.assertTrue('aardvark' in packages)
michael@0 51 self.assertTrue('addon-sdk' in packages.aardvark.dependencies)
michael@0 52 self.assertEqual(packages['addon-sdk'].loader, 'lib/sdk/loader/cuddlefish.js')
michael@0 53 self.assertTrue(packages.aardvark.main == 'main')
michael@0 54 self.assertTrue(packages.aardvark.version == "1.0")
michael@0 55
michael@0 56 class PackagePath(unittest.TestCase):
michael@0 57 def test_packagepath(self):
michael@0 58 root_path = os.path.join(tests_path, 'static-files')
michael@0 59 pkg_path = os.path.join(root_path, 'packages', 'minimal')
michael@0 60 target_cfg = packaging.get_config_in_dir(pkg_path)
michael@0 61 pkg_cfg = packaging.build_config(root_path, target_cfg)
michael@0 62 base_packages = set(pkg_cfg.packages.keys())
michael@0 63 ppath = [os.path.join(tests_path, 'bug-611495-files')]
michael@0 64 pkg_cfg2 = packaging.build_config(root_path, target_cfg, packagepath=ppath)
michael@0 65 all_packages = set(pkg_cfg2.packages.keys())
michael@0 66 self.assertEqual(sorted(["jspath-one"]),
michael@0 67 sorted(all_packages - base_packages))
michael@0 68
michael@0 69 class Directories(unittest.TestCase):
michael@0 70 # for bug 652227
michael@0 71 packages_path = os.path.join(tests_path, "bug-652227-files", "packages")
michael@0 72 def get_config(self, pkg_name):
michael@0 73 pkg_path = os.path.join(tests_path, "bug-652227-files", "packages",
michael@0 74 pkg_name)
michael@0 75 return packaging.get_config_in_dir(pkg_path)
michael@0 76
michael@0 77 def test_explicit_lib(self):
michael@0 78 # package.json provides .lib
michael@0 79 p = self.get_config('explicit-lib')
michael@0 80 self.assertEqual(os.path.abspath(p.lib[0]),
michael@0 81 os.path.abspath(os.path.join(self.packages_path,
michael@0 82 "explicit-lib",
michael@0 83 "alt2-lib")))
michael@0 84
michael@0 85 def test_directories_lib(self):
michael@0 86 # package.json provides .directories.lib
michael@0 87 p = self.get_config('explicit-dir-lib')
michael@0 88 self.assertEqual(os.path.abspath(p.lib[0]),
michael@0 89 os.path.abspath(os.path.join(self.packages_path,
michael@0 90 "explicit-dir-lib",
michael@0 91 "alt-lib")))
michael@0 92
michael@0 93 def test_lib(self):
michael@0 94 # package.json is empty, but lib/ exists
michael@0 95 p = self.get_config("default-lib")
michael@0 96 self.assertEqual(os.path.abspath(p.lib[0]),
michael@0 97 os.path.abspath(os.path.join(self.packages_path,
michael@0 98 "default-lib",
michael@0 99 "lib")))
michael@0 100
michael@0 101 def test_root(self):
michael@0 102 # package.json is empty, no lib/, so files are in root
michael@0 103 p = self.get_config('default-root')
michael@0 104 self.assertEqual(os.path.abspath(p.lib[0]),
michael@0 105 os.path.abspath(os.path.join(self.packages_path,
michael@0 106 "default-root")))
michael@0 107
michael@0 108 def test_locale(self):
michael@0 109 # package.json is empty, but locale/ exists and should be used
michael@0 110 p = self.get_config("default-locale")
michael@0 111 self.assertEqual(os.path.abspath(p.locale),
michael@0 112 os.path.abspath(os.path.join(self.packages_path,
michael@0 113 "default-locale",
michael@0 114 "locale")))
michael@0 115
michael@0 116 if __name__ == "__main__":
michael@0 117 unittest.main()

mercurial