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

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

mercurial