summaryrefslogtreecommitdiffstats
path: root/testrunner
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2009-10-21 11:16:42 -0700
committerBrett Chabot <brettchabot@android.com>2009-10-21 11:19:12 -0700
commit34fb7f6b0c1e8375f168e5a9d4e5c7a93d4ecd7f (patch)
treefb8b1848e771c27d1298e2f6f4ea3c7ee4415871 /testrunner
parentec59a8834bbca256495045a6687a672f66b52df0 (diff)
downloadandroid_development-34fb7f6b0c1e8375f168e5a9d4e5c7a93d4ecd7f.tar.gz
android_development-34fb7f6b0c1e8375f168e5a9d4e5c7a93d4ecd7f.tar.bz2
android_development-34fb7f6b0c1e8375f168e5a9d4e5c7a93d4ecd7f.zip
Add ability to retrieve instrumentations from android_manifest parser.
Also add a simple unit test for the parser.
Diffstat (limited to 'testrunner')
-rw-r--r--testrunner/android_manifest.py18
-rw-r--r--testrunner/tests/AndroidManifest.xml30
-rwxr-xr-xtestrunner/tests/android_manifest_tests.py42
3 files changed, 90 insertions, 0 deletions
diff --git a/testrunner/android_manifest.py b/testrunner/android_manifest.py
index 5406f56ee..5825118f1 100644
--- a/testrunner/android_manifest.py
+++ b/testrunner/android_manifest.py
@@ -36,6 +36,10 @@ class AndroidManifest(object):
if app_path:
self.ParseManifest(app_path)
+ def GetAppPath(self):
+ """Retrieve file system path to this manifest file's directory."""
+ return self._app_path
+
def GetPackageName(self):
"""Retrieve package name defined at <manifest package="...">.
@@ -56,6 +60,7 @@ class AndroidManifest(object):
IOError: AndroidManifest.xml cannot be found at given path, or cannot be
opened for reading
"""
+ self._app_path = app_path
self._manifest_path = os.path.join(app_path, self.FILENAME)
self._dom = xml.dom.minidom.parse(self._manifest_path)
@@ -76,6 +81,18 @@ class AndroidManifest(object):
uses_sdk_element.setAttribute('android:minSdkVersion', min_sdk_version)
self._SaveXml()
+ def GetInstrumentationNames(self):
+ """Get the instrumentation names from manifest.
+
+ Returns:
+ list of names, might be empty
+ """
+ instr_elements = self._dom.getElementsByTagName('instrumentation')
+ instrs = []
+ for element in instr_elements:
+ instrs.append(element.getAttribute('android:name'))
+ return instrs
+
def _GetManifestElement(self):
"""Retrieve the root manifest element.
@@ -90,3 +107,4 @@ class AndroidManifest(object):
def _SaveXml(self):
"""Saves the manifest to disk."""
self._dom.writexml(open(self._manifest_path, mode='w'), encoding='utf-8')
+
diff --git a/testrunner/tests/AndroidManifest.xml b/testrunner/tests/AndroidManifest.xml
new file mode 100644
index 000000000..e867f730f
--- /dev/null
+++ b/testrunner/tests/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<!-- Sample manifest file used for unit testing -->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.example.android.tests">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.example.android"
+ android:label="Tests"/>
+
+</manifest>
diff --git a/testrunner/tests/android_manifest_tests.py b/testrunner/tests/android_manifest_tests.py
new file mode 100755
index 000000000..2817726c4
--- /dev/null
+++ b/testrunner/tests/android_manifest_tests.py
@@ -0,0 +1,42 @@
+#!/usr/bin/python2.4
+#
+#
+# Copyright 2009, 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 sys
+import unittest
+sys.path.append('../..')
+
+from testrunner import android_manifest
+
+
+class AndroidManifestTest(unittest.TestCase):
+ """Unit tests for AndroidManifest."""
+
+ def setUp(self):
+ """Create android_mainfest for testing from sample file."""
+ self._manifest = android_manifest.AndroidManifest(app_path='.')
+
+ def testGetPackageName(self):
+ self.assertEquals('com.example.android.tests',
+ self._manifest.GetPackageName())
+
+ def testGetInstrumentationNames(self):
+ self.assertEquals(['android.test.InstrumentationTestRunner'],
+ self._manifest.GetInstrumentationNames())
+
+
+if __name__ == '__main__':
+ unittest.main()