DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d1ed7de67f5a)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
#!/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


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""")

    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'))


if __name__ == '__main__':
    unittest.main()