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