<s> '''<STR_LIT>''' <EOL> from libs . sikuli import Sikuli <EOL> from src . core . app_launcher import AppLauncher <EOL> from unittest . util import strclass <EOL> import logging <EOL> import os <EOL> import pika <EOL> import shutil <EOL> import time <EOL> import unittest <EOL> from src . core . r import ClientMessageConsts <EOL> class AppTestCase ( unittest . TestCase ) : <EOL> failuresCount = <NUM_LIT:0> <EOL> isFailed = False <EOL> _context = { } <EOL> def setUp ( self ) : <EOL> app = AppLauncher . launchFromSnapshot ( self . settings ) <EOL> AppLauncher . box = app . box <EOL> def _importClassByName ( cl ) : <EOL> d = cl . rfind ( "<STR_LIT:.>" ) <EOL> classname = cl [ d + <NUM_LIT:1> : len ( cl ) ] <EOL> m = __import__ ( cl [ <NUM_LIT:0> : d ] , globals ( ) , locals ( ) , [ classname ] ) <EOL> return getattr ( m , classname ) <EOL> self . initialPage = app . launch ( _importClassByName ( self . settings . get ( "<STR_LIT>" , "<STR_LIT>" ) ) , app . box ) <EOL> self . screenShotsCaptured = <NUM_LIT:0> <EOL> def tearDown ( self ) : <EOL> if len ( self . _resultForDoCleanups . failures ) > AppTestCase . failuresCount : <EOL> self . takeScreenShot ( ) <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> AppTestCase . failuresCount += <NUM_LIT:1> <EOL> self . isFailed = True <EOL> if not self . settings . getboolean ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> AppLauncher . closeEmulator ( self . settings ) <EOL> def run ( self , result ) : <EOL> logging . info ( "<STR_LIT>" % ( strclass ( self . __class__ ) , self . _testMethodName ) ) <EOL> super ( AppTestCase , self ) . run ( result ) <EOL> def takeScreenShot ( self ) : <EOL> imgFilename = "<STR_LIT>" . format ( strclass ( self . __class__ ) , self . _testMethodName ) <EOL> imgLocation = Sikuli . getBundlePath ( ) + "<STR_LIT>" <EOL> if not os . path . isdir ( imgLocation ) : <EOL> os . makedirs ( imgLocation ) <EOL> screenshotFilename = Sikuli . Screen ( ) . capture ( Sikuli . Screen ( ) . getBounds ( ) ) <EOL> shutil . move ( screenshotFilename , imgLocation + imgFilename ) <EOL> def onReceiveTestCaseRunResponse ( self , ch , method , properties , body ) : <EOL> logging . info ( "<STR_LIT>" % body ) <EOL> ch . stop_consuming ( ) <EOL> if body == ClientMessageConsts . TASK_FAILED : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def requestRunTestCase ( self , testCaseNameFragment ) : <EOL> connection = pika . BlockingConnection ( pika . ConnectionParameters ( <EOL> host = self . settings . get ( "<STR_LIT>" , "<STR_LIT>" ) ) ) <EOL> channel = connection . channel ( ) <EOL> channel . queue_declare ( queue = '<STR_LIT>' , durable = True ) <EOL> channel . basic_publish ( exchange = '<STR_LIT>' , routing_key = '<STR_LIT>' , body = testCaseNameFragment , <EOL> properties = pika . BasicProperties ( <EOL> delivery_mode = <NUM_LIT:2> , <EOL> ) ) <EOL> channel = connection . channel ( ) <EOL> channel . queue_declare ( queue = '<STR_LIT>' , durable = True ) <EOL> channel . queue_purge ( queue = '<STR_LIT>' ) <EOL> channel . basic_consume ( self . onReceiveTestCaseRunResponse , queue = '<STR_LIT>' , no_ack = True ) <EOL> channel . start_consuming ( ) <EOL> connection . close ( ) <EOL> def getVar ( self ) : <EOL> pass </s>
