<s> import os <EOL> import time <EOL> import tempfile <EOL> import subprocess <EOL> from flexx . util import icon <EOL> from flexx . util . testing import run_tests_if_main , raises , skipif <EOL> from flexx . webruntime . common import BaseRuntime <EOL> from flexx . webruntime import launch <EOL> from flexx import webruntime <EOL> URL = None <EOL> HTML = """<STR_LIT>""" <EOL> def setup_module ( ) : <EOL> global URL , FILE <EOL> fname = os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> with open ( fname , '<STR_LIT:wb>' ) as f : <EOL> f . write ( HTML . encode ( ) ) <EOL> URL = '<STR_LIT>' + fname <EOL> def has_qt ( ) : <EOL> try : <EOL> from PyQt4 import QtWebKit <EOL> except ImportError : <EOL> try : <EOL> from PySide import QtWebKit <EOL> except ImportError : <EOL> return False <EOL> return True <EOL> def has_nw ( ) : <EOL> exe = webruntime . nodewebkit . get_nodewebkit_exe or '<STR_LIT>' <EOL> try : <EOL> subprocess . check_call ( [ exe , '<STR_LIT>' ] , shell = True ) <EOL> except Exception : <EOL> return False <EOL> return True <EOL> def has_chrome ( ) : <EOL> return ( webruntime . chromeapp . get_chrome_exe ( ) or <EOL> webruntime . chromeapp . get_chromium_exe ( ) ) <EOL> def test_iconize ( ) : <EOL> icn = webruntime . common . iconize ( None ) <EOL> assert isinstance ( icn , icon . Icon ) <EOL> fname = os . path . join ( tempfile . gettempdir ( ) , '<STR_LIT>' ) <EOL> icn . write ( fname ) <EOL> icn = webruntime . common . iconize ( fname ) <EOL> assert isinstance ( icn , icon . Icon ) <EOL> assert webruntime . common . iconize ( icn ) is icn <EOL> raises ( ValueError , webruntime . common . iconize , [ ] ) <EOL> @ skipif ( not has_qt ( ) , reason = '<STR_LIT>' ) <EOL> def test_qtwebkit ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc <EOL> p . close ( ) <EOL> def test_xul ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc <EOL> p . close ( ) <EOL> p . close ( ) <EOL> @ skipif ( not has_nw ( ) , reason = '<STR_LIT>' ) <EOL> def test_nwjs ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc <EOL> p . close ( ) <EOL> @ skipif ( not has_chrome ( ) , reason = '<STR_LIT>' ) <EOL> def test_chomeapp ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc <EOL> p . close ( ) <EOL> def test_nodejs ( ) : <EOL> code = '<STR_LIT>' <EOL> p = launch ( URL , '<STR_LIT>' , code = code ) <EOL> assert p . _proc <EOL> p . close ( ) <EOL> def test_browser ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc is None <EOL> def test_browser_ff ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc is None <EOL> def test_browser_fallback ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc is None <EOL> @ skipif ( os . getenv ( '<STR_LIT>' ) == '<STR_LIT:true>' , reason = '<STR_LIT>' ) <EOL> def test_selenium ( ) : <EOL> p = launch ( URL , '<STR_LIT>' ) <EOL> assert p . _proc is None <EOL> assert p . driver <EOL> time . sleep ( <NUM_LIT:0.5> ) <EOL> p . close ( ) <EOL> raises ( ValueError , launch , URL , '<STR_LIT>' ) <EOL> def test_unknown ( ) : <EOL> raises ( ValueError , launch , URL , '<STR_LIT:foo>' ) <EOL> def test_default ( ) : <EOL> p = launch ( URL ) <EOL> assert p . __class__ . __name__ == '<STR_LIT>' <EOL> p . close ( ) <EOL> def test_base_runtime_must_have_url_in_kwargs ( ) : <EOL> with raises ( KeyError ) as excinfo : <EOL> BaseRuntime ( ) <EOL> assert '<STR_LIT:url>' in str ( excinfo . value ) <EOL> run_tests_if_main ( ) </s>
