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

« back to all changes in this revision

Viewing changes to python/tests/dnotify6.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, then remove the file, then recreate it as a directory
 
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, 51, 52 ]
 
16
expect = [gamin.GAMExists, gamin.GAMEndExist, gamin.GAMDeleted,
 
17
          gamin.GAMCreated]
 
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 dbg < 2 and path[-8:] != "temp_dir":
 
24
        print "Error got debug path unexpected %s" % (path)
 
25
        ok = 0
 
26
    if dbg >= 2 and path[-10:] != "temp_dir/a":
 
27
        print "Error got debug path unexpected %s" % (path)
 
28
        ok = 0
 
29
    if db_expect[dbg] != type:
 
30
        print "Error got debug event %d expected %d" % (type, db_expect[dbg])
 
31
        ok = 0
 
32
    dbg = dbg + 1
 
33
 
 
34
def callback(path, event, which):
 
35
    global top, expect, ok
 
36
#    print "Got callback: %s, %s" % (path, event)
 
37
    if event == gamin.GAMAcknowledge:
 
38
        return
 
39
    if expect[top] != event:
 
40
        print "Error got event %d expected %d" % (expect[top], event)
 
41
        ok = 0
 
42
    top = top + 1
 
43
 
 
44
shutil.rmtree ("temp_dir", True)
 
45
os.mkdir ("temp_dir")
 
46
open("temp_dir/a", "w").close()
 
47
 
 
48
mon = gamin.WatchMonitor()
 
49
mon._debug_object("notify", debug, 0)
 
50
mon.watch_file("temp_dir/a", callback, 0)
 
51
time.sleep(1)
 
52
mon.handle_events()
 
53
os.unlink("temp_dir/a")
 
54
time.sleep(1)
 
55
mon.handle_events()
 
56
os.mkdir("temp_dir/a")
 
57
time.sleep(1)
 
58
mon.handle_events()
 
59
mon.stop_watch("temp_dir/a")
 
60
time.sleep(1)
 
61
mon.handle_events()
 
62
mon.disconnect()
 
63
del mon
 
64
shutil.rmtree ("temp_dir", True)
 
65
 
 
66
if top != 4:
 
67
    print "Error: monitor got %d events insteads of 4" % (top)
 
68
elif dbg != 4 and gamin.has_debug_api == 1:
 
69
    print "Error: debug got %d events insteads of 4" % (dbg)
 
70
elif ok == 1:
 
71
    print "OK"