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

« back to all changes in this revision

Viewing changes to python/tests/basic4.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
import gamin
 
4
import time
 
5
import os
 
6
import sys
 
7
import shutil
 
8
 
 
9
top = 0
 
10
ok = 1
 
11
expect = [gamin.GAMExists, gamin.GAMExists, gamin.GAMEndExist,
 
12
          gamin.GAMChanged]
 
13
 
 
14
def callback(path, event):
 
15
    global top, expect, ok
 
16
    print "Got callback: %s, %s" % (path, event)
 
17
    if expect[top] != event:
 
18
        print "Error got event %d expected %d" % (event, expect[top])
 
19
        ok = 0
 
20
    top = top + 1
 
21
 
 
22
shutil.rmtree ("temp_dir", True)
 
23
os.mkdir ("temp_dir")
 
24
open("temp_dir/a", "w").close()
 
25
 
 
26
mon = gamin.WatchMonitor()
 
27
mon.watch_directory("temp_dir", callback)
 
28
time.sleep(1)
 
29
fd = open("temp_dir/a", "w")
 
30
fd.write("change")
 
31
fd.close
 
32
time.sleep(1)
 
33
mon.handle_events()
 
34
mon.stop_watch("temp_dir")
 
35
mon.disconnect()
 
36
del mon
 
37
shutil.rmtree ("temp_dir", True)
 
38
if top != 4:
 
39
    print "Error: top monitor got %d events insteads of 4" % (top)
 
40
    sys.exit(1)
 
41
 
 
42
if ok:
 
43
    print "OK"