blob: 9e15177ba10478a03aad0cdcb9cdf2ad96885d0c [file] [log] [blame]
markdrdd1893d2018-02-05 17:13:47 -08001#!/usr/bin/env python3
markdr2e25b4d2017-09-28 14:32:37 -07002#
3# Copyright 2017 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import unittest
18from acts.libs.ota.ota_tools import ota_tool_factory
19
20
21class MockOtaTool(object):
22 def __init__(self, command):
23 self.command = command
24
25
26class OtaToolFactoryTests(unittest.TestCase):
27 def setUp(self):
28 ota_tool_factory._constructed_tools = {}
29
30 def test_create_constructor_exists(self):
31 ota_tool_factory._CONSTRUCTORS = {
32 MockOtaTool.__name__: lambda command: MockOtaTool(command),
33 }
34 ret = ota_tool_factory.create(MockOtaTool.__name__, 'command')
35 self.assertEqual(type(ret), MockOtaTool)
36 self.assertTrue(ret in ota_tool_factory._constructed_tools.values())
37
38 def test_create_not_in_constructors(self):
39 ota_tool_factory._CONSTRUCTORS = {}
40 with self.assertRaises(KeyError):
41 ota_tool_factory.create(MockOtaTool.__name__, 'command')
42
43 def test_create_returns_cached_tool(self):
44 ota_tool_factory._CONSTRUCTORS = {
45 MockOtaTool.__name__: lambda command: MockOtaTool(command),
46 }
47 ret_a = ota_tool_factory.create(MockOtaTool.__name__, 'command')
48 ret_b = ota_tool_factory.create(MockOtaTool.__name__, 'command')
49 self.assertEqual(ret_a, ret_b)