| Total Complexity | 7 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | # ----------------------------------------------------------------------------- |
||
| 3 | # Copyright (c) 2015 Yann Lanthony |
||
| 4 | # Copyright (c) 2017-2018 Spyder Project Contributors |
||
| 5 | # |
||
| 6 | # Licensed under the terms of the MIT License |
||
| 7 | # (See LICENSE.txt for details) |
||
| 8 | # ----------------------------------------------------------------------------- |
||
| 9 | |||
| 10 | # Standard library imports |
||
| 11 | from os.path import dirname, join, normpath |
||
| 12 | import os |
||
| 13 | import time |
||
| 14 | |||
| 15 | |||
| 16 | PROJECT_DIR = normpath(dirname(dirname(__file__))) |
||
| 17 | EXAMPLES_DIR = normpath(join(PROJECT_DIR, 'examples')) |
||
| 18 | |||
| 19 | |||
| 20 | def example(*paths): |
||
| 21 | """Get path to an example.""" |
||
| 22 | |||
| 23 | return normpath(join(dirname(__file__), '..', 'examples', *paths)) |
||
| 24 | |||
| 25 | |||
| 26 | def touch(file): |
||
| 27 | """Touch a file.""" |
||
| 28 | |||
| 29 | with open(str(file), 'a'): |
||
| 30 | os.utime(str(file), None) |
||
| 31 | |||
| 32 | |||
| 33 | def await_condition(condition, timeout=20, qt_app=None): |
||
| 34 | """Return True if a condition is met in the given timeout period""" |
||
| 35 | |||
| 36 | for _ in range(timeout): |
||
| 37 | if qt_app: |
||
| 38 | # pump event loop while waiting for condition |
||
| 39 | qt_app.processEvents() |
||
| 40 | if condition(): |
||
| 41 | return True |
||
| 42 | time.sleep(0.1) |
||
| 43 | return False |
||
| 44 |