Skip to content

Commit

Permalink
Add unit tests for dysh shell
Browse files Browse the repository at this point in the history
  • Loading branch information
tchamberlin committed Nov 21, 2023
1 parent 4958e7d commit bb2e705
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/dysh/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
--------------------------------------------------------------------------
"""

DEFAULT_PROFILE = "dysh"
DEFAULT_COLORS = "LightBG"


def parse_args():
parser = argparse.ArgumentParser(
Expand All @@ -37,15 +40,18 @@ def parse_args():
)
)
parser.add_argument("paths", help="FITS file paths to load initially", nargs="*", type=Path)
parser.add_argument("-p", "--profile", help="The IPython profile to use", default="dysh")
parser.add_argument("-p", "--profile", help="The IPython profile to use", default=DEFAULT_PROFILE)
parser.add_argument("-L", "--fits-loader", help="The SDFITS loader class name to use", default="GBTFITSLoad")
parser.add_argument(
"--colors", help="Set the color scheme", choices=["NoColor", "Neutral", "Linux", "LightBG"], default="LightBG"
"--colors",
help="Set the color scheme",
choices=["NoColor", "Neutral", "Linux", "LightBG"],
default=DEFAULT_COLORS,
)
return parser.parse_known_args()


def init_shell(colors: str, profile: str | Path, *ipython_args, sdfits_files=None):
def init_shell(*ipython_args, colors=DEFAULT_COLORS, profile: str | Path = "DEFAULT_PROFILE", sdfits_files=None):
c = Config()
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -81,7 +87,7 @@ def open_sdfits_files(paths: List[Path], loader_class_name="GBTFITSLoad") -> Lis
def main():
args, remaining_args = parse_args()
sdfits_files = open_sdfits_files(args.paths, args.fits_loader)
init_shell(colors=args.colors, profile=args.profile, *remaining_args, sdfits_files=sdfits_files)
init_shell(*remaining_args, colors=args.colors, profile=args.profile, sdfits_files=sdfits_files)


if __name__ == "__main__":
Expand Down
27 changes: 27 additions & 0 deletions src/dysh/test_shell.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import subprocess
import sys
import uuid
from io import StringIO

from dysh.shell import init_shell


def test_shell_cli():
"""Simply prove that we can launch $ dysh from CLI"""
subprocess.check_call(["dysh"])


def test_init_shell(monkeypatch):
"""Prove that we can open the shell, print something, and exit without error"""

# Generate a unique string that we will look for in stdout later
test_str = uuid.uuid4().hex.upper()
mock_input = StringIO(f"print('{test_str}')\n")
monkeypatch.setattr(sys, "stdin", mock_input)

mock_stdout = StringIO()
monkeypatch.setattr(sys, "stdout", mock_stdout)
init_shell("--no-banner", colors="NoColor", profile="dysh")

mock_stdout.seek(0)
assert test_str in mock_stdout.read()

0 comments on commit bb2e705

Please sign in to comment.