testing/mozbase/mozinstall/tests/test.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 mozinfo
     8 import mozinstall
     9 import mozfile
    10 import os
    11 import tarfile
    12 import tempfile
    13 import unittest
    14 import zipfile
    16 # Store file location at load time
    17 here = os.path.dirname(os.path.abspath(__file__))
    19 class TestMozInstall(unittest.TestCase):
    21     @classmethod
    22     def setUpClass(cls):
    23         """ Setting up stub installers """
    24         cls.dmg = os.path.join(here, 'Installer-Stubs', 'firefox.dmg')
    25         cls.exe = os.path.join(here, 'Installer-Stubs', 'firefox.exe')
    26         cls.zipfile = os.path.join(here, 'Installer-Stubs', 'firefox.zip')
    27         cls.bz2 = os.path.join(here, 'Installer-Stubs', 'firefox.tar.bz2')
    29     def setUp(self):
    30         self.tempdir = tempfile.mkdtemp()
    32     def tearDown(self):
    33         mozfile.rmtree(self.tempdir)
    35     def test_get_binary(self):
    36         """ Test mozinstall's get_binary method """
    38         if mozinfo.isLinux:
    39             installdir = mozinstall.install(self.bz2, self.tempdir)
    40             binary = os.path.join(installdir, 'firefox')
    41             self.assertEqual(binary, mozinstall.get_binary(installdir, 'firefox'))
    43         elif mozinfo.isWin:
    44             installdir_exe = mozinstall.install(self.exe,
    45                                                 os.path.join(self.tempdir, 'exe'))
    46             binary_exe = os.path.join(installdir_exe, 'firefox', 'firefox',
    47                                       'firefox.exe')
    48             self.assertEqual(binary_exe, mozinstall.get_binary(installdir_exe,
    49                              'firefox'))
    51             installdir_zip = mozinstall.install(self.zipfile,
    52                                                 os.path.join(self.tempdir, 'zip'))
    53             binary_zip = os.path.join(installdir_zip, 'firefox.exe')
    54             self.assertEqual(binary_zip, mozinstall.get_binary(installdir_zip,
    55                              'firefox'))
    57         elif mozinfo.isMac:
    58             installdir = mozinstall.install(self.dmg, self.tempdir)
    59             binary = os.path.join(installdir, 'Contents', 'MacOS', 'firefox')
    60             self.assertEqual(binary, mozinstall.get_binary(installdir, 'firefox'))
    62     def test_get_binary_error(self):
    63         """ Test an InvalidBinary error is raised """
    65         tempdir_empty = tempfile.mkdtemp()
    66         self.assertRaises(mozinstall.InvalidBinary, mozinstall.get_binary,
    67                           tempdir_empty, 'firefox')
    68         mozfile.rmtree(tempdir_empty)
    70     def test_is_installer(self):
    71         """ Test we can identify a correct installer """
    73         if mozinfo.isLinux:
    74             self.assertTrue(mozinstall.is_installer(self.bz2))
    76         if mozinfo.isWin:
    77             # test zip installer
    78             self.assertTrue(mozinstall.is_installer(self.zipfile))
    80             # test exe installer
    81             self.assertTrue(mozinstall.is_installer(self.exe))
    83             try:
    84                 # test stub browser file
    85                 # without pefile on the system this test will fail
    86                 import pefile
    87                 stub_exe = os.path.join(here, 'build_stub', 'firefox.exe')
    88                 self.assertFalse(mozinstall.is_installer(stub_exe))
    89             except ImportError:
    90                 pass
    92         if mozinfo.isMac:
    93             self.assertTrue(mozinstall.is_installer(self.dmg))
    95     def test_invalid_source_error(self):
    96         """ Test InvalidSource error is raised with an incorrect installer """
    98         if mozinfo.isLinux:
    99             self.assertRaises(mozinstall.InvalidSource, mozinstall.install,
   100                               self.dmg, 'firefox')
   102         elif mozinfo.isWin:
   103             self.assertRaises(mozinstall.InvalidSource, mozinstall.install,
   104                               self.bz2, 'firefox')
   106         elif mozinfo.isMac:
   107             self.assertRaises(mozinstall.InvalidSource, mozinstall.install,
   108                               self.exe, 'firefox')
   110     def test_install(self):
   111         """ Test mozinstall's install capability """
   113         if mozinfo.isLinux:
   114             installdir = mozinstall.install(self.bz2, self.tempdir)
   115             self.assertEqual(os.path.join(self.tempdir, 'firefox'), installdir)
   117         elif mozinfo.isWin:
   118             installdir_exe = mozinstall.install(self.exe,
   119                                                 os.path.join(self.tempdir, 'exe'))
   120             self.assertEqual(os.path.join(self.tempdir, 'exe', 'firefox'),
   121                              installdir_exe)
   123             installdir_zip = mozinstall.install(self.zipfile,
   124                                                 os.path.join(self.tempdir, 'zip'))
   125             self.assertEqual(os.path.join(self.tempdir, 'zip', 'firefox'),
   126                              installdir_zip)
   128         elif mozinfo.isMac:
   129             installdir = mozinstall.install(self.dmg, self.tempdir)
   130             self.assertEqual(os.path.join(os.path.realpath(self.tempdir),
   131                                           'FirefoxStub.app'), installdir)
   133     def test_uninstall(self):
   134         """ Test mozinstall's uninstall capabilites """
   135         # Uninstall after installing
   137         if mozinfo.isLinux:
   138             installdir = mozinstall.install(self.bz2, self.tempdir)
   139             mozinstall.uninstall(installdir)
   140             self.assertFalse(os.path.exists(installdir))
   142         elif mozinfo.isWin:
   143             # Exe installer for Windows
   144             installdir_exe = mozinstall.install(self.exe,
   145                                                 os.path.join(self.tempdir, 'exe'))
   146             mozinstall.uninstall(installdir_exe)
   147             self.assertFalse(os.path.exists(installdir_exe))
   149             # Zip installer for Windows
   150             installdir_zip = mozinstall.install(self.zipfile,
   151                                                 os.path.join(self.tempdir, 'zip'))
   152             mozinstall.uninstall(installdir_zip)
   153             self.assertFalse(os.path.exists(installdir_zip))
   155         elif mozinfo.isMac:
   156             installdir = mozinstall.install(self.dmg, self.tempdir)
   157             mozinstall.uninstall(installdir)
   158             self.assertFalse(os.path.exists(installdir))
   160 if __name__ == '__main__':
   161     unittest.main()

mercurial