本文整理汇总了Python中pyvirtualdisplay.smartdisplay.SmartDisplay类的典型用法代码示例。如果您正苦于以下问题:Python SmartDisplay类的具体用法?Python SmartDisplay怎么用?Python SmartDisplay使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmartDisplay类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prog_shot
def prog_shot(cmd, f, wait, timeout, screen_size, visible, bgcolor, cwd=None):
'''start process in headless X and create screenshot after 'wait' sec.
Repeats screenshot until it is not empty if 'repeat_if_empty'=True.
wait: wait at least N seconds after first window is displayed,
it can be used to skip splash screen
:param enable_crop: True -> crop screenshot
:param wait: int
'''
disp = SmartDisplay(visible=visible, size=screen_size, bgcolor=bgcolor)
disp.pyscreenshot_backend = None
disp.pyscreenshot_childprocess = True
proc = EasyProcess(cmd, cwd=cwd)
def func():
try:
img = disp.waitgrab(timeout=timeout)
except DisplayTimeoutError as e:
raise DisplayTimeoutError(str(e) + ' ' + str(proc))
if wait:
proc.sleep(wait)
img = disp.grab()
return img
img = disp.wrap(proc.wrap(func))()
if img:
img.save(f)
return (proc.stdout, proc.stderr)
示例2: Test
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
def tearDown(self):
self.p.stop()
self.screen.stop()
# def test_empty(self):
# self.p = EasyProcess('zenity --warning').start()
# wnd is not ready
# time.sleep(0.2)
# self.assertRaises(EmptyScreenException, active_rectangles)
def test_zenity(self):
self.p = EasyProcess('zenity --warning').start()
self.wait()
ls = active_rectangles()
self.assertEquals(len(ls), 1)
def test_notab(self):
self.p = EasyProcess('xmessage -buttons x,y,z hi').start()
self.wait()
ls = active_rectangles(grid=10)
self.assertEquals(len(ls), 3)
def test_gmessage(self):
self.p = EasyProcess('gmessage -buttons x,y,z hi').start()
self.wait()
ls = active_rectangles()
self.assertEquals(len(ls), 3)
示例3: Test
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay()
self.screen.start()
self.p = None
def tearDown(self):
self.p.stop()
self.screen.stop()
# def test_empty(self):
# self.p = EasyProcess('zenity --warning').start()
# wnd is not ready
# self.assertRaises(EmptyScreenException, tab_rectangles)
# def test_zenity(self):
# self.p = EasyProcess('zenity --warning').start()
# self.wait()
# ls = tab_rectangles()
# self.assertEquals(len(ls), 2)
def test_notab(self):
self.p = EasyProcess('xmessage hi').start()
self.wait()
ls = tab_rectangles()
self.assertEquals(len(ls), 0)
def test_gmessage(self):
self.p = EasyProcess('gmessage -buttons x,y,z hi').start()
self.wait()
ls = tab_rectangles()
self.assertEquals(len(ls), 4)
示例4: test_slowshot_wrap
def test_slowshot_wrap(self):
disp = SmartDisplay(visible=0)
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py)
f = disp.wrap(proc.wrap(disp.waitgrab))
img = f()
eq_(img is not None, True)
示例5: test_slowshot
def test_slowshot(self):
disp = SmartDisplay(visible=0).start()
py = path(__file__).parent / ('slowgui.py')
proc = EasyProcess('python ' + py).start()
img = disp.waitgrab()
proc.stop()
disp.stop()
eq_(img is not None, True)
示例6: cli_parse
def cli_parse():
'''Parse command-line arguments'''
options = {'title': None, 'desc': None, 'date': None,
'time': None, 'id': None}
parser = argparse.ArgumentParser()
parser.add_argument("action", help='''use "create" to create a new event\n
"update" to update an event\n"details" to get event info''') # noqa
parser.add_argument("--title", help="event title")
parser.add_argument("--date", help="event date")
parser.add_argument("--id", help="event id")
parser.add_argument("--desc", help="event description")
parser.add_argument("--filedesc", help="path to txt file w/ event description", # noqa
type=argparse.FileType('r'))
parser.add_argument("--otp", help="2-step verification code")
parser.add_argument("--show", help="1 to display the browser, 0 for invisible virtual display", # noqa
default=0, type=int)
try:
args = parser.parse_args()
except:
parser.print_help()
exit(1)
disp = None
if not args.show: # set up invisible virtual display
from pyvirtualdisplay.smartdisplay import SmartDisplay
try:
disp = SmartDisplay(visible=0, bgcolor='black').start()
atexit.register(disp.stop)
except:
if disp:
disp.stop()
raise
if args.title:
options['title'] = args.title
if args.desc:
options['desc'] = args.desc
elif args.filedesc:
options['desc'] = args.filedesc.read()
if args.date:
options['date'] = dtparser.parse(args.date).strftime('%Y-%m-%d')
options['time'] = dtparser.parse(args.date).strftime('%I:%M %p')
if args.id:
options['id'] = args.id
if args.otp:
options['otp'] = args.otp
options['action'] = args.action
return options
示例7: test_disp
def test_disp(self):
vd = SmartDisplay().start()
d = SmartDisplay(visible=1).start().sleep(2).stop()
self.assertEquals(d.return_code, 0)
d = SmartDisplay(visible=0).start().stop()
self.assertEquals(d.return_code, 0)
vd.stop()
示例8: CuiJsTestCase
class CuiJsTestCase(LiveServerTestCase):
def setUp(self):
# See https://code.djangoproject.com/ticket/10827
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)
def tearDown(self):
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()
def wait_until_expr(self, expr, timeout=60):
WebDriverWait(self.driver, timeout).until(
lambda driver: driver.execute_script('return (%s)' % expr))
def test(self):
sys.stderr.write('\n\nRunning candidate UI unit tests...\n')
sys.stderr.flush()
tests_url = self.live_server_url + reverse('cui_test')
jasmine_spec = os.environ.get('JASMINE_SPEC')
if jasmine_spec:
tests_url += "?spec={}".format(urlquote(jasmine_spec))
self.driver.get(tests_url)
self.wait_until_expr('window.seleniumReporter')
runner = SeleniumRunner(self.driver, sys.stderr)
success = runner.run()
self.assertTrue(success, 'JS tests failed. See full report on stderr')
示例9: __init__
def __init__(self, browser="chrome", executable_path=None):
"""
Initialization does two things:
1. Makes sure that there is active X session.
2. Starts browser.
On initialization it stats X session if can't find 'DISPLAY' in
os.environ. For this purposes used *pyvirtualdisplay* package.
For handling browser used seleniumwrapper library.
"""
# lets start display in case if no is available
self.hangout_id = None
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {}
if browser == "chrome":
kwargs['executable_path'] = executable_path or CHROMEDRV_PATH
self.browser = selwrap.create(browser, **kwargs)
self.video = VideoSettings(self)
self.microphone = MicrophoneSettings(self)
self.audio = AudioSettings(self)
self.bandwidth = BandwidthSettings(self)
示例10: Test
class Test(TestCase):
def wait(self):
self.screen.waitgrab()
def setUp(self):
self.screen = SmartDisplay(visible=VISIBLE)
self.screen.start()
self.p = None
def tearDown(self):
self.p.stop()
self.screen.stop()
def test_zenity(self):
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key('\n')
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key_list(['\n'])
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key(' ')
self.assertFalse(getbbox(grab()))
self.p = EasyProcess('zenity --warning').start()
self.wait()
send_key('x')
self.assertTrue(getbbox(grab()))
def test_gcalctool1(self):
self.p = EasyProcess('gnome-calculator').start()
self.wait()
focus_wnd()
send_key('ctrl+q')
time.sleep(1)
# img_debug(grab(), 'ctrl+q')
self.assertFalse(getbbox(grab()))
示例11: RealBrowser
class RealBrowser(webdriver.Firefox):
def __init__(self, timeout=30):
self._abstract_display = SmartDisplay(visible=0)
self._abstract_display.start()
super(RealBrowser, self).__init__()
self.implicitly_wait(timeout)
def quit(self):
super(RealBrowser, self).quit()
self._abstract_display.stop()
@timeout(REQUEST_TIMEOUT)
def _open(self, url):
self.get(url)
def open(self, url):
try:
self._open(url)
return True
except Exception, e:
logger.error('network error for %s: %s', url, str(e))
示例12: CuiJsTestCase
class CuiJsTestCase(LiveServerTestCase):
def setUp(self):
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
self.driver = webdriver.Firefox()
def tearDown(self):
if hasattr(self, 'driver'):
self.driver.quit()
if hasattr(self, 'display'):
self.display.stop()
def wait_until_expr(self, expr, timeout=60):
WebDriverWait(self.driver, timeout).until(
lambda driver: driver.execute_script('return (%s)' % expr))
def test(self):
sys.stderr.write('\n\nRunning candidate UI unit tests...\n')
sys.stderr.flush()
self.driver.get(self.live_server_url+reverse('cui_test'))
self.wait_until_expr('window.jsApiReporter !== undefined && window.jsApiReporter.finished')
specs = self.driver.execute_script('return window.jsApiReporter.specs()')
self.assertTrue(len(specs) > 0, 'No test results found! The tests probably contain syntax errors.')
passed = True
for spec in specs:
sys.stderr.write(' %s ... %s\n' % (spec['fullName'], spec['status']))
if spec['status'] != 'passed':
passed = False
for exp in spec['failedExpectations']:
sys.stderr.write(' %s\n' % exp['message'])
sys.stderr.write('Access full report at %s\n\n' % reverse('cui_test'))
sys.stderr.flush()
self.assertTrue(passed, 'JS tests failed. See full report on stderr')
示例13: setUp
def setUp(self):
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)
示例14: __init__
def __init__(self, executable_path=None, chrome_options=None):
self.hangout_id = None
self.on_air = None
# lets start display in case if no is available
self.display = None
if not os.environ.get('DISPLAY'):
self.display = SmartDisplay()
self.display.start()
kwargs = {'executable_path': executable_path or CHROMEDRV_PATH}
if chrome_options is not None:
kwargs['chrome_options'] = chrome_options
self.browser = selwrap.create('chrome', **kwargs)
self.utils = Utils(self.browser)
for name, instance in getUtilitiesFor(IModule):
setattr(self, name, instance(self.utils))
示例15: setUp
def setUp(self):
# See https://code.djangoproject.com/ticket/10827
from django.contrib.contenttypes.models import ContentType
ContentType.objects.clear_cache()
if not os.environ.get('SHOW_SELENIUM'):
self.display = SmartDisplay(visible=0, size=(1024, 768))
self.display.start()
remote_selenium = os.environ.get('REMOTE_SELENIUM')
if not remote_selenium:
self.driver = webdriver.Firefox()
else:
self.driver = webdriver.Remote(
command_executor=remote_selenium,
desired_capabilities={
'browserName': 'unknown',
'javascriptEnabled': True,
'platform': 'ANY',
'version': ''
}
)