Skip to content
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

Merged
merged 9 commits into from
May 3, 2022
Merged

add testing #4

merged 9 commits into from
May 3, 2022

Conversation

shouples
Copy link
Collaborator

  • Adds some basic unit tests focused around the output structure from format_dx()

  • Handles imports and testing for non-IPython environments

    • no other functionality outside of IPython should work aside from dx.format_dx(df)

IN_IPYTHON_ENV = get_ipython() is not None
if IN_IPYTHON_ENV:
DEFAULT_IPYTHON_DISPLAY_FORMATTER = get_ipython().display_formatter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"image/jpeg": formatters.JPEGFormatter(),
"image/png": formatters.PNGFormatter(),
"image/svg+xml": formatters.SVGFormatter(),
}
Copy link
Collaborator

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.

assert len(data) == len(fields)


# # TODO: mock IPython environment's display formatter
Copy link
Collaborator

@rgbkrk rgbkrk Apr 30, 2022

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'"}, {})

"""Reverts IPython.display_formatter to its original state"""
if not IN_IPYTHON_ENV and ipython_shell is None:
return
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@rgbkrk rgbkrk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. :shipit:

@shouples shouples merged commit 91748f2 into main May 3, 2022
@shouples shouples deleted the djs/add-testing branch March 17, 2023 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants