Chromium Code Reviews| 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:'), 7) | 87 self.assertEqual(bundle_list.count('description:'), 8) |
|
Matt Ball
2011/12/09 19:40:55
This test has been a little fragile. We should pr
| |
| 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(4, len(bundles)) | 118 self.assertEqual(5, 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 in ['test_1', 'test_2', 'pepper_1']: | 126 if bundle_name in ['test_1', 'test_2', 'pepper_1', 'pepper_phony']: |
| 127 self.assertTrue(local_manifest.BundleNeedsUpdate(bundle)) | 127 self.assertTrue(local_manifest.BundleNeedsUpdate(bundle)) |
| 128 else: | 128 else: |
| 129 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) | 129 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) |
| 130 | 130 |
| 131 def testMergeManifests(self): | 131 def testMergeManifests(self): |
| 132 '''Test merging a Bundle into a manifest file''' | 132 '''Test merging a Bundle into a manifest file''' |
| 133 tools = sdk_update.ManifestTools(self._options) | 133 tools = sdk_update.ManifestTools(self._options) |
| 134 tools.LoadManifest() | 134 tools.LoadManifest() |
| 135 bundles = tools.GetBundles() | 135 bundles = tools.GetBundles() |
| 136 self.assertEqual(4, len(bundles)) | 136 self.assertEqual(5, len(bundles)) |
| 137 local_manifest = sdk_update.SDKManifestFile( | 137 local_manifest = sdk_update.SDKManifestFile( |
| 138 os.path.join(self._options.user_data_dir, | 138 os.path.join(self._options.user_data_dir, |
| 139 sdk_update.MANIFEST_FILENAME)) | 139 sdk_update.MANIFEST_FILENAME)) |
| 140 self.assertEqual(None, local_manifest.GetBundleNamed('test_2')) | 140 self.assertEqual(None, local_manifest.GetBundleNamed('test_2')) |
| 141 for bundle in bundles: | 141 for bundle in bundles: |
| 142 local_manifest.MergeBundle(bundle) | 142 local_manifest.MergeBundle(bundle) |
| 143 self.assertNotEqual(None, local_manifest.GetBundleNamed('test_2')) | 143 self.assertNotEqual(None, local_manifest.GetBundleNamed('test_2')) |
| 144 for bundle in bundles: | 144 for bundle in bundles: |
| 145 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) | 145 self.assertFalse(local_manifest.BundleNeedsUpdate(bundle)) |
| 146 | 146 |
| 147 def testMergeBundle(self): | 147 def testMergeBundle(self): |
| 148 '''Test MergeWithBundle''' | 148 '''Test MergeWithBundle''' |
| 149 tools = sdk_update.ManifestTools(self._options) | 149 tools = sdk_update.ManifestTools(self._options) |
| 150 tools.LoadManifest() | 150 tools.LoadManifest() |
| 151 bundles = tools.GetBundles() | 151 bundles = tools.GetBundles() |
| 152 self.assertEqual(4, len(bundles)) | 152 self.assertEqual(5, len(bundles)) |
| 153 local_manifest = sdk_update.SDKManifestFile( | 153 local_manifest = sdk_update.SDKManifestFile( |
| 154 os.path.join(self._options.user_data_dir, | 154 os.path.join(self._options.user_data_dir, |
| 155 sdk_update.MANIFEST_FILENAME)) | 155 sdk_update.MANIFEST_FILENAME)) |
| 156 self.assertNotEqual(None, local_manifest) | 156 self.assertNotEqual(None, local_manifest) |
| 157 # Test the | operator. | 157 # Test the | operator. |
| 158 for bundle in bundles: | 158 for bundle in bundles: |
| 159 bundle_name = bundle['name'] | 159 bundle_name = bundle['name'] |
| 160 if bundle_name in ['pepper_1', 'test_2']: | 160 if bundle_name in ['pepper_1', 'test_2', 'pepper_phony']: |
| 161 continue | 161 continue |
| 162 local_test_bundle = local_manifest.GetBundleNamed(bundle_name) | 162 local_test_bundle = local_manifest.GetBundleNamed(bundle_name) |
| 163 merged_bundle = local_test_bundle.MergeWithBundle(bundle) | 163 merged_bundle = local_test_bundle.MergeWithBundle(bundle) |
| 164 self.assertTrue('revision' in merged_bundle) | 164 self.assertTrue('revision' in merged_bundle) |
| 165 if bundle_name == 'test_1': | 165 if bundle_name == 'test_1': |
| 166 self.assertEqual(2, merged_bundle['revision']) | 166 self.assertEqual(2, merged_bundle['revision']) |
| 167 else: | 167 else: |
| 168 self.assertEqual(1, merged_bundle['revision']) | 168 self.assertEqual(1, merged_bundle['revision']) |
| 169 merged_bundle.Validate() | 169 merged_bundle.Validate() |
| 170 | 170 |
| 171 def testVersion(self): | 171 def testVersion(self): |
| 172 '''Test that showing the version works''' | 172 '''Test that showing the version works''' |
| 173 self.assertRaises(exceptions.SystemExit, sdk_update.main, ['--version']) | 173 self.assertRaises(exceptions.SystemExit, sdk_update.main, ['--version']) |
| 174 | 174 |
| 175 | 175 |
| 176 def main(): | 176 def main(): |
| 177 suite = unittest.TestLoader().loadTestsFromTestCase(TestSDKUpdate) | 177 suite = unittest.TestLoader().loadTestsFromTestCase(TestSDKUpdate) |
| 178 result = unittest.TextTestRunner(verbosity=2).run(suite) | 178 result = unittest.TextTestRunner(verbosity=2).run(suite) |
| 179 | 179 |
| 180 return int(not result.wasSuccessful()) | 180 return int(not result.wasSuccessful()) |
| 181 | 181 |
| 182 | 182 |
| 183 if __name__ == '__main__': | 183 if __name__ == '__main__': |
| 184 sys.exit(main()) | 184 sys.exit(main()) |
| OLD | NEW |