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.

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

mercurial