Created tests for the OTA Update library
Tests mirror the structure of the code:
acts/framework/tests/(.*)_test.py -> acts/framework/acts/$1.py
Bug: 63705128
Test: This commit
Change-Id: I73e72998f28d9442a2190767a333127478eb31ac
diff --git a/acts/framework/tests/libs/ota/ota_tools/ota_tool_factory_test.py b/acts/framework/tests/libs/ota/ota_tools/ota_tool_factory_test.py
new file mode 100644
index 0000000..5b9839e
--- /dev/null
+++ b/acts/framework/tests/libs/ota/ota_tools/ota_tool_factory_test.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3.4
+#
+# Copyright 2017 - The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import unittest
+from acts.libs.ota.ota_tools import ota_tool_factory
+
+
+class MockOtaTool(object):
+ def __init__(self, command):
+ self.command = command
+
+
+class OtaToolFactoryTests(unittest.TestCase):
+ def setUp(self):
+ ota_tool_factory._constructed_tools = {}
+
+ def test_create_constructor_exists(self):
+ ota_tool_factory._CONSTRUCTORS = {
+ MockOtaTool.__name__: lambda command: MockOtaTool(command),
+ }
+ ret = ota_tool_factory.create(MockOtaTool.__name__, 'command')
+ self.assertEqual(type(ret), MockOtaTool)
+ self.assertTrue(ret in ota_tool_factory._constructed_tools.values())
+
+ def test_create_not_in_constructors(self):
+ ota_tool_factory._CONSTRUCTORS = {}
+ with self.assertRaises(KeyError):
+ ota_tool_factory.create(MockOtaTool.__name__, 'command')
+
+ def test_create_returns_cached_tool(self):
+ ota_tool_factory._CONSTRUCTORS = {
+ MockOtaTool.__name__: lambda command: MockOtaTool(command),
+ }
+ ret_a = ota_tool_factory.create(MockOtaTool.__name__, 'command')
+ ret_b = ota_tool_factory.create(MockOtaTool.__name__, 'command')
+ self.assertEqual(ret_a, ret_b)