testing/mozbase/mozversion/tests/test_sources.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
    11 import mozfile
    12 from mozversion import get_version
    15 class SourcesTest(unittest.TestCase):
    16     """test getting version information from a sources xml"""
    18     application_ini = """[App]\nName = B2G\n"""
    19     sources_xml = """<?xml version="1.0" ?><manifest>
    20   <project path="build" revision="build_revision" />
    21   <project path="gaia" revision="gaia_revision" />
    22   <project path="gecko" revision="gecko_revision" />
    23 </manifest>
    24 """
    26     def setUp(self):
    27         self.cwd = os.getcwd()
    28         self.tempdir = tempfile.mkdtemp()
    30         self.binary = os.path.join(self.tempdir, 'binary')
    31         with open(self.binary, 'w') as f:
    32             f.write('foobar')
    34     def tearDown(self):
    35         os.chdir(self.cwd)
    36         mozfile.remove(self.tempdir)
    38     def test_sources(self):
    39         with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
    40             f.writelines(self.application_ini)
    42         sources = os.path.join(self.tempdir, 'sources.xml')
    43         with open(sources, 'w') as f:
    44             f.writelines(self.sources_xml)
    46         os.chdir(self.tempdir)
    47         self._check_version(get_version(sources=sources))
    49     def test_sources_in_current_directory(self):
    50         with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
    51             f.writelines(self.application_ini)
    53         with open(os.path.join(self.tempdir, 'sources.xml'), 'w') as f:
    54             f.writelines(self.sources_xml)
    56         os.chdir(self.tempdir)
    57         self._check_version(get_version())
    59     def test_invalid_sources_path(self):
    60         v = get_version(self.binary, os.path.join(self.tempdir, 'invalid'))
    61         self.assertEqual(v, {})
    63     def test_missing_sources_file(self):
    64         v = get_version(self.binary)
    65         self.assertEqual(v, {})
    67     def _check_version(self, version):
    68         self.assertEqual(version.get('build_changeset'), 'build_revision')
    69         self.assertEqual(version.get('gaia_changeset'), 'gaia_revision')
    70         self.assertEqual(version.get('gecko_changeset'), 'gecko_revision')
    71         self.assertIsNone(version.get('invalid_key'))
    74 if __name__ == '__main__':
    75     unittest.main()

mercurial