##// END OF EJS Templates
Adding test_twistedutil.py.
Brian Granger -
Show More
@@ -0,0 +1,48 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3
4 #-----------------------------------------------------------------------------
5 # Copyright (C) 2008 The IPython Development Team
6 #
7 # Distributed under the terms of the BSD License. The full license is in
8 # the file COPYING, distributed as part of this software.
9 #-----------------------------------------------------------------------------
10
11 #-----------------------------------------------------------------------------
12 # Imports
13 #-----------------------------------------------------------------------------
14
15 import tempfile
16 import os, sys
17
18 from twisted.internet import reactor
19 from twisted.trial import unittest
20
21 from IPython.kernel.error import FileTimeoutError
22 from IPython.kernel.twistedutil import wait_for_file
23
24 #-----------------------------------------------------------------------------
25 # Tests
26 #-----------------------------------------------------------------------------
27
28 class TestWaitForFile(unittest.TestCase):
29
30 def test_delay(self):
31 filename = tempfile.mktemp()
32 def _create_file():
33 open(filename,'w').write('####')
34 dcall = reactor.callLater(0.5, _create_file)
35 d = wait_for_file(filename,delay=0.1)
36 d.addCallback(lambda r: self.assert_(r))
37 def _cancel_dcall(r):
38 if dcall.active():
39 dcall.cancel()
40 d.addCallback(_cancel_dcall)
41 return d
42
43 def test_timeout(self):
44 filename = tempfile.mktemp()
45 d = wait_for_file(filename,delay=0.1,max_tries=1)
46 d.addErrback(lambda f: self.assertRaises(FileTimeoutError,f.raiseException))
47 return d
48 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now