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

« back to all changes in this revision

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