diff options
author | Tri Vo <trong@google.com> | 2017-03-02 11:28:31 -0800 |
---|---|---|
committer | Tri Vo <trong@google.com> | 2017-03-02 14:56:21 -0800 |
commit | 05f0189a7cc0e730ad65f9c17ea1c4d822472e2f (patch) | |
tree | 306f60f6506b2e9714329a5c75b25bf0b2a94318 | |
parent | fed6a6f680b73585419dbd42658d89e398ad4d54 (diff) | |
download | acloud-05f0189a7cc0e730ad65f9c17ea1c4d822472e2f.tar.gz |
Add internal/lib/driver_test_lib.py to fix unit tests.
Add a script to run all unit tests.
Test: tools/acloud/run_tests.sh
-rw-r--r-- | .gitignore | 2 | ||||
-rwxr-xr-x | README.md | 5 | ||||
-rw-r--r-- | internal/lib/driver_test_lib.py | 50 | ||||
-rw-r--r-- | public/device_driver_test.py | 2 | ||||
-rwxr-xr-x | run_tests.sh | 12 |
5 files changed, 70 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..415166b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +*.*~ @@ -11,4 +11,9 @@ Devices on Google Compute Engine) instantiated by using the Android source code `$ pip install acloud.zip` #3. Execution: + `$ acloud <flags> + +To run all unit tests: + + `$ tools\acloud\run_tests.sh` diff --git a/internal/lib/driver_test_lib.py b/internal/lib/driver_test_lib.py new file mode 100644 index 00000000..4ca1bfc4 --- /dev/null +++ b/internal/lib/driver_test_lib.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# +# 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. + +"""Driver test library.""" + +import mock +import unittest + + +class BaseDriverTest(unittest.TestCase): + """Base class for driver tests.""" + + def setUp(self): + """Set up test.""" + self._patchers = [] + + def tearDown(self): + """Tear down test.""" + for patcher in reversed(self._patchers): + patcher.stop() + + def Patch(self, *args, **kwargs): + """A wrapper for mock.patch.object. + + This wrapper starts a patcher and store it in self._patchers, + so that we can later stop them in tearDown. + + Args: + *args: Arguments to pass to mock.patch. + **kwargs: Keyword arguments to pass to mock.patch. + + Returns: + Mock object + """ + patcher = mock.patch.object(*args, **kwargs) + self._patchers.append(patcher) + return patcher.start() diff --git a/public/device_driver_test.py b/public/device_driver_test.py index eb0a64f8..7b12f61d 100644 --- a/public/device_driver_test.py +++ b/public/device_driver_test.py @@ -24,7 +24,7 @@ import mock import unittest from acloud.internal.lib import auth -from acloud.internal.lib import andorid_build_client +from acloud.internal.lib import android_build_client from acloud.internal.lib import android_compute_client from acloud.internal.lib import driver_test_lib from acloud.internal.lib import gstorage_client diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 00000000..d9d6987d --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -z "$ANDROID_BUILD_TOP" ]; then + echo "Missing ANDROID_BUILD_TOP env variable. Run 'lunch' first." + exit 1 +fi + +# Runs all unit tests under tools/acloud. +tests=$(find . -type f | grep test\.py) +for t in $tests; do + PYTHONPATH=$ANDROID_BUILD_TOP/tools python $t; +done |