~helene-verhaeghe27/cairo-dock-core/bugfix

« back to all changes in this revision

Viewing changes to tests/TestCustomLauncher.py

  • Committer: Fabrice Rey
  • Date: 2013-06-28 23:44:28 UTC
  • Revision ID: fabounet03@gmail.com-20130628234428-cwsvh6mexcfm0063
Added a test framework, and several tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from time import sleep
 
2
import sys  # argv
 
3
import os  # system, path
 
4
import subprocess  # system, path
 
5
from Test import Test, key, set_param
 
6
from CairoDock import CairoDock
 
7
 
 
8
# Test Custom Launcher
 
9
class TestCustomLauncher(Test):
 
10
        def __init__(self, dock):
 
11
                self.test_file='/tmp/cairo-dock-test'
 
12
                Test.__init__(self, "Test custom launcher", dock)
 
13
        
 
14
        def run(self):
 
15
                if os.path.exists(self.test_file):
 
16
                        os.remove(self.test_file)
 
17
                
 
18
                # add a new custom launcher at the beginning of the dock
 
19
                conf_file = self.d.Add({'type':'Launcher', 'name':'xxx', 'command':'echo -n 321 > '+self.test_file, 'icon':'gtk-home.png', 'position':1})
 
20
                if conf_file == None or conf_file == "" or not os.path.exists(conf_file):
 
21
                        self.print_error ("Failed to add the launcher")
 
22
                        return
 
23
                
 
24
                # reload
 
25
                set_param (conf_file, "Desktop Entry", "Name", "Test launcher")
 
26
                set_param (conf_file, "Desktop Entry", "Exec", "echo -n 123 > \/tmp\/cairo-dock-test")
 
27
                self.d.Reload('config-file='+conf_file)
 
28
                
 
29
                # left-click on it
 
30
                key ("super+Return")
 
31
                key("2")  # 'position' starts from 0, but numbers on the icons start from 1
 
32
                
 
33
                try:
 
34
                        f = open('/tmp/cairo-dock-test', 'r')
 
35
                        result = f.read()
 
36
                        if result != "123":
 
37
                                self.print_error ("Failed to reload the launcher")
 
38
                except:
 
39
                        self.print_error ("[Test custom launcher] Failed to activate the launcher")
 
40
                
 
41
                # remove it
 
42
                self.d.Remove('config-file='+conf_file);
 
43
                if os.path.exists(conf_file):
 
44
                        self.print_error ("Failed to remove the launcher")
 
45
                
 
46
                self.end()