-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add testing #4
add testing #4
Conversation
IN_IPYTHON_ENV = get_ipython() is not None | ||
if IN_IPYTHON_ENV: | ||
DEFAULT_IPYTHON_DISPLAY_FORMATTER = get_ipython().display_formatter | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
dx/tests/conftest.py
Outdated
"image/jpeg": formatters.JPEGFormatter(), | ||
"image/png": formatters.PNGFormatter(), | ||
"image/svg+xml": formatters.SVGFormatter(), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't have to but I think it's fine to reduce the total set here in the tests since you only need text/html
, application/vnd.dataresource+json
, text/plain
, and the dex media type.
dx/tests/test_formatters.py
Outdated
assert len(data) == len(fields) | ||
|
||
|
||
# # TODO: mock IPython environment's display formatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IPython tests use this in their conftest.py
(note: I edited this to work in a local script):
from IPython.testing import tools
def get_ipython():
from IPython.terminal.interactiveshell import TerminalInteractiveShell
if TerminalInteractiveShell._instance:
return TerminalInteractiveShell.instance()
config = tools.default_config()
config.TerminalInteractiveShell.simple_prompt = True
# Create and initialize our test-friendly IPython instance.
shell = TerminalInteractiveShell.instance(config=config)
return shell
As an example:
$ cat ipy.py
from IPython.testing import tools
def get_ipython():
from IPython.terminal.interactiveshell import TerminalInteractiveShell
if TerminalInteractiveShell._instance:
return TerminalInteractiveShell.instance()
config = tools.default_config()
config.TerminalInteractiveShell.simple_prompt = True
# Create and initialize our test-friendly IPython instance.
shell = TerminalInteractiveShell.instance(config=config)
return shell
print(get_ipython().display_formatter.format("a simple script"))
$ python ipy.py
({'text/plain': "'a simple script'"}, {})
… instance in a better way
"""Reverts IPython.display_formatter to its original state""" | ||
if not IN_IPYTHON_ENV and ipython_shell is None: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great.
Adds some basic unit tests focused around the output structure from
format_dx()
Handles imports and testing for non-IPython environments
dx.format_dx(df)