OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import os |
| 6 import unittest |
| 7 |
| 8 from telemetry.core import exceptions |
| 9 from telemetry.internal.util import binary_manager |
| 10 from telemetry.third_party import mock |
| 11 |
| 12 |
| 13 class BinaryManagerTest(unittest.TestCase): |
| 14 def setUp(self): |
| 15 # We need to preserve the real initialized dependecny_manager. |
| 16 self.actual_dep_manager = binary_manager._dependency_manager |
| 17 binary_manager._dependency_manager = None |
| 18 |
| 19 # Mock out the dependency manager and support binaries module so we're only |
| 20 # testing the binary_manager itself. |
| 21 self.actual_dep_manager_module = binary_manager.dependency_manager |
| 22 self.actual_support_binaries_module = binary_manager.support_binaries |
| 23 self.manager = mock.MagicMock() |
| 24 binary_manager.dependency_manager = self.manager.dependency_manager |
| 25 binary_manager.support_binaries = self.manager.support_binaries |
| 26 |
| 27 def tearDown(self): |
| 28 binary_manager._dependency_manager = self.actual_dep_manager |
| 29 binary_manager.dependency_manager = self.actual_dep_manager_module |
| 30 binary_manager.support_binaries = self.actual_support_binaries_module |
| 31 |
| 32 def testInitializationNoEnvironmentConfig(self): |
| 33 expected = [mock.call.dependency_manager.DependencyManager( |
| 34 [binary_manager.TELEMETRY_PROJECT_CONFIG])] |
| 35 binary_manager.InitDependencyManager(None) |
| 36 self.assertEqual(self.manager.mock_calls, expected) |
| 37 |
| 38 def testInitializationWithEnvironmentConfig(self): |
| 39 environment_config = os.path.join('some', 'config', 'path') |
| 40 expected = [mock.call.dependency_manager.DependencyManager( |
| 41 [binary_manager.TELEMETRY_PROJECT_CONFIG, environment_config])] |
| 42 binary_manager.InitDependencyManager(environment_config) |
| 43 self.assertEqual(self.manager.mock_calls, expected) |
| 44 |
| 45 def testReinitialization(self): |
| 46 binary_manager.InitDependencyManager(None) |
| 47 self.assertRaises(exceptions.InitializationError, |
| 48 binary_manager.InitDependencyManager, None) |
| 49 |
| 50 def testFetchPathInitialized(self): |
| 51 expected = [mock.call.dependency_manager.DependencyManager( |
| 52 [binary_manager.TELEMETRY_PROJECT_CONFIG]), |
| 53 mock.call.support_binaries.FindPath('dep', 'plat', 'arch')] |
| 54 binary_manager.InitDependencyManager(None) |
| 55 binary_manager.FetchPath('dep', 'plat', 'arch') |
| 56 self.assertEqual(self.manager.mock_calls, expected) |
| 57 #TODO(aiolos): We should be switching over to using the dependency_manager |
| 58 #insead of the support binaries, and update the tests at that time. |
| 59 |
| 60 def testFetchPathUninitialized(self): |
| 61 self.assertRaises(exceptions.InitializationError, |
| 62 binary_manager.FetchPath, 'dep', 'plat', 'arch') |
| 63 |
| 64 def testLocalPathInitialized(self): |
| 65 expected = [mock.call.dependency_manager.DependencyManager( |
| 66 [binary_manager.TELEMETRY_PROJECT_CONFIG]), |
| 67 mock.call.support_binaries.FindLocallyBuiltPath('dep')] |
| 68 binary_manager.InitDependencyManager(None) |
| 69 binary_manager.LocalPath('dep', 'plat', 'arch') |
| 70 self.assertEqual(self.manager.mock_calls, expected) |
| 71 #TODO(aiolos): We should be switching over to using the dependency_manager |
| 72 #insead of the support binaries, and update the tests at that time. |
| 73 |
| 74 def testLocalPathUninitialized(self): |
| 75 self.assertRaises(exceptions.InitializationError, |
| 76 binary_manager.LocalPath, 'dep', 'plat', 'arch') |
| 77 |
OLD | NEW |