Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
Added version check + test
Browse files Browse the repository at this point in the history
  • Loading branch information
major committed Jul 16, 2015
1 parent 0d275bf commit a5e9c2a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
27 changes: 14 additions & 13 deletions supernova/executable.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from __future__ import print_function

import argparse
import click
import pkg_resources
import sys

Expand All @@ -46,28 +47,28 @@ def __call__(self, parser, *args, **kwargs):
parser.exit()


# Copying tr3buchet's hack to short circuit argparse and display the
# version number of supernova
class _ShowVersion(argparse._HelpAction):
"""_ShowVersion used for the --version argument."""
def __call__(self, parser, *args, **kwargs):
version = pkg_resources.require("supernova")[0].version
print("supernova %s" % version)
parser.exit()
def print_version(ctx, param, value):
version = pkg_resources.require("supernova")[0].version
click.echo("supernova %s" % version)
ctx.exit()


def run_supernova():
@click.command()
@click.option('--executable', '-x', default='nova',
help='command to run', show_default=True)
@click.version_option(prog_name='supernova')
def run_supernova(executable):
"""
Handles all of the prep work and error checking for the
supernova executable.
"""
config.run_config()

parser = argparse.ArgumentParser()
parser.add_argument('-x', '--executable', default='nova',
help='command to run instead of nova')
parser.add_argument('--version', action=_ShowVersion,
help='display supernova version')
# parser.add_argument('-x', '--executable', default='nova',
# help='command to run instead of nova')
# parser.add_argument('--version', action=_ShowVersion,
# help='display supernova version')
parser.add_argument('-l', '--list', action=_ListAction,
help='list all configured environments')
parser.add_argument('-d', '--debug', action='store_true',
Expand Down
13 changes: 12 additions & 1 deletion tests/test_supernova.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
from supernova import supernova
import pkg_resources
from click.testing import CliRunner
from supernova import executable, supernova


class TestSuperNova(object):

def test_init(self):
obj = supernova.SuperNova()
assert obj is not None

def test_version_output(self):
# Get the current version number using setuptools
version = pkg_resources.require("supernova")[0].version

runner = CliRunner()
result = runner.invoke(executable.run_supernova, ['--version'])
assert result.exit_code == 0
assert result.output == "supernova, version {0}\n".format(version)

0 comments on commit a5e9c2a

Please sign in to comment.