devtools/qunit.py
changeset 10886 941e3d15c338
parent 10885 b3a192804b63
child 10934 3f18ec9d96dd
equal deleted inserted replaced
10885:b3a192804b63 10886:941e3d15c338
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 
    18 
    19 import os, os.path as osp
    19 import os, os.path as osp
       
    20 import errno
    20 from tempfile import mkdtemp
    21 from tempfile import mkdtemp
    21 from subprocess import Popen
    22 from subprocess import Popen, PIPE, STDOUT
    22 
    23 
    23 from six.moves.queue import Queue, Empty
    24 from six.moves.queue import Queue, Empty
    24 
    25 
    25 # imported by default to simplify further import statements
    26 # imported by default to simplify further import statements
    26 from logilab.common.testlib import unittest_main, with_tempdir, InnerTest, Tags
    27 from logilab.common.testlib import unittest_main, with_tempdir, InnerTest, Tags
    39         self._profile_dir = mkdtemp(prefix='cwtest-ffxprof-')
    40         self._profile_dir = mkdtemp(prefix='cwtest-ffxprof-')
    40         self.firefox_cmd = ['firefox', '-no-remote']
    41         self.firefox_cmd = ['firefox', '-no-remote']
    41         if os.name == 'posix':
    42         if os.name == 'posix':
    42             self.firefox_cmd = [osp.join(osp.dirname(__file__), 'data', 'xvfb-run.sh'),
    43             self.firefox_cmd = [osp.join(osp.dirname(__file__), 'data', 'xvfb-run.sh'),
    43                                 '-a', '-s', '-noreset -screen 0 800x600x24'] + self.firefox_cmd
    44                                 '-a', '-s', '-noreset -screen 0 800x600x24'] + self.firefox_cmd
       
    45 
       
    46     def test(self):
       
    47         try:
       
    48             proc = Popen(['firefox', '--help'], stdout=PIPE, stderr=STDOUT)
       
    49             stdout, _ = proc.communicate()
       
    50             return proc.returncode == 0, stdout
       
    51         except OSError as exc:
       
    52             if exc.errno == errno.ENOENT:
       
    53                 msg = '[%s] %s' % (errno.errorcode[exc.errno], exc.strerror)
       
    54                 return False, msg
       
    55             raise
    44 
    56 
    45     def start(self, url):
    57     def start(self, url):
    46         self.stop()
    58         self.stop()
    47         cmd = self.firefox_cmd + ['-silent', '--profile', self._profile_dir,
    59         cmd = self.firefox_cmd + ['-silent', '--profile', self._profile_dir,
    48                                   '-url', url]
    60                                   '-url', url]
   114 
   126 
   115         while not self.test_queue.empty():
   127         while not self.test_queue.empty():
   116             self.test_queue.get(False)
   128             self.test_queue.get(False)
   117 
   129 
   118         browser = FirefoxHelper()
   130         browser = FirefoxHelper()
       
   131         isavailable, reason = browser.test()
       
   132         if not isavailable:
       
   133             self.fail('firefox not available or not working properly (%s)' % reason)
   119         browser.start(self.config['base-url'] + "?vid=qunit")
   134         browser.start(self.config['base-url'] + "?vid=qunit")
   120         test_count = 0
   135         test_count = 0
   121         error = False
   136         error = False
   122         def raise_exception(cls, *data):
   137         def raise_exception(cls, *data):
   123             raise cls(*data)
   138             raise cls(*data)