testing/mozbase/mozversion/tests/test_b2g.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 5 # You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6
michael@0 7 import os
michael@0 8 import tempfile
michael@0 9 import unittest
michael@0 10 import zipfile
michael@0 11
michael@0 12 import mozfile
michael@0 13 from mozversion import get_version
michael@0 14
michael@0 15
michael@0 16 class SourcesTest(unittest.TestCase):
michael@0 17 """test getting version information from a sources xml"""
michael@0 18
michael@0 19 def setUp(self):
michael@0 20 self.tempdir = tempfile.mkdtemp()
michael@0 21
michael@0 22 self.binary = os.path.join(self.tempdir, 'binary')
michael@0 23 with open(self.binary, 'w') as f:
michael@0 24 f.write('foobar')
michael@0 25
michael@0 26 with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
michael@0 27 f.writelines("""[App]\nName = B2G\n""")
michael@0 28
michael@0 29 def tearDown(self):
michael@0 30 mozfile.remove(self.tempdir)
michael@0 31
michael@0 32 def _create_zip(self, revision, date='date'):
michael@0 33 zip_path = os.path.join(
michael@0 34 self.tempdir, 'gaia', 'profile', 'webapps',
michael@0 35 'settings.gaiamobile.org', 'application.zip')
michael@0 36 os.makedirs(os.path.dirname(zip_path))
michael@0 37 app_zip = zipfile.ZipFile(zip_path, 'w')
michael@0 38 app_zip.writestr('resources/gaia_commit.txt', revision + '\n' + date)
michael@0 39 app_zip.close()
michael@0 40
michael@0 41 def test_gaia_commit(self):
michael@0 42 self._create_zip('a' * 40, 'date')
michael@0 43 v = get_version(self.binary)
michael@0 44 self.assertEqual(v.get('gaia_changeset'), 'a' * 40)
michael@0 45 self.assertEqual(v.get('gaia_date'), 'date')
michael@0 46
michael@0 47 def test_invalid_gaia_commit(self):
michael@0 48 self._create_zip('a' * 41)
michael@0 49 v = get_version(self.binary)
michael@0 50 self.assertIsNone(v.get('gaia_changeset'))
michael@0 51
michael@0 52 def test_missing_gaia_commit(self):
michael@0 53 v = get_version(self.binary)
michael@0 54 self.assertIsNone(v.get('gaia_changeset'))
michael@0 55 self.assertIsNone(v.get('gaia_date'))
michael@0 56
michael@0 57
michael@0 58 if __name__ == '__main__':
michael@0 59 unittest.main()

mercurial