testing/mozbase/mozversion/tests/test_binary.py

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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 BinaryTest(unittest.TestCase):
    16     """test getting application version information from a binary path"""
    18     application_ini = """[App]
    19 Name = AppName
    20 CodeName = AppCodeName
    21 Version = AppVersion
    22 BuildID = AppBuildID
    23 SourceRepository = AppSourceRepo
    24 SourceStamp = AppSourceStamp
    25 """
    26     platform_ini = """[Build]
    27 BuildID = PlatformBuildID
    28 SourceStamp = PlatformSourceStamp
    29 SourceRepository = PlatformSourceRepo
    30 """
    32     def setUp(self):
    33         self.cwd = os.getcwd()
    34         self.tempdir = tempfile.mkdtemp()
    36         self.binary = os.path.join(self.tempdir, 'binary')
    37         with open(self.binary, 'w') as f:
    38             f.write('foobar')
    40     def tearDown(self):
    41         os.chdir(self.cwd)
    42         mozfile.remove(self.tempdir)
    44     def test_binary(self):
    45         with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
    46             f.writelines(self.application_ini)
    48         with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
    49             f.writelines(self.platform_ini)
    51         self._check_version(get_version(self.binary))
    53     def test_binary_in_current_path(self):
    54         with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
    55             f.writelines(self.application_ini)
    57         with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
    58             f.writelines(self.platform_ini)
    59         os.chdir(self.tempdir)
    60         self._check_version(get_version())
    62     def test_invalid_binary_path(self):
    63         self.assertRaises(IOError, get_version,
    64                           os.path.join(self.tempdir, 'invalid'))
    66     def test_missing_ini_files(self):
    67         v = get_version(self.binary)
    68         self.assertEqual(v, {})
    70     def _check_version(self, version):
    71         self.assertEqual(version.get('application_name'), 'AppName')
    72         self.assertEqual(version.get('application_display_name'), 'AppCodeName')
    73         self.assertEqual(version.get('application_version'), 'AppVersion')
    74         self.assertEqual(version.get('application_buildid'), 'AppBuildID')
    75         self.assertEqual(
    76             version.get('application_repository'), 'AppSourceRepo')
    77         self.assertEqual(
    78             version.get('application_changeset'), 'AppSourceStamp')
    79         self.assertIsNone(version.get('platform_name'))
    80         self.assertIsNone(version.get('platform_version'))
    81         self.assertEqual(version.get('platform_buildid'), 'PlatformBuildID')
    82         self.assertEqual(
    83             version.get('platform_repository'), 'PlatformSourceRepo')
    84         self.assertEqual(
    85             version.get('platform_changeset'), 'PlatformSourceStamp')
    86         self.assertIsNone(version.get('invalid_key'))
    89 if __name__ == '__main__':
    90     unittest.main()

mercurial