OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Unit tests for sdk_update.py.""" | 6 """Unit tests for sdk_update.py.""" |
7 | 7 |
8 import exceptions | 8 import exceptions |
9 import mox | 9 import mox |
10 import os | 10 import os |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 os.path.join(SCRIPT_DIR, 'sdk_test_cache'), | 77 os.path.join(SCRIPT_DIR, 'sdk_test_cache'), |
78 '--manifest-url=file://%s' % | 78 '--manifest-url=file://%s' % |
79 urllib.pathname2url(os.path.join( | 79 urllib.pathname2url(os.path.join( |
80 SCRIPT_DIR, 'naclsdk_manifest_test.json')), | 80 SCRIPT_DIR, 'naclsdk_manifest_test.json')), |
81 'list'] | 81 'list'] |
82 bundle_list = CallSDKUpdate(command)[0] | 82 bundle_list = CallSDKUpdate(command)[0] |
83 # Just do some simple sanity checks on the resulting string | 83 # Just do some simple sanity checks on the resulting string |
84 self.assertEqual(bundle_list.count('sdk_tools'), 2) | 84 self.assertEqual(bundle_list.count('sdk_tools'), 2) |
85 self.assertEqual(bundle_list.count('test_1'), 2) | 85 self.assertEqual(bundle_list.count('test_1'), 2) |
86 self.assertEqual(bundle_list.count('test_2'), 1) | 86 self.assertEqual(bundle_list.count('test_2'), 1) |
87 self.assertEqual(bundle_list.count('description:'), 6) | 87 self.assertEqual(bundle_list.count('description:'), 7) |
88 | 88 |
89 def testUpdateHelp(self): | 89 def testUpdateHelp(self): |
90 '''Test the help for the update command''' | 90 '''Test the help for the update command''' |
91 self.assertRaises(exceptions.SystemExit, | 91 self.assertRaises(exceptions.SystemExit, |
92 sdk_update.main, ['help', 'update']) | 92 sdk_update.main, ['help', 'update']) |
93 | 93 |
94 def testUpdateBogusBundle(self): | 94 def testUpdateBogusBundle(self): |
95 '''Test running update with a bogus bundle''' | 95 '''Test running update with a bogus bundle''' |
96 self.assertRaises(sdk_update.Error, | 96 self.assertRaises(sdk_update.Error, |
97 sdk_update.main, | 97 sdk_update.main, |
(...skipping 10 matching lines...) Expand all Loading... |
108 test_bundle = manifest_file.GetBundleNamed('test_1') | 108 test_bundle = manifest_file.GetBundleNamed('test_1') |
109 self.assertNotEqual(None, test_bundle) | 109 self.assertNotEqual(None, test_bundle) |
110 self.assertTrue('revision' in test_bundle) | 110 self.assertTrue('revision' in test_bundle) |
111 self.assertEqual(1, test_bundle['revision']) | 111 self.assertEqual(1, test_bundle['revision']) |
112 | 112 |
113 def testNeedsUpdate(self): | 113 def testNeedsUpdate(self): |
114 '''Test that the test_1 bundle needs updating''' | 114 '''Test that the test_1 bundle needs updating''' |
115 tools = sdk_update.ManifestTools(self._options) | 115 tools = sdk_update.ManifestTools(self._options) |
116 tools.LoadManifest() | 116 tools.LoadManifest() |
117 bundles = tools.GetBundles() | 117 bundles = tools.GetBundles() |
118 self.assertEqual(3, len(bundles)) | 118 self.assertEqual(4, len(bundles)) |
119 local_manifest = sdk_update.SDKManifestFile( | 119 local_manifest = sdk_update.SDKManifestFile( |
120 os.path.join(self._options.user_data_dir, | 120 os.path.join(self._options.user_data_dir, |
121 sdk_update.MANIFEST_FILENAME)) | 121 sdk_update.MANIFEST_FILENAME)) |
122 self.assertNotEqual(None, local_manifest) | 122 self.assertNotEqual(None, local_manifest) |
123 for bundle in bundles: | 123 for bundle in bundles: |
124 bundle_name = bundle['name'] | 124 bundle_name = bundle['name'] |
125 self.assertTrue('revision' in bundle) | 125 self.assertTrue('revision' in bundle) |
126 if bundle_name == 'test_1': | 126 if bundle_name in ['test_1', 'test_2', 'pepper_1']: |
127 self.assertTrue(local_manifest.BundleNeedsUpdate(bundle)) | |
128 elif bundle_name == 'test_2': | |
129 self.assertTrue(local_manifest.BundleNeedsUpdate(bundle)) | 127 self.assertTrue(local_manifest.BundleNeedsUpdate(bundle)) |
130 else: | 128 else: |
131 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) | 129 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) |
132 | 130 |
133 def testMergeManifests(self): | 131 def testMergeManifests(self): |
134 '''Test merging a Bundle into a manifest file''' | 132 '''Test merging a Bundle into a manifest file''' |
135 tools = sdk_update.ManifestTools(self._options) | 133 tools = sdk_update.ManifestTools(self._options) |
136 tools.LoadManifest() | 134 tools.LoadManifest() |
137 bundles = tools.GetBundles() | 135 bundles = tools.GetBundles() |
138 self.assertEqual(3, len(bundles)) | 136 self.assertEqual(4, len(bundles)) |
139 local_manifest = sdk_update.SDKManifestFile( | 137 local_manifest = sdk_update.SDKManifestFile( |
140 os.path.join(self._options.user_data_dir, | 138 os.path.join(self._options.user_data_dir, |
141 sdk_update.MANIFEST_FILENAME)) | 139 sdk_update.MANIFEST_FILENAME)) |
142 self.assertEqual(None, local_manifest.GetBundleNamed('test_2')) | 140 self.assertEqual(None, local_manifest.GetBundleNamed('test_2')) |
143 for bundle in bundles: | 141 for bundle in bundles: |
144 local_manifest.MergeBundle(bundle) | 142 local_manifest.MergeBundle(bundle) |
145 self.assertNotEqual(None, local_manifest.GetBundleNamed('test_2')) | 143 self.assertNotEqual(None, local_manifest.GetBundleNamed('test_2')) |
146 for bundle in bundles: | 144 for bundle in bundles: |
147 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) | 145 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) |
148 | 146 |
149 def testMergeBundle(self): | 147 def testMergeBundle(self): |
150 '''Test MergeWithBundle''' | 148 '''Test MergeWithBundle''' |
151 tools = sdk_update.ManifestTools(self._options) | 149 tools = sdk_update.ManifestTools(self._options) |
152 tools.LoadManifest() | 150 tools.LoadManifest() |
153 bundles = tools.GetBundles() | 151 bundles = tools.GetBundles() |
154 self.assertEqual(3, len(bundles)) | 152 self.assertEqual(4, len(bundles)) |
155 local_manifest = sdk_update.SDKManifestFile( | 153 local_manifest = sdk_update.SDKManifestFile( |
156 os.path.join(self._options.user_data_dir, | 154 os.path.join(self._options.user_data_dir, |
157 sdk_update.MANIFEST_FILENAME)) | 155 sdk_update.MANIFEST_FILENAME)) |
158 self.assertNotEqual(None, local_manifest) | 156 self.assertNotEqual(None, local_manifest) |
159 # Test the | operator. | 157 # Test the | operator. |
160 for bundle in bundles: | 158 for bundle in bundles: |
161 bundle_name = bundle['name'] | 159 bundle_name = bundle['name'] |
162 if bundle_name == 'test_2': | 160 if bundle_name in ['pepper_1', 'test_2']: |
163 continue | 161 continue |
164 local_test_bundle = local_manifest.GetBundleNamed(bundle_name) | 162 local_test_bundle = local_manifest.GetBundleNamed(bundle_name) |
165 merged_bundle = local_test_bundle.MergeWithBundle(bundle) | 163 merged_bundle = local_test_bundle.MergeWithBundle(bundle) |
166 self.assertTrue('revision' in merged_bundle) | 164 self.assertTrue('revision' in merged_bundle) |
167 if bundle_name == 'test_1': | 165 if bundle_name == 'test_1': |
168 self.assertEqual(2, merged_bundle['revision']) | 166 self.assertEqual(2, merged_bundle['revision']) |
169 else: | 167 else: |
170 self.assertEqual(1, merged_bundle['revision']) | 168 self.assertEqual(1, merged_bundle['revision']) |
171 merged_bundle.Validate() | 169 merged_bundle.Validate() |
172 | 170 |
173 def testVersion(self): | 171 def testVersion(self): |
174 '''Test that showing the version works''' | 172 '''Test that showing the version works''' |
175 self.assertRaises(exceptions.SystemExit, sdk_update.main, ['--version']) | 173 self.assertRaises(exceptions.SystemExit, sdk_update.main, ['--version']) |
176 | 174 |
177 | 175 |
178 def main(): | 176 def main(): |
179 suite = unittest.TestLoader().loadTestsFromTestCase(TestSDKUpdate) | 177 suite = unittest.TestLoader().loadTestsFromTestCase(TestSDKUpdate) |
180 result = unittest.TextTestRunner(verbosity=2).run(suite) | 178 result = unittest.TextTestRunner(verbosity=2).run(suite) |
181 | 179 |
182 return int(not result.wasSuccessful()) | 180 return int(not result.wasSuccessful()) |
183 | 181 |
184 | 182 |
185 if __name__ == '__main__': | 183 if __name__ == '__main__': |
186 sys.exit(main()) | 184 sys.exit(main()) |
OLD | NEW |