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

« back to all changes in this revision

Viewing changes to python/tests/dnotify7.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 file
 
5
# in addition the directory is being watched, as a rsult internally
 
6
# the dnotify monitoring sequence is different since we keep
 
7
#
 
8
import gamin
 
9
import time
 
10
import os
 
11
import sys
 
12
import shutil
 
13
 
 
14
ok = 1
 
15
dbg = 0
 
16
db_expect = [ 51, # directory watch
 
17
              53, # file watch count incremented
 
18
              53, # file disapear count decremented
 
19
              53, # file recreated
 
20
              53, # removal of watch on file
 
21
              52  # removal of watch on directory
 
22
              ]
 
23
top_f = 0
 
24
expect_f = [gamin.GAMExists, gamin.GAMEndExist, gamin.GAMDeleted,
 
25
            gamin.GAMCreated]
 
26
top_d = 0
 
27
expect_d = [gamin.GAMExists,  # directory exists
 
28
            gamin.GAMExists,  # file a exists
 
29
            gamin.GAMEndExist,# end listing
 
30
            gamin.GAMDeleted, # file a removed
 
31
            gamin.GAMCreated  # file a created
 
32
           ] 
 
33
 
 
34
def debug(path, type, data):
 
35
    global dbg, db_expect, ok
 
36
 
 
37
#    print "Got debug %s, %s, %s" % (path, type, data)
 
38
    if path[-8:] != "temp_dir":
 
39
        print "Error got debug path unexpected %s" % (path)
 
40
        ok = 0
 
41
    if db_expect[dbg] != type:
 
42
        print "Error got debug event %d expected %d" % (type, db_expect[dbg])
 
43
        ok = 0
 
44
    dbg = dbg + 1
 
45
 
 
46
def callback_file(path, event):
 
47
    global top_f, expect_f, ok
 
48
#    print "Got callback: %s, %s" % (path, event)
 
49
    if event == gamin.GAMAcknowledge:
 
50
        return
 
51
    if expect_f[top_f] != event:
 
52
        print "Error got file event %d expected %d" % (expect_f[top_f], event)
 
53
        ok = 0
 
54
    top_f = top_f + 1
 
55
 
 
56
def callback_dir(path, event):
 
57
    global top_d, expect_d, ok
 
58
#    print "Got callback: %s, %s" % (path, event)
 
59
    if event == gamin.GAMAcknowledge:
 
60
        return
 
61
    if expect_d[top_d] != event:
 
62
        print "Error got dir event %d expected %d" % (expect_d[top_d], event)
 
63
        ok = 0
 
64
    top_d = top_d + 1
 
65
 
 
66
shutil.rmtree ("temp_dir", True)
 
67
os.mkdir ("temp_dir")
 
68
open("temp_dir/a", "w").close()
 
69
 
 
70
mon = gamin.WatchMonitor()
 
71
mon._debug_object("notify", debug, 0)
 
72
mon.watch_directory("temp_dir", callback_dir)
 
73
mon.watch_file("temp_dir/a", callback_file)
 
74
time.sleep(1)
 
75
mon.handle_events()
 
76
os.unlink("temp_dir/a")
 
77
time.sleep(1)
 
78
mon.handle_events()
 
79
open("temp_dir/a", "w").close()
 
80
time.sleep(1)
 
81
mon.handle_events()
 
82
mon.stop_watch("temp_dir/a")
 
83
mon.stop_watch("temp_dir")
 
84
time.sleep(1)
 
85
mon.handle_events()
 
86
mon.disconnect()
 
87
del mon
 
88
shutil.rmtree ("temp_dir", True)
 
89
 
 
90
if top_f != 4:
 
91
    print "Error: file monitor got %d events insteads of 4" % (top_f)
 
92
if top_d != 5:
 
93
    print "Error: dir monitor got %d events insteads of 4" % (top_d)
 
94
elif dbg != 6 and gamin.has_debug_api == 1:
 
95
    print "Error: debug got %d events insteads of 6" % (dbg)
 
96
elif ok == 1:
 
97
    print "OK"