1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
11 class PathTest(unittest
.TestCase
):
13 def testIsExecutable(self
):
14 self
.assertFalse(py_utils
.IsExecutable('nonexistent_file'))
15 # We use actual files on disk instead of pyfakefs because the executable is
16 # set different on win that posix platforms and pyfakefs doesn't support
18 self
.assertFalse(py_utils
.IsExecutable(_GetFileInTestDir('foo.txt')))
19 self
.assertTrue(py_utils
.IsExecutable(sys
.executable
))
22 def _GetFileInTestDir(file_name
):
23 return os
.path
.join(os
.path
.dirname(__file__
), 'test_data', file_name
)
26 class WaitForTest(unittest
.TestCase
):
28 def testWaitForTrue(self
):
31 self
.assertTrue(py_utils
.WaitFor(ReturnTrue
, .1))
33 def testWaitForFalse(self
):
37 with self
.assertRaises(py_utils
.TimeoutException
):
38 py_utils
.WaitFor(ReturnFalse
, .1)
40 def testWaitForEventuallyTrue(self
):
41 # Use list to pass to inner function in order to allow modifying the
42 # variable from the outer scope.
44 def ReturnCounterBasedValue():
48 self
.assertTrue(py_utils
.WaitFor(ReturnCounterBasedValue
, .5))
50 def testWaitForTrueLambda(self
):
51 self
.assertTrue(py_utils
.WaitFor(lambda: True, .1))
53 def testWaitForFalseLambda(self
):
54 with self
.assertRaises(py_utils
.TimeoutException
):
55 py_utils
.WaitFor(lambda: False, .1)