More test coverage.
This commit is contained in:
@@ -4,14 +4,13 @@ import argparse
|
||||
import logging
|
||||
import sys
|
||||
from warnings import warn
|
||||
from pecan import load_app
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class HelpfulArgumentParser(argparse.ArgumentParser):
|
||||
|
||||
def error(self, message):
|
||||
def error(self, message): # pragma: nocover
|
||||
"""error(message: string)
|
||||
|
||||
Prints a usage message incorporating the message to stderr and
|
||||
@@ -38,7 +37,7 @@ class CommandManager(object):
|
||||
try:
|
||||
cmd = ep.load()
|
||||
assert hasattr(cmd, 'run')
|
||||
except Exception, e:
|
||||
except Exception, e: # pragma: nocover
|
||||
warn("Unable to load plugin %s: %s" % (ep, e), RuntimeWarning)
|
||||
continue
|
||||
self.add({ep.name: cmd})
|
||||
@@ -77,7 +76,7 @@ class CommandRunner(object):
|
||||
self.commands[ns.command_name]().run(ns)
|
||||
|
||||
@classmethod
|
||||
def handle_command_line(cls):
|
||||
def handle_command_line(cls): # pragma: nocover
|
||||
runner = CommandRunner()
|
||||
runner.run(sys.argv[1:])
|
||||
|
||||
@@ -86,10 +85,10 @@ class CommandRunner(object):
|
||||
try:
|
||||
dist = pkg_resources.get_distribution('Pecan')
|
||||
if os.path.dirname(os.path.dirname(__file__)) == dist.location:
|
||||
return dist.version
|
||||
return dist.version # pragma: nocover
|
||||
else:
|
||||
return '(development)'
|
||||
except:
|
||||
except: # pragma: nocover
|
||||
return '(development)'
|
||||
|
||||
@property
|
||||
@@ -114,6 +113,7 @@ class BaseCommand(object):
|
||||
self.args = args
|
||||
|
||||
def load_app(self):
|
||||
from pecan import load_app
|
||||
if not os.path.isfile(self.args.config_file):
|
||||
raise RuntimeError('`%s` is not a file.' % self.args.config_file)
|
||||
return load_app(self.args.config_file)
|
||||
|
||||
@@ -23,7 +23,7 @@ class ScaffoldManager(object):
|
||||
try:
|
||||
cmd = ep.load()
|
||||
assert hasattr(cmd, 'copy_to')
|
||||
except Exception, e:
|
||||
except Exception, e: # pragma: nocover
|
||||
warn(
|
||||
"Unable to load scaffold %s: %s" % (ep, e), RuntimeWarning
|
||||
)
|
||||
@@ -55,6 +55,6 @@ class CreateCommand(BaseCommand):
|
||||
|
||||
def run(self, args):
|
||||
super(CreateCommand, self).run(args)
|
||||
CreateCommand.manager.scaffolds[args.template_name]().copy_to(
|
||||
self.manager.scaffolds[args.template_name]().copy_to(
|
||||
args.project_name
|
||||
)
|
||||
|
||||
53
pecan/tests/test_commands.py
Normal file
53
pecan/tests/test_commands.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCommandManager(unittest.TestCase):
|
||||
|
||||
def test_commands(self):
|
||||
from pecan.commands import ServeCommand, ShellCommand, CreateCommand
|
||||
from pecan.commands.base import CommandManager
|
||||
m = CommandManager()
|
||||
assert m.commands['serve'] == ServeCommand
|
||||
assert m.commands['shell'] == ShellCommand
|
||||
assert m.commands['create'] == CreateCommand
|
||||
|
||||
|
||||
class TestCommandRunner(unittest.TestCase):
|
||||
|
||||
def test_commands(self):
|
||||
from pecan.commands import (
|
||||
ServeCommand, ShellCommand, CreateCommand, CommandRunner
|
||||
)
|
||||
runner = CommandRunner()
|
||||
assert runner.commands['serve'] == ServeCommand
|
||||
assert runner.commands['shell'] == ShellCommand
|
||||
assert runner.commands['create'] == CreateCommand
|
||||
|
||||
def test_run(self):
|
||||
from pecan.commands import CommandRunner
|
||||
runner = CommandRunner()
|
||||
with self.assertRaises(RuntimeError):
|
||||
runner.run(['serve', 'missing_file.py'])
|
||||
|
||||
|
||||
class TestCreateCommand(unittest.TestCase):
|
||||
|
||||
def test_run(self):
|
||||
from pecan.commands import CreateCommand
|
||||
|
||||
class FakeArg(object):
|
||||
project_name = 'default'
|
||||
template_name = 'default'
|
||||
|
||||
class FakeScaffold(object):
|
||||
def copy_to(self, project_name):
|
||||
assert project_name == 'default'
|
||||
|
||||
class FakeManager(object):
|
||||
scaffolds = {
|
||||
'default': FakeScaffold
|
||||
}
|
||||
|
||||
c = CreateCommand()
|
||||
c.manager = FakeManager()
|
||||
c.run(FakeArg())
|
||||
8
setup.py
8
setup.py
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
from setuptools import setup, command, find_packages
|
||||
from setuptools import setup, find_packages
|
||||
from setuptools.command.test import test as TestCommand
|
||||
|
||||
version = '0.1.0'
|
||||
@@ -17,15 +17,15 @@ requirements = [
|
||||
]
|
||||
|
||||
try:
|
||||
import json
|
||||
import json # noqa
|
||||
except:
|
||||
try:
|
||||
import simplejson
|
||||
import simplejson # noqa
|
||||
except:
|
||||
requirements.append("simplejson >= 2.1.1")
|
||||
|
||||
try:
|
||||
import argparse
|
||||
import argparse # noqa
|
||||
except:
|
||||
requirements.append('argparse')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user