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

« back to all changes in this revision

Viewing changes to python/tests/dnotify.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 file
 
5
#
 
6
 
 
7
import gamin
 
8
import time
 
9
import os
 
10
import sys
 
11
import shutil
 
12
 
 
13
ok = 1
 
14
top = 0
 
15
dbg = 0
 
16
db_expect = [ 51, 52 ]
 
17
expect = [gamin.GAMExists, gamin.GAMEndExist]
 
18
 
 
19
def debug(path, type, data):
 
20
    global dbg, db_expect, ok
 
21
 
 
22
#    print "Got debug %s, %s, %s" % (path, type, data)
 
23
    if path[-10:] != "temp_dir/a":
 
24
        print "Error got debug path unexpected %s" % (path)
 
25
        ok = 0
 
26
    if db_expect[dbg] != type:
 
27
        print "Error got debug event %d expected %d" % (db_expect[dbg], type)
 
28
        ok = 0
 
29
    dbg = dbg + 1
 
30
 
 
31
def callback(path, event, which):
 
32
    global top, expect, ok
 
33
#    print "Got callback: %s, %s" % (path, event)
 
34
    if event == gamin.GAMAcknowledge:
 
35
        return
 
36
    if expect[top] != event:
 
37
        print "Error got event %d expected %d" % (expect[top], event)
 
38
        ok = 0
 
39
    top = top + 1
 
40
 
 
41
 
 
42
shutil.rmtree ("temp_dir", True)
 
43
os.mkdir ("temp_dir")
 
44
os.mkdir ("temp_dir/a")
 
45
 
 
46
mon = gamin.WatchMonitor()
 
47
mon._debug_object("notify", debug, 0)
 
48
mon.watch_file("temp_dir/a", callback, 0)
 
49
time.sleep(1)
 
50
mon.handle_events()
 
51
mon.stop_watch("temp_dir/a")
 
52
time.sleep(1)
 
53
os.rmdir("temp_dir/a")
 
54
time.sleep(1)
 
55
mon.handle_events()
 
56
mon.disconnect()
 
57
del mon
 
58
shutil.rmtree ("temp_dir", True)
 
59
 
 
60
if top != 2:
 
61
    print "Error: monitor got %d events insteads of 2" % (top)
 
62
elif dbg != 2 and gamin.has_debug_api == 1:
 
63
    print "Error: debug got %d events insteads of 2" % (dbg)
 
64
elif ok == 1:
 
65
    print "OK"