-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a9a093
commit d08ddff
Showing
6 changed files
with
126 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import io | ||
import site | ||
import inspect | ||
import importlib | ||
import warnings | ||
from pathlib import Path | ||
|
||
WHITELISTED_FILENAMES = ["geckodriver.log", ".pytest-sugar.conf"] | ||
WHITELISTED_PREFIXES = ["/tmp"] + site.PREFIXES | ||
WHITELISTED_POSTFIXES = [str(Path(".plotly" / Path(".config"))), ".py", ".json"] | ||
WHITELISTED_CONTAINS = [ | ||
".pytest_cache", | ||
"__pycache__", | ||
".cache", | ||
".egg-info", | ||
"/dev/null", | ||
] | ||
|
||
import builtins | ||
|
||
FUNCTIONS = [ | ||
("builtins", "open", "filepath"), | ||
("pandas", "read_csv", "filepath"), | ||
("xtgeo", "Well", "self"), | ||
] | ||
|
||
|
||
class MonitorBuiltinOpen: | ||
def __init__(self): | ||
self._original_functions = [ | ||
getattr(importlib.import_module(module), function) | ||
for module, function, _ in FUNCTIONS | ||
] | ||
|
||
def stop_monitoring(self): | ||
pass | ||
# builtins.open = self._original_open | ||
# io.open = self._original_open | ||
|
||
def start_monitoring(self): | ||
pass | ||
# def wrapped_open(*args, **kwargs): | ||
# path = str(args[0]) | ||
# if Path(path).name not in WHITELISTED_FILENAMES and str(Path(path).parent) != "." and all([part not in path for part in WHITELISTED_CONTAINS]) and all([not path.startswith(prefix) for prefix in WHITELISTED_PREFIXES]) and all([not path.endswith(postfix) for postfix in WHITELISTED_POSTFIXES]): | ||
# raise RuntimeError(f"File {path} opened, which is not white-listed as a 'portable' location.") | ||
# return self._original_open(*args, **kwargs) | ||
|
||
# builtins.open = wrapped_open | ||
# io.open = wrapped_open | ||
|
||
|
||
monitor_builtin_open = MonitorBuiltinOpen() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import pytest | ||
|
||
import dash | ||
from dash_html_components import Div | ||
|
||
from ._monitor_builtin_open import monitor_builtin_open | ||
from ..common_cache import CACHE | ||
from ..themes import default_theme | ||
|
||
|
||
class WebvizSinglePlugin: | ||
def __init__(self): | ||
self._app = dash.Dash(__name__) | ||
self._configure_app() | ||
|
||
def _configure_app(self): | ||
self._app.config.suppress_callback_exceptions = True | ||
CACHE.init_app(self._app.server) | ||
self._app.webviz_settings = {"theme": default_theme} | ||
|
||
def check_portability(self): | ||
monitor_builtin_open.start_monitoring() | ||
|
||
@property | ||
def app(self): | ||
return self._app | ||
|
||
|
||
@pytest.fixture | ||
def webviz_single_plugin(): | ||
return WebvizSinglePlugin() |