Bug 1061809 - [mozversion] Update retrieval of application information due to upcoming Mac signing changes. r=dhunt

---
 testing/mozbase/mozversion/mozversion/__init__.py  |  3 +-
 testing/mozbase/mozversion/mozversion/errors.py    | 26 ++++++++++
 .../mozbase/mozversion/mozversion/mozversion.py    | 58 ++++++++++++----------
 testing/mozbase/mozversion/tests/test_binary.py    | 22 ++++++--
 testing/mozbase/mozversion/tests/test_sources.py   | 17 ++++---
 5 files changed, 90 insertions(+), 36 deletions(-)
 create mode 100644 testing/mozbase/mozversion/mozversion/errors.py
This commit is contained in:
Henrik Skupin 2014-09-11 17:23:05 +02:00
Родитель 34032eed5e
Коммит d41b38b4b3
5 изменённых файлов: 90 добавлений и 36 удалений

Просмотреть файл

@ -2,4 +2,5 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from mozversion import cli, get_version
from .errors import *
from .mozversion import cli, get_version

Просмотреть файл

@ -0,0 +1,26 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
class VersionError(Exception):
def __init__(self, message):
Exception.__init__(self, message)
class AppNotFoundError(VersionError):
"""Exception for the application not found"""
def __init__(self, message):
VersionError.__init__(self, message)
class LocalAppNotFoundError(AppNotFoundError):
"""Exception for local application not found"""
def __init__(self, path):
AppNotFoundError.__init__(self, 'Application not found at: %s' % path)
class RemoteAppNotFoundError(AppNotFoundError):
"""Exception for remote application not found"""
def __init__(self, message):
AppNotFoundError.__init__(self, message)

Просмотреть файл

@ -16,19 +16,7 @@ import mozdevice
import mozlog
import mozfile
class VersionError(Exception):
def __init__(self, message):
Exception.__init__(self, message)
class LocalAppNotFoundError(VersionError):
"""Exception for local application not found"""
def __init__(self):
VersionError.__init__(
self, 'No binary path or application.ini found in working '
'directory. Specify a binary path or run from the directory '
'containing the binary.')
import errors
INI_DATA_MAPPING = (('application', 'App'), ('platform', 'Build'))
@ -87,16 +75,27 @@ class LocalVersion(Version):
Version.__init__(self, **kwargs)
path = None
def find_location(path):
if os.path.exists(os.path.join(path, 'application.ini')):
return path
if sys.platform == 'darwin':
path = os.path.join(os.path.dirname(path), 'Resources')
if os.path.exists(os.path.join(path, 'application.ini')):
return path
else:
return None
if binary:
if not os.path.exists(binary):
raise IOError('Binary path does not exist: %s' % binary)
path = os.path.dirname(binary)
path = find_location(os.path.dirname(os.path.realpath(binary)))
else:
if os.path.exists(os.path.join(os.getcwd(), 'application.ini')):
path = os.getcwd()
path = find_location(os.getcwd())
if not path:
raise LocalAppNotFoundError()
raise errors.LocalAppNotFoundError(path)
self.get_gecko_info(path)
@ -110,7 +109,7 @@ class B2GVersion(Version):
os.path.exists(os.path.join(os.getcwd(), 'sources.xml')) and \
os.path.join(os.getcwd(), 'sources.xml')
if sources:
if sources and os.path.exists(sources):
sources_xml = xml.dom.minidom.parse(sources)
for element in sources_xml.getElementsByTagName('project'):
path = element.getAttribute('path')
@ -182,10 +181,11 @@ class RemoteB2GVersion(B2GVersion):
dm = mozdevice.DeviceManagerADB(deviceSerial=device_serial)
elif dm_type == 'sut':
if not host:
raise Exception('A host for SUT must be supplied.')
raise errors.RemoteAppNotFoundError('A host for SUT must be supplied.')
dm = mozdevice.DeviceManagerSUT(host=host)
else:
raise Exception('Unknown device manager type: %s' % dm_type)
raise errors.RemoteAppNotFoundError('Unknown device manager type: %s' %
dm_type)
if not sources:
path = 'system/sources.xml'
@ -224,7 +224,7 @@ class RemoteB2GVersion(B2GVersion):
if key in desired_props.keys():
self._info[desired_props[key]] = value
if self._info['device_id'].lower() == 'flame':
if self._info.get('device_id', '').lower() == 'flame':
self._info['device_firmware_version_base'] = dm._runCmd(
['shell', 'getprop', 't2m.sw.version']).output[0]
@ -253,9 +253,13 @@ def get_version(binary=None, sources=None, dm_type=None, host=None,
version = LocalVersion(binary)
if version._info.get('application_name') == 'B2G':
version = LocalB2GVersion(binary, sources=sources)
except LocalAppNotFoundError:
version = RemoteB2GVersion(sources=sources, dm_type=dm_type, host=host,
device_serial=device_serial)
except errors.LocalAppNotFoundError:
try:
version = RemoteB2GVersion(sources=sources, dm_type=dm_type,
host=host, device_serial=device_serial)
except errors.RemoteAppNotFoundError:
raise errors.AppNotFoundError('No application found')
return version._info
@ -275,8 +279,10 @@ def cli(args=sys.argv[1:]):
dm_type = os.environ.get('DM_TRANS', 'adb')
host = os.environ.get('TEST_DEVICE')
version = get_version(binary=options.binary, sources=options.sources,
dm_type=dm_type, host=host,
version = get_version(binary=options.binary,
sources=options.sources,
dm_type=dm_type,
host=host,
device_serial=options.device)
for (key, value) in sorted(version.items()):
if value:

Просмотреть файл

@ -9,7 +9,8 @@ import tempfile
import unittest
import mozfile
from mozversion import get_version
from mozversion import errors, get_version
class BinaryTest(unittest.TestCase):
@ -41,6 +42,12 @@ SourceRepository = PlatformSourceRepo
os.chdir(self.cwd)
mozfile.remove(self.tempdir)
@unittest.skipIf(not os.environ.get('BROWSER_PATH'),
'No binary has been specified.')
def test_real_binary(self):
v = get_version(os.environ.get('BROWSER_PATH'))
self.assertTrue(isinstance(v, dict))
def test_binary(self):
with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines(self.application_ini)
@ -63,9 +70,18 @@ SourceRepository = PlatformSourceRepo
self.assertRaises(IOError, get_version,
os.path.join(self.tempdir, 'invalid'))
def test_missing_ini_files(self):
def test_without_ini_files(self):
"""With missing ini files an exception should be thrown"""
self.assertRaises(errors.AppNotFoundError, get_version,
self.binary)
def test_without_platform_file(self):
"""With a missing platform file no exception should be thrown"""
with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines(self.application_ini)
v = get_version(self.binary)
self.assertEqual(v, {})
self.assertTrue(isinstance(v, dict))
def _check_version(self, version):
self.assertEqual(version.get('application_name'), 'AppName')

Просмотреть файл

@ -9,7 +9,8 @@ import tempfile
import unittest
import mozfile
from mozversion import get_version
from mozversion import errors, get_version
class SourcesTest(unittest.TestCase):
@ -57,12 +58,16 @@ class SourcesTest(unittest.TestCase):
self._check_version(get_version())
def test_invalid_sources_path(self):
v = get_version(self.binary, os.path.join(self.tempdir, 'invalid'))
self.assertEqual(v, {})
"""An invalid source path should cause an exception"""
self.assertRaises(errors.AppNotFoundError, get_version,
self.binary, os.path.join(self.tempdir, 'invalid'))
def test_missing_sources_file(self):
v = get_version(self.binary)
self.assertEqual(v, {})
def test_without_sources_file(self):
"""With a missing sources file no exception should be thrown"""
with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
f.writelines(self.application_ini)
get_version(self.binary)
def _check_version(self, version):
self.assertEqual(version.get('build_changeset'), 'build_revision')