~ubuntu-branches/debian/jessie/gamin/jessie

« back to all changes in this revision

Viewing changes to python/tests/dnotify8.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2007-03-23 14:43:49 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070323144349-1inpdk22uaneks9h
Tags: 0.1.8-2
* debian/control: Improve long description. (Closes: #405347)
* debian/patches/14_nfs-fix.patch: Fix gam_server startup for Thunar.
  Thanks to Maximiliano Curia. (Closes: #403247)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
#
 
3
# Checking DNotify registration/dregistration when monitoring a
 
4
# directory as a directory and also watching the parent directory,
 
5
# then remove the children directory and check we are still watching
 
6
# the parent one correctly
 
7
#
 
8
import gamin
 
9
import time
 
10
import os
 
11
import sys
 
12
import shutil
 
13
 
 
14
ok = 1
 
15
top = 0
 
16
top2 = 0
 
17
dbg = 0
 
18
db_expect = [ 51, 51, 52, 52 ]
 
19
expect = [gamin.GAMExists, gamin.GAMExists, gamin.GAMEndExist,
 
20
          gamin.GAMDeleted, gamin.GAMCreated]
 
21
expect2 = [gamin.GAMExists, gamin.GAMEndExist, gamin.GAMDeleted ]
 
22
 
 
23
def debug(path, type, data):
 
24
    global dbg, db_expect, ok
 
25
 
 
26
#    print "Got debug %s, %s, %s" % (path, type, data)
 
27
    if db_expect[dbg] != type:
 
28
        print "Error got debug event %d expected %d" % (type, db_expect[dbg])
 
29
        ok = 0
 
30
    dbg = dbg + 1
 
31
 
 
32
def callback(path, event, which):
 
33
    global top, expect, ok
 
34
#    print "Got callback: %s, %s" % (path, event)
 
35
    if event == gamin.GAMAcknowledge:
 
36
        return
 
37
    if expect[top] != event:
 
38
        print "Error got event %d expected %d" % (expect[top], event)
 
39
        ok = 0
 
40
    top = top + 1
 
41
 
 
42
def callback2(path, event, which):
 
43
    global top2, expect2, ok
 
44
#    print "Got callback2: %s, %s" % (path, event)
 
45
    if event == gamin.GAMAcknowledge:
 
46
        return
 
47
    if expect2[top2] != event:
 
48
        print "Error got event %d expected %d" % (expect2[top2], event)
 
49
        ok = 0
 
50
    top2 = top2 + 1
 
51
 
 
52
shutil.rmtree ("temp_dir", True)
 
53
os.mkdir ("temp_dir")
 
54
os.mkdir ("temp_dir/a")
 
55
 
 
56
mon = gamin.WatchMonitor()
 
57
mon._debug_object("notify", debug, 0)
 
58
mon.watch_directory("temp_dir", callback, 0)
 
59
mon.watch_directory("temp_dir/a", callback2, 0)
 
60
time.sleep(1)
 
61
mon.handle_events()
 
62
shutil.rmtree("temp_dir/a")
 
63
time.sleep(1)
 
64
mon.handle_events()
 
65
open("temp_dir/b", "w").close()
 
66
time.sleep(1)
 
67
mon.handle_events()
 
68
mon.stop_watch("temp_dir/a")
 
69
mon.stop_watch("temp_dir")
 
70
time.sleep(1)
 
71
mon.handle_events()
 
72
mon.disconnect()
 
73
del mon
 
74
shutil.rmtree ("temp_dir", True)
 
75
 
 
76
if top != 5:
 
77
    print "Error: monitor got %d events insteads of 5" % (top)
 
78
elif top2 != 3:
 
79
    print "Error: monitor got %d events insteads of 3" % (top2)
 
80
elif dbg != 4 and gamin.has_debug_api == 1:
 
81
    print "Error: debug got %d events insteads of 4" % (dbg)
 
82
elif ok == 1:
 
83
    print "OK"