summaryrefslogtreecommitdiffstats
path: root/testing/mozbase/mozversion/tests/test_sources.py
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/test_sources.py
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/test_sources.py')
-rw-r--r--testing/mozbase/mozversion/tests/test_sources.py85
1 files changed, 85 insertions, 0 deletions
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()