summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozversion/tests
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /testing/mozbase/mozversion/tests
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'testing/mozbase/mozversion/tests')
-rw-r--r--testing/mozbase/mozversion/tests/manifest.ini4
-rw-r--r--testing/mozbase/mozversion/tests/test_apk.py43
-rw-r--r--testing/mozbase/mozversion/tests/test_b2g.py75
-rw-r--r--testing/mozbase/mozversion/tests/test_binary.py177
-rw-r--r--testing/mozbase/mozversion/tests/test_sources.py85
5 files changed, 384 insertions, 0 deletions
diff --git a/testing/mozbase/mozversion/tests/manifest.ini b/testing/mozbase/mozversion/tests/manifest.ini
new file mode 100644
index 000000000..3c034ea78
--- /dev/null
+++ b/testing/mozbase/mozversion/tests/manifest.ini
@@ -0,0 +1,4 @@
+[test_binary.py]
+[test_sources.py]
+[test_b2g.py]
+[test_apk.py] \ No newline at end of file
diff --git a/testing/mozbase/mozversion/tests/test_apk.py b/testing/mozbase/mozversion/tests/test_apk.py
new file mode 100644
index 000000000..37fcb0bcf
--- /dev/null
+++ b/testing/mozbase/mozversion/tests/test_apk.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+
+# 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/.
+
+import mozfile
+import unittest
+import zipfile
+from mozversion import get_version
+
+
+class ApkTest(unittest.TestCase):
+ """test getting version information from an android .apk"""
+
+ application_changeset = 'a' * 40
+ platform_changeset = 'b' * 40
+
+ def create_apk_zipfiles(self, zfile):
+ zfile.writestr('application.ini',
+ """[App]\nSourceStamp=%s\n""" % self.application_changeset)
+ zfile.writestr('platform.ini',
+ """[Build]\nSourceStamp=%s\n""" % self.platform_changeset)
+ zfile.writestr('AndroidManifest.xml', '')
+
+ def test_basic(self):
+ with mozfile.NamedTemporaryFile() as f:
+ with zipfile.ZipFile(f.name, 'w') as z:
+ self.create_apk_zipfiles(z)
+ v = get_version(f.name)
+ self.assertEqual(v.get('application_changeset'), self.application_changeset)
+ self.assertEqual(v.get('platform_changeset'), self.platform_changeset)
+
+ def test_with_package_name(self):
+ with mozfile.NamedTemporaryFile() as f:
+ with zipfile.ZipFile(f.name, 'w') as z:
+ self.create_apk_zipfiles(z)
+ z.writestr('package-name.txt', "org.mozilla.fennec")
+ v = get_version(f.name)
+ self.assertEqual(v.get('package_name'), "org.mozilla.fennec")
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/testing/mozbase/mozversion/tests/test_b2g.py b/testing/mozbase/mozversion/tests/test_b2g.py
new file mode 100644
index 000000000..09e0eb09e
--- /dev/null
+++ b/testing/mozbase/mozversion/tests/test_b2g.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+# 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/.
+
+import os
+import tempfile
+import unittest
+import zipfile
+
+import mozfile
+from mozversion import get_version, errors
+
+
+class SourcesTest(unittest.TestCase):
+ """test getting version information from a sources xml"""
+
+ def setUp(self):
+ self.tempdir = tempfile.mkdtemp()
+
+ self.binary = os.path.join(self.tempdir, 'binary')
+ with open(self.binary, 'w') as f:
+ f.write('foobar')
+
+ with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
+ f.writelines("""[App]\nName = B2G\n""")
+
+ with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
+ f.write('[Build]\nBuildID = PlatformBuildID\n')
+
+ def tearDown(self):
+ mozfile.remove(self.tempdir)
+
+ def _create_zip(self, revision=None, date=None):
+ zip_path = os.path.join(
+ self.tempdir, 'gaia', 'profile', 'webapps',
+ 'settings.gaiamobile.org', 'application.zip')
+ os.makedirs(os.path.dirname(zip_path))
+ app_zip = zipfile.ZipFile(zip_path, 'w')
+ if revision or date:
+ app_zip.writestr('resources/gaia_commit.txt',
+ '%s\n%s' % (revision, date))
+ app_zip.close()
+
+ def test_gaia_commit(self):
+ revision, date = ('a' * 40, 'date')
+ self._create_zip(revision, date)
+ v = get_version(self.binary)
+ self.assertEqual(v.get('gaia_changeset'), revision)
+ self.assertEqual(v.get('gaia_date'), date)
+
+ def test_invalid_gaia_commit(self):
+ revision, date = ('a' * 41, 'date')
+ self._create_zip(revision, date)
+ v = get_version(self.binary)
+ self.assertIsNone(v.get('gaia_changeset'))
+ self.assertEqual(v.get('gaia_date'), date)
+
+ def test_missing_zip_file(self):
+ v = get_version(self.binary)
+ self.assertIsNone(v.get('gaia_changeset'))
+ self.assertIsNone(v.get('gaia_date'))
+
+ def test_missing_gaia_commit(self):
+ self._create_zip()
+ v = get_version(self.binary)
+ self.assertIsNone(v.get('gaia_changeset'))
+ self.assertIsNone(v.get('gaia_date'))
+
+ def test_b2g_fallback_when_no_binary(self):
+ self.assertRaises(errors.RemoteAppNotFoundError, get_version)
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/testing/mozbase/mozversion/tests/test_binary.py b/testing/mozbase/mozversion/tests/test_binary.py
new file mode 100644
index 000000000..54665974f
--- /dev/null
+++ b/testing/mozbase/mozversion/tests/test_binary.py
@@ -0,0 +1,177 @@
+#!/usr/bin/env python
+
+# 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/.
+
+import os
+import sys
+import tempfile
+import shutil
+import unittest
+
+import mozfile
+
+from mozversion import errors, get_version
+
+
+class BinaryTest(unittest.TestCase):
+ """test getting application version information from a binary path"""
+
+ application_ini = """[App]
+ID = AppID
+Name = AppName
+CodeName = AppCodeName
+Version = AppVersion
+BuildID = AppBuildID
+SourceRepository = AppSourceRepo
+SourceStamp = AppSourceStamp
+Vendor = AppVendor
+"""
+ platform_ini = """[Build]
+BuildID = PlatformBuildID
+Milestone = PlatformMilestone
+SourceStamp = PlatformSourceStamp
+SourceRepository = PlatformSourceRepo
+"""
+
+ def setUp(self):
+ self.cwd = os.getcwd()
+ self.tempdir = tempfile.mkdtemp()
+
+ self.binary = os.path.join(self.tempdir, 'binary')
+ with open(self.binary, 'w') as f:
+ f.write('foobar')
+
+ def tearDown(self):
+ 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):
+ self._write_ini_files()
+
+ self._check_version(get_version(self.binary))
+
+ @unittest.skipIf(not hasattr(os, 'symlink'),
+ 'os.symlink not supported on this platform')
+ def test_symlinked_binary(self):
+ self._write_ini_files()
+
+ # create a symlink of the binary in another directory and check
+ # version against this symlink
+ tempdir = tempfile.mkdtemp()
+ try:
+ browser_link = os.path.join(tempdir,
+ os.path.basename(self.binary))
+ os.symlink(self.binary, browser_link)
+
+ self._check_version(get_version(browser_link))
+ finally:
+ mozfile.remove(tempdir)
+
+ def test_binary_in_current_path(self):
+ self._write_ini_files()
+
+ os.chdir(self.tempdir)
+ self._check_version(get_version())
+
+ def test_with_ini_files_on_osx(self):
+ self._write_ini_files()
+
+ platform = sys.platform
+ sys.platform = 'darwin'
+ try:
+ # get_version is working with ini files next to the binary
+ self._check_version(get_version(binary=self.binary))
+
+ # or if they are in the Resources dir
+ # in this case the binary must be in a Contents dir, next
+ # to the Resources dir
+ contents_dir = os.path.join(self.tempdir, 'Contents')
+ os.mkdir(contents_dir)
+ moved_binary = os.path.join(contents_dir,
+ os.path.basename(self.binary))
+ shutil.move(self.binary, moved_binary)
+
+ resources_dir = os.path.join(self.tempdir, 'Resources')
+ os.mkdir(resources_dir)
+ for ini_file in ('application.ini', 'platform.ini'):
+ shutil.move(os.path.join(self.tempdir, ini_file), resources_dir)
+
+ self._check_version(get_version(binary=moved_binary))
+ finally:
+ sys.platform = platform
+
+ def test_invalid_binary_path(self):
+ self.assertRaises(IOError, get_version,
+ os.path.join(self.tempdir, 'invalid'))
+
+ 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_ini_file(self):
+ """With a missing platform.ini file an exception should be thrown"""
+ self._write_ini_files(platform=False)
+ self.assertRaises(errors.AppNotFoundError, get_version,
+ self.binary)
+
+ def test_without_application_ini_file(self):
+ """With a missing application.ini file an exception should be thrown"""
+ self._write_ini_files(application=False)
+ self.assertRaises(errors.AppNotFoundError, get_version,
+ self.binary)
+
+ def test_with_exe(self):
+ """Test that we can resolve .exe files"""
+ self._write_ini_files()
+
+ exe_name_unprefixed = self.binary + '1'
+ exe_name = exe_name_unprefixed + '.exe'
+ with open(exe_name, 'w') as f:
+ f.write('foobar')
+ self._check_version(get_version(exe_name_unprefixed))
+
+ def test_not_found_with_binary_specified(self):
+ self.assertRaises(errors.LocalAppNotFoundError, get_version, self.binary)
+
+ def _write_ini_files(self, application=True, platform=True):
+ if application:
+ with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
+ f.writelines(self.application_ini)
+ if platform:
+ with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
+ f.writelines(self.platform_ini)
+
+ def _check_version(self, version):
+ self.assertEqual(version.get('application_id'), 'AppID')
+ self.assertEqual(version.get('application_name'), 'AppName')
+ self.assertEqual(
+ version.get('application_display_name'), 'AppCodeName')
+ self.assertEqual(version.get('application_version'), 'AppVersion')
+ self.assertEqual(version.get('application_buildid'), 'AppBuildID')
+ self.assertEqual(
+ version.get('application_repository'), 'AppSourceRepo')
+ self.assertEqual(
+ version.get('application_changeset'), 'AppSourceStamp')
+ self.assertEqual(version.get('application_vendor'), 'AppVendor')
+ self.assertIsNone(version.get('platform_name'))
+ self.assertEqual(version.get('platform_buildid'), 'PlatformBuildID')
+ self.assertEqual(
+ version.get('platform_repository'), 'PlatformSourceRepo')
+ self.assertEqual(
+ version.get('platform_changeset'), 'PlatformSourceStamp')
+ self.assertIsNone(version.get('invalid_key'))
+ self.assertEqual(
+ version.get('platform_version'), 'PlatformMilestone')
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/testing/mozbase/mozversion/tests/test_sources.py b/testing/mozbase/mozversion/tests/test_sources.py
new file mode 100644
index 000000000..6c663edd6
--- /dev/null
+++ b/testing/mozbase/mozversion/tests/test_sources.py
@@ -0,0 +1,85 @@
+#!/usr/bin/env python
+
+# 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/.
+
+import os
+import tempfile
+import unittest
+
+import mozfile
+
+from mozversion import errors, get_version
+
+
+class SourcesTest(unittest.TestCase):
+ """test getting version information from a sources xml"""
+
+ application_ini = """[App]\nName = B2G\n"""
+ platform_ini = """[Build]
+BuildID = PlatformBuildID
+SourceStamp = PlatformSourceStamp
+SourceRepository = PlatformSourceRepo
+"""
+ sources_xml = """<?xml version="1.0" ?><manifest>
+ <project path="build" revision="build_revision" />
+ <project path="gaia" revision="gaia_revision" />
+ <project path="gecko" revision="gecko_revision" />
+</manifest>
+"""
+
+ def setUp(self):
+ self.cwd = os.getcwd()
+ self.tempdir = tempfile.mkdtemp()
+
+ self.binary = os.path.join(self.tempdir, 'binary')
+ with open(self.binary, 'w') as f:
+ f.write('foobar')
+
+ def tearDown(self):
+ os.chdir(self.cwd)
+ mozfile.remove(self.tempdir)
+
+ def _write_conf_files(self, sources=True):
+ with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
+ f.writelines(self.application_ini)
+ with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
+ f.writelines(self.platform_ini)
+ if sources:
+ with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f:
+ f.writelines(self.sources_xml)
+
+ def test_sources(self):
+ self._write_conf_files()
+
+ os.chdir(self.tempdir)
+ self._check_version(get_version(sources=os.path.join(self.tempdir,
+ 'sources.xml')))
+
+ def test_sources_in_current_directory(self):
+ self._write_conf_files()
+
+ os.chdir(self.tempdir)
+ self._check_version(get_version())
+
+ def test_invalid_sources_path(self):
+ """An invalid source path should cause an exception"""
+ self.assertRaises(errors.AppNotFoundError, get_version,
+ self.binary, os.path.join(self.tempdir, 'invalid'))
+
+ def test_without_sources_file(self):
+ """With a missing sources file no exception should be thrown"""
+ self._write_conf_files(sources=False)
+
+ get_version(self.binary)
+
+ def _check_version(self, version):
+ self.assertEqual(version.get('build_changeset'), 'build_revision')
+ self.assertEqual(version.get('gaia_changeset'), 'gaia_revision')
+ self.assertEqual(version.get('gecko_changeset'), 'gecko_revision')
+ self.assertIsNone(version.get('invalid_key'))
+
+
+if __name__ == '__main__':
+ unittest.main()