Merge change I12f05ef0 into eclair

* changes:
  Add ability to retrieve instrumentations from android_manifest parser.
This commit is contained in:
Android (Google) Code Review
2009-10-21 17:26:32 -04:00
3 changed files with 90 additions and 0 deletions

View File

@@ -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')

View File

@@ -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>

View File

@@ -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()