~jason-cozens/mago/unittest

« back to all changes in this revision

Viewing changes to notify-osd/notify_osd.py

  • Committer: Eitan Isaacson
  • Date: 2009-03-22 23:36:18 UTC
  • Revision ID: eitan@ascender.com-20090322233618-npc5waa6pb08bc2d
Ported notify-osd to new framework.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
import ldtp
 
4
import ldtputils
 
5
 
 
6
from time import time, gmtime, strftime, sleep
 
7
 
 
8
from desktoptesting.deskex import NotifyOSD
 
9
from desktoptesting.check import ScreenshotCompare, FAIL
 
10
 
 
11
class NotifyOSDTest(NotifyOSD):
 
12
    def layoutTest(self, oracle=None, summary=None, body=None, icon=None):
 
13
        self.notify(summary, body, icon)
 
14
        elapsed, screeny = self.grab_image_and_wait(summary)
 
15
 
 
16
        checker = ScreenshotCompare(oracle, screeny)
 
17
 
 
18
        try:
 
19
            passed = checker.perform_test()
 
20
        except Exception, e:
 
21
            checker.calibrate()
 
22
            raise e
 
23
 
 
24
        if passed == FAIL:
 
25
            raise AssertionError('screenshots differ', screeny)
 
26
 
 
27
    def queueTest(self, oracle=None, summary=None, body=None, icon=None):
 
28
        oracles = oracle.split('|')
 
29
        summaries = summary.split('|')
 
30
        bodies = body.split('|')
 
31
        icons = icon.split('|')
 
32
 
 
33
        bubbles = []
 
34
 
 
35
        for oracle, summary, body, icons in \
 
36
                zip(oracles, summaries, bodies, icons):
 
37
            bubbles.append(_Bubble(oracle, summary, body, icons))
 
38
 
 
39
        for b in bubbles:
 
40
            self.notify(b.summary, b.body, b.icon)
 
41
 
 
42
        for b in bubbles:
 
43
            b.elapsed, b.screeny = self.grab_image_and_wait(b.summary)
 
44
            
 
45
        for b in bubbles:
 
46
            testcheck = ScreenshotCompare(b.oracle, b.screeny)
 
47
 
 
48
            try:
 
49
                check = testcheck.perform_test()
 
50
            except Exception, e:
 
51
                testcheck.calibrate()
 
52
                raise e
 
53
 
 
54
            if check == FAIL:
 
55
                raise AssertionError("screenshots differ", b.screeny)
 
56
 
 
57
    def synchronousTest(self, summary1=None, body1=None, icon1=None,
 
58
                        summary2=None, body2=None, icon2=None, value2=None):
 
59
        ALLOWED_OVERLAP = 14
 
60
 
 
61
        self.notify(summary1, body1, icon1)
 
62
        sleep(1)
 
63
        self.notify_synchronous(summary2, body2, icon2, int(value2))
 
64
 
 
65
        x2, y2, w2, h2 = self.get_extents(summary2, True)
 
66
        x1, y1, w1, h1 = self.get_extents(summary1)
 
67
 
 
68
        if w1 == -1:
 
69
            # First bubble does not exist anymore, this could mean 
 
70
            # that the second bubble did not appear synchronously.
 
71
            raise AssertionError("not synchronous")
 
72
        elif (y1 + h1) - y2 > ALLOWED_OVERLAP:
 
73
            raise AssertionError("bad overlap")
 
74
 
 
75
class _Bubble:
 
76
    def __init__(self, oracle, summary, body, icon):
 
77
        self.oracle = oracle
 
78
        self.summary = summary
 
79
        self.body = body
 
80
        self.icon = icon
 
81
        self.elapsed = None
 
82
        self.screeny = None