Bug 1064731 - [mozversion] Add unit test to cover the case when binary is a symlink. r=dhunt
authorJulien Pagès <j.parkouss@gmail.com>
Tue, 14 Oct 2014 04:00:00 -0400
changeset 210351 1ac8890ee0a354c51824bc0597ea00c5b72110dc
parent 210350 8754d79ca14c1b58d13408533637066b3ddce47b
child 210352 fa03ad915ea5ebf0241e8a99a48d070664801427
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersdhunt
bugs1064731
milestone36.0a1
Bug 1064731 - [mozversion] Add unit test to cover the case when binary is a symlink. r=dhunt
testing/mozbase/mozversion/tests/test_binary.py
--- a/testing/mozbase/mozversion/tests/test_binary.py
+++ b/testing/mozbase/mozversion/tests/test_binary.py
@@ -44,64 +44,77 @@ SourceRepository = PlatformSourceRepo
 
     @unittest.skipIf(not os.environ.get('BROWSER_PATH'),
                      'No binary has been specified.')
     def test_real_binary(self):
         v = get_version(os.environ.get('BROWSER_PATH'))
         self.assertTrue(isinstance(v, dict))
 
     def test_binary(self):
-        with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
-            f.writelines(self.application_ini)
-
-        with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
-            f.writelines(self.platform_ini)
+        self._write_ini_files()
 
         self._check_version(get_version(self.binary))
 
+    @unittest.skipIf(not hasattr(os, 'symlink'),
+                     'os.symlink not supported on this platform')
+    def test_symlinked_binary(self):
+        self._write_ini_files()
+
+        # create a symlink of the binary in another directory and check
+        # version against this symlink
+        tempdir = tempfile.mkdtemp()
+        try:
+            browser_link = os.path.join(tempdir,
+                                        os.path.basename(self.binary))
+            os.symlink(self.binary, browser_link)
+
+            self._check_version(get_version(browser_link))
+        finally:
+            mozfile.remove(tempdir)
+
     def test_binary_in_current_path(self):
-        with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
-            f.writelines(self.application_ini)
+        self._write_ini_files()
 
-        with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
-            f.writelines(self.platform_ini)
         os.chdir(self.tempdir)
         self._check_version(get_version())
 
     def test_invalid_binary_path(self):
         self.assertRaises(IOError, get_version,
                           os.path.join(self.tempdir, 'invalid'))
 
     def test_without_ini_files(self):
         """With missing ini files an exception should be thrown"""
         self.assertRaises(errors.AppNotFoundError, get_version,
                           self.binary)
 
     def test_without_platform_file(self):
         """With a missing platform file no exception should be thrown"""
-        with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
-            f.writelines(self.application_ini)
+        self._write_ini_files(platform=False)
 
         v = get_version(self.binary)
         self.assertTrue(isinstance(v, dict))
 
     def test_with_exe(self):
         """Test that we can resolve .exe files"""
-        with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
-            f.writelines(self.application_ini)
-
-        with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
-            f.writelines(self.platform_ini)
+        self._write_ini_files()
 
         exe_name_unprefixed = self.binary + '1'
         exe_name = exe_name_unprefixed + '.exe'
         with open(exe_name, 'w') as f:
             f.write('foobar')
         self._check_version(get_version(exe_name_unprefixed))
 
+    def _write_ini_files(self, application=True, platform=True):
+        if application:
+            with open(os.path.join(self.tempdir, 'application.ini'), 'w') as f:
+                f.writelines(self.application_ini)
+        if platform:
+            with open(os.path.join(self.tempdir, 'platform.ini'), 'w') as f:
+                f.writelines(self.platform_ini)
+
     def _check_version(self, version):
         self.assertEqual(version.get('application_name'), 'AppName')
         self.assertEqual(version.get('application_display_name'), 'AppCodeName')
         self.assertEqual(version.get('application_version'), 'AppVersion')
         self.assertEqual(version.get('application_buildid'), 'AppBuildID')
         self.assertEqual(
             version.get('application_repository'), 'AppSourceRepo')
         self.assertEqual(