This repository has been archived by the owner on May 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
103 lines (75 loc) · 3.12 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#-----------------------------------------------------------------------------
# Copyright (c) 2011, Enthought, Inc.
# All rights reserved.
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Logging Setup
#------------------------------------------------------------------------------
# Add a NullHandler so enaml loggers don't complain when they get used.
import logging
class NullHandler(logging.Handler):
def handle(self, record):
pass
def emit(self, record):
pass
def createLock(self):
self.lock = None
logger = logging.getLogger(__name__)
logger.addHandler(NullHandler())
del logging, logger, NullHandler
#------------------------------------------------------------------------------
# Import Helper
#------------------------------------------------------------------------------
def imports():
""" Lazily imports and returns an enaml imports context.
"""
from enaml.core.import_hooks import imports
return imports()
#------------------------------------------------------------------------------
# Operator Context Functions
#------------------------------------------------------------------------------
#: The private storage for the optional default operator context function
#: which overrides that which is provided by default.
_default_operator_context_func = None
def set_default_operator_context_func(func):
""" Set the default operator context func to the given callable.
Parameters
----------
func : callable
A callable object which takes no arguments and returns an
instance of OperatorContext.
"""
global _default_operator_context_func
_default_operator_context_func = func
def reset_default_operator_context_func():
""" Reset the default operator context func such that the default
context is returned to the framework default.
"""
global _default_operator_context_func
_default_operator_context_func = None
def default_operator_context():
""" Creates an returns the default operator context. The default
context is either that which is provided by the framework unless
overridden by the user by providing a default context func via
'set_default_operator_context_func'
"""
ctxt_func = _default_operator_context_func
if ctxt_func is not None:
return ctxt_func()
from enaml.core.operator_context import OperatorContext
from enaml.core.operators import OPERATORS
return OperatorContext(OPERATORS)
#------------------------------------------------------------------------------
# Test Helpers
#------------------------------------------------------------------------------
def test_collector():
""" Discover and collect tests for the Enaml Package.
.. note :: addapted from the unittest2
"""
import os
import sys
from unittest import TestLoader
# import __main__ triggers code re-execution
__main__ = sys.modules['__main__']
setupDir = os.path.abspath(os.path.dirname(__main__.__file__))
return TestLoader().discover(setupDir)