mirror of
https://github.com/datafolklabs/cement.git
synced 2026-02-06 14:26:55 +00:00
Fix PEP8 Compliance Issues
This commit is contained in:
parent
5e8003b7c0
commit
b55680c5e2
3
Makefile
3
Makefile
@ -12,6 +12,9 @@ test:
|
||||
comply:
|
||||
flake8 cement/ tests/
|
||||
|
||||
comply-fix:
|
||||
autopep8 -ri cement/ tests/
|
||||
|
||||
docs:
|
||||
python setup.py build_sphinx
|
||||
@echo
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
from .core.foundation import App
|
||||
from .ext.ext_argparse import ArgparseController as Controller
|
||||
from .ext.ext_argparse import expose as ex
|
||||
|
||||
@ -52,9 +52,10 @@ class ArgumentHandlerBase(Handler):
|
||||
|
||||
Keyword Args:
|
||||
dest (str): The destination name (variable). Default: `args[0]`
|
||||
help (str): The help text for ``--help`` output (for that argument).
|
||||
action (str): Must support: ``['store', 'store_true', 'store_false',
|
||||
'store_const']``
|
||||
help (str): The help text for ``--help`` output (for that
|
||||
argument).
|
||||
action (str): Must support: ``['store', 'store_true',
|
||||
'store_false', 'store_const']``
|
||||
choices (list): A list of valid values that can be passed to an
|
||||
option whose action is ``store``.
|
||||
const (str): The value stored if ``action == 'store_const'``.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
"""Cement core config module."""
|
||||
|
||||
import os
|
||||
from abc import ABC, abstractmethod, abstractproperty
|
||||
from abc import abstractmethod
|
||||
from ..core.handler import Handler
|
||||
from ..utils.fs import abspath
|
||||
from ..utils.misc import minimal_logger
|
||||
@ -38,8 +38,8 @@ class ConfigHandlerBase(Handler):
|
||||
@abstractmethod
|
||||
def parse_file(self, file_path):
|
||||
"""
|
||||
Parse config file settings from ``file_path``. Returns True if the file
|
||||
existed, and was parsed successfully. Returns False otherwise.
|
||||
Parse config file settings from ``file_path``. Returns True if the
|
||||
file existed, and was parsed successfully. Returns False otherwise.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the config file to parse.
|
||||
|
||||
@ -1,10 +1,6 @@
|
||||
"""Cement core controller module."""
|
||||
|
||||
import re
|
||||
import textwrap
|
||||
import argparse
|
||||
from abc import abstractmethod
|
||||
from ..core import exc
|
||||
from ..core.handler import Handler
|
||||
from ..utils.misc import minimal_logger
|
||||
|
||||
@ -42,15 +38,16 @@ class ControllerHandlerBase(Handler):
|
||||
"""
|
||||
Reads the application object's data to dispatch a command from this
|
||||
controller. For example, reading ``self.app.pargs`` to determine what
|
||||
command was pass # pragma: nocovered, and then executing that command function.
|
||||
command was pass # pragma: nocovered, and then executing that
|
||||
command function.
|
||||
|
||||
Note that Cement does *not* parse arguments when calling ``_dispatch()``
|
||||
on a controller, as it expects the controller to handle parsing
|
||||
arguments (I.e. ``self.app.args.parse()``).
|
||||
Note that Cement does *not* parse arguments when calling
|
||||
``_dispatch()`` on a controller, as it expects the controller to
|
||||
handle parsing arguments (I.e. ``self.app.args.parse()``).
|
||||
|
||||
Returns:
|
||||
unknown: The result of the executed controller function, or ``None``
|
||||
if no controller function is called.
|
||||
unknown: The result of the executed controller function, or
|
||||
``None`` if no controller function is called.
|
||||
|
||||
"""
|
||||
pass # pragma: nocover
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
"""Cement core extensions module."""
|
||||
|
||||
import sys
|
||||
from abc import ABC, abstractmethod, abstractproperty
|
||||
from abc import abstractmethod
|
||||
from ..core import exc
|
||||
from ..core.handler import Handler
|
||||
from ..utils.misc import minimal_logger
|
||||
@ -74,7 +74,7 @@ class ExtensionHandler(ExtensionHandlerBase):
|
||||
class Meta:
|
||||
|
||||
"""
|
||||
Handler meta-data (can be pass # pragma: no covered as keyword arguments to the parent
|
||||
Handler meta-data (can be passed as keyword arguments to the parent
|
||||
class).
|
||||
"""
|
||||
|
||||
@ -134,7 +134,7 @@ class ExtensionHandler(ExtensionHandlerBase):
|
||||
|
||||
def load_extensions(self, ext_list):
|
||||
"""
|
||||
Given a list of extension modules, iterate over the list and pass # pragma: no cover
|
||||
Given a list of extension modules, iterate over the list and pass
|
||||
individually to ``self.load_extension()``.
|
||||
|
||||
Args:
|
||||
|
||||
@ -5,7 +5,7 @@ import sys
|
||||
import signal
|
||||
import platform
|
||||
from time import sleep
|
||||
from ..core import backend, exc, log, config, plugin
|
||||
from ..core import exc, log, config, plugin
|
||||
from ..core import output, extension, arg, controller, meta, cache, mail
|
||||
from ..core.handler import HandlerManager
|
||||
from ..core.hook import HookManager
|
||||
@ -197,10 +197,11 @@ class App(meta.MetaMixin):
|
||||
cement will load all files that ends with ``.conf``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
[
|
||||
'/etc/myapp/conf.d',
|
||||
'~/.config/myapp/conf.d',
|
||||
'~/.myapp/conf.d',
|
||||
'~/.myapp/conf.d'
|
||||
]
|
||||
|
||||
Directories and files inside are loaded in order, and have precedence
|
||||
@ -215,9 +216,9 @@ class App(meta.MetaMixin):
|
||||
|
||||
plugins = []
|
||||
"""
|
||||
A list of plugins to load. This is generally considered bad
|
||||
practice since plugins should be dynamically enabled/disabled
|
||||
via a plugin config file.
|
||||
A list of plugins to load. This is generally considered bad practice
|
||||
since plugins should be dynamically enabled/disabled via a plugin
|
||||
config file.
|
||||
"""
|
||||
|
||||
plugin_config_dirs = None
|
||||
@ -1043,7 +1044,8 @@ class App(meta.MetaMixin):
|
||||
@property
|
||||
def pargs(self):
|
||||
"""
|
||||
Returns the ``parsed_args`` object as returned by ``self.args.parse()``.
|
||||
Returns the ``parsed_args`` object as returned by
|
||||
``self.args.parse()``.
|
||||
"""
|
||||
return self._parsed_args
|
||||
|
||||
@ -1437,23 +1439,23 @@ class App(meta.MetaMixin):
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: python
|
||||
|
||||
import os
|
||||
from cement import App
|
||||
import os
|
||||
from cement import App
|
||||
|
||||
class MyApp(App):
|
||||
class Meta:
|
||||
label = 'myapp'
|
||||
class MyApp(App):
|
||||
class Meta:
|
||||
label = 'myapp'
|
||||
|
||||
def validate_config(self):
|
||||
super(MyApp, self).validate_config()
|
||||
def validate_config(self):
|
||||
super(MyApp, self).validate_config()
|
||||
|
||||
# test that the log file directory exist, if not create it
|
||||
logdir = os.path.dirname(self.config.get('log', 'file'))
|
||||
# test that the log file directory exist, if not create it
|
||||
logdir = os.path.dirname(self.config.get('log', 'file'))
|
||||
|
||||
if not os.path.exists(logdir):
|
||||
os.makedirs(logdir)
|
||||
if not os.path.exists(logdir):
|
||||
os.makedirs(logdir)
|
||||
|
||||
"""
|
||||
pass
|
||||
@ -1468,9 +1470,9 @@ class App(meta.MetaMixin):
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: python
|
||||
.. code-block:: python
|
||||
|
||||
app.add_template_dir('/path/to/my/templates')
|
||||
app.add_template_dir('/path/to/my/templates')
|
||||
|
||||
"""
|
||||
path = fs.abspath(path)
|
||||
|
||||
@ -4,7 +4,7 @@ Cement core handler module.
|
||||
"""
|
||||
|
||||
import re
|
||||
from abc import ABC, abstractproperty
|
||||
from abc import ABC
|
||||
from ..core import exc, meta
|
||||
from ..utils.misc import minimal_logger
|
||||
|
||||
@ -117,8 +117,8 @@ class HandlerManager(object):
|
||||
handler_label (str): The label of the handler (i.e. ``json``)
|
||||
|
||||
Keyword Args:
|
||||
fallback (Handler): A fallback value to return if handler_label doesn't
|
||||
exist.
|
||||
fallback (Handler): A fallback value to return if handler_label
|
||||
doesn't exist.
|
||||
|
||||
Returns:
|
||||
Handler: An uninstantiated handler object
|
||||
@ -308,7 +308,7 @@ class HandlerManager(object):
|
||||
raise exc.FrameworkError("Handler interface '%s' doesn't exist." %
|
||||
interface)
|
||||
if obj._meta.label in self.__handlers__[interface] and \
|
||||
self.__handlers__[interface][obj._meta.label] != handler_class:
|
||||
self.__handlers__[interface][obj._meta.label] != handler_class:
|
||||
|
||||
if force is True:
|
||||
LOG.debug(
|
||||
@ -326,7 +326,7 @@ class HandlerManager(object):
|
||||
|
||||
if not issubclass(handler_class, interface_class):
|
||||
raise exc.InterfaceError("Handler %s " % handler_class.__name__ +
|
||||
"does not sub-class %s" % \
|
||||
"does not sub-class %s" %
|
||||
interface_class.__name__)
|
||||
|
||||
self.__handlers__[interface][obj._meta.label] = handler_class
|
||||
|
||||
@ -4,7 +4,7 @@ Cement core log module.
|
||||
"""
|
||||
|
||||
# from ..core import interface
|
||||
from abc import ABC, abstractmethod, abstractproperty
|
||||
from abc import abstractmethod
|
||||
from ..core.handler import Handler
|
||||
|
||||
|
||||
@ -103,6 +103,7 @@ class LogHandlerBase(Handler):
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class LogHandler(LogHandlerBase):
|
||||
|
||||
"""
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
"""Cement core mail module."""
|
||||
|
||||
# from ..core import interface
|
||||
from abc import ABC, abstractmethod, abstractproperty
|
||||
from abc import abstractmethod
|
||||
from ..core.handler import Handler
|
||||
from ..utils.misc import minimal_logger
|
||||
|
||||
@ -87,6 +86,7 @@ class MailHandlerBase(Handler):
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class MailHandler(MailHandlerBase):
|
||||
|
||||
"""Mail handler implementation."""
|
||||
|
||||
@ -16,6 +16,7 @@ class Meta(object):
|
||||
for key in dict_obj.keys():
|
||||
setattr(self, key, dict_obj[key])
|
||||
|
||||
|
||||
class MetaMixin(object):
|
||||
|
||||
"""
|
||||
|
||||
@ -65,6 +65,7 @@ class OutputHandler(OutputHandlerBase):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class TemplateOutputHandler(OutputHandler):
|
||||
|
||||
"""Base class for template base output handlers."""
|
||||
|
||||
@ -7,7 +7,6 @@ from ..utils.misc import minimal_logger
|
||||
LOG = minimal_logger(__name__)
|
||||
|
||||
|
||||
|
||||
class PluginHandlerBase(Handler):
|
||||
|
||||
"""
|
||||
@ -70,6 +69,7 @@ class PluginHandlerBase(Handler):
|
||||
"""Returns a list of plugins that are disabled in the config."""
|
||||
pass
|
||||
|
||||
|
||||
class PluginHandler(PluginHandlerBase):
|
||||
|
||||
"""
|
||||
|
||||
@ -166,7 +166,6 @@ The above looks like:
|
||||
import re
|
||||
import sys
|
||||
from argparse import ArgumentParser, RawDescriptionHelpFormatter, SUPPRESS
|
||||
from ..core.handler import Handler
|
||||
from ..core.arg import ArgumentHandler
|
||||
from ..core.controller import ControllerHandler
|
||||
from ..core.exc import FrameworkError
|
||||
@ -316,9 +315,11 @@ class expose(object):
|
||||
func.__cement_meta__ = metadict
|
||||
return func
|
||||
|
||||
|
||||
# shortcut for cleaner controllers
|
||||
ex = expose
|
||||
|
||||
|
||||
class ArgparseController(ControllerHandler):
|
||||
|
||||
"""
|
||||
@ -342,7 +343,11 @@ class ArgparseController(ControllerHandler):
|
||||
description = 'description at the top of --help'
|
||||
epilog = "the text at the bottom of --help."
|
||||
arguments = [
|
||||
(['-f', '--foo'], dict(help='my foo option', dest='foo')),
|
||||
(
|
||||
['-f', '--foo'],
|
||||
{ 'help' : 'my foo option',
|
||||
'dest' : 'foo' }
|
||||
),
|
||||
]
|
||||
|
||||
class Second(ArgparseController):
|
||||
@ -351,7 +356,11 @@ class ArgparseController(ControllerHandler):
|
||||
stacked_on = 'base'
|
||||
stacked_type = 'embedded'
|
||||
arguments = [
|
||||
(['--foo2'], dict(help='my foo2 option', dest='foo2')),
|
||||
(
|
||||
['--foo2'],
|
||||
{ 'help' : 'my foo2 option',
|
||||
'dest' : 'foo2' }
|
||||
),
|
||||
]
|
||||
|
||||
"""
|
||||
|
||||
@ -124,7 +124,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
label = 'configparser'
|
||||
"""The string identifier of this handler."""
|
||||
|
||||
|
||||
def merge(self, dict_obj, override=True):
|
||||
"""
|
||||
Merge a dictionary into our config. If override is True then
|
||||
@ -155,7 +154,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
# we don't support nested config blocks, so no need to go
|
||||
# further down to more nested dicts.
|
||||
|
||||
|
||||
def _parse_file(self, file_path):
|
||||
"""
|
||||
Parse a configuration file at ``file_path`` and store it.
|
||||
@ -173,7 +171,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
# will likely raise an exception anyhow.
|
||||
return True
|
||||
|
||||
|
||||
def keys(self, section):
|
||||
"""
|
||||
Return a list of keys within ``section``.
|
||||
@ -187,7 +184,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
"""
|
||||
return self.options(section)
|
||||
|
||||
|
||||
def get_dict(self):
|
||||
"""
|
||||
Return a dict of the entire configuration.
|
||||
@ -200,7 +196,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
_config[section] = self.get_section_dict(section)
|
||||
return _config
|
||||
|
||||
|
||||
def get_sections(self):
|
||||
"""
|
||||
Return a list of configuration sections.
|
||||
@ -211,7 +206,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
"""
|
||||
return self.sections()
|
||||
|
||||
|
||||
def get_section_dict(self, section):
|
||||
"""
|
||||
Return a dict representation of a section.
|
||||
@ -228,7 +222,6 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
dict_obj[key] = self.get(section, key)
|
||||
return dict_obj
|
||||
|
||||
|
||||
def add_section(self, section):
|
||||
"""
|
||||
Adds a block section to the config.
|
||||
@ -239,18 +232,17 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
"""
|
||||
return RawConfigParser.add_section(self, section)
|
||||
|
||||
|
||||
def _get_env_var(self, section, key):
|
||||
if section == self.app._meta.config_section:
|
||||
env_var = "%s_%s" % (self.app._meta.config_section, key)
|
||||
else:
|
||||
env_var = "%s_%s_%s" % (self.app._meta.config_section, section, key)
|
||||
env_var = "%s_%s_%s" % (
|
||||
self.app._meta.config_section, section, key)
|
||||
|
||||
env_var = env_var.upper()
|
||||
env_var = re.sub('[^0-9a-zA-Z]+', '_', env_var)
|
||||
return env_var
|
||||
|
||||
|
||||
def get(self, section, key):
|
||||
env_var = self._get_env_var(section, key)
|
||||
if env_var in os.environ.keys():
|
||||
@ -258,11 +250,9 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
|
||||
else:
|
||||
return RawConfigParser.get(self, section, key)
|
||||
|
||||
|
||||
def has_section(self, section):
|
||||
return RawConfigParser.has_section(self, section)
|
||||
|
||||
|
||||
def set(self, section, key, value):
|
||||
return RawConfigParser.set(self, section, key, value)
|
||||
|
||||
|
||||
@ -150,7 +150,7 @@ more information on partials.
|
||||
|
||||
import sys
|
||||
import pybars._compiler
|
||||
from cement.core import output, handler
|
||||
from cement.core import output
|
||||
from cement.utils.misc import minimal_logger
|
||||
|
||||
# Monkey patch so we don't escape HTML (not clear how else to do this)
|
||||
|
||||
@ -97,7 +97,7 @@ LOG = minimal_logger(__name__)
|
||||
|
||||
def extend_print(app):
|
||||
def _print(text):
|
||||
app.render({'out' : text}, handler='print')
|
||||
app.render({'out': text}, handler='print')
|
||||
app.extend('print', _print)
|
||||
|
||||
|
||||
@ -123,7 +123,6 @@ class PrintOutputHandler(output.OutputHandler):
|
||||
#: to override the ``output_handler`` via command line options.
|
||||
overridable = False
|
||||
|
||||
|
||||
def render(self, data_dict, template=None, **kw):
|
||||
"""
|
||||
Take a data dictionary and render only the ``out`` key as text output.
|
||||
@ -144,7 +143,8 @@ class PrintOutputHandler(output.OutputHandler):
|
||||
LOG.debug("rendering output as text via %s" % self.__module__)
|
||||
return data_dict['out'] + '\n'
|
||||
else:
|
||||
LOG.debug("no 'out' key found in data dict. not rendering output via %s" % self.__module__)
|
||||
LOG.debug("no 'out' key found in data dict. "
|
||||
"not rendering output via %s" % self.__module__)
|
||||
return None
|
||||
|
||||
|
||||
@ -168,7 +168,6 @@ class PrintDictOutputHandler(output.OutputHandler):
|
||||
#: to override the ``output_handler`` via command line options.
|
||||
overridable = False
|
||||
|
||||
|
||||
def render(self, data_dict, template=None, **kw):
|
||||
"""
|
||||
Take a data dictionary and render it as text output. Note that the
|
||||
@ -187,7 +186,7 @@ class PrintDictOutputHandler(output.OutputHandler):
|
||||
"""
|
||||
LOG.debug("rendering output as text via %s" % self.__module__)
|
||||
out = ''
|
||||
for key,val in data_dict.items():
|
||||
for key, val in data_dict.items():
|
||||
out = out + '%s: %s\n' % (key, val)
|
||||
|
||||
return out
|
||||
|
||||
@ -67,7 +67,6 @@ Looks like:
|
||||
"""
|
||||
|
||||
import re
|
||||
from .. import Controller
|
||||
from ..utils.misc import minimal_logger
|
||||
|
||||
LOG = minimal_logger(__name__)
|
||||
@ -84,7 +83,7 @@ def extend_scrub(app):
|
||||
if not hasattr(app._meta, 'scrub') or app._meta.scrub is None:
|
||||
return text
|
||||
elif isinstance(text, str):
|
||||
for regex,replace in app._meta.scrub:
|
||||
for regex, replace in app._meta.scrub:
|
||||
text = re.sub(regex, replace, text)
|
||||
else:
|
||||
LOG.debug('text is not str > %s' % type(text))
|
||||
@ -106,6 +105,7 @@ def extend_scrub(app):
|
||||
help=arg_help,
|
||||
action='store_true')
|
||||
|
||||
|
||||
def load(app):
|
||||
app.hook.register('post_render', scrub_output)
|
||||
app.hook.register('pre_argument_parsing', extend_scrub)
|
||||
|
||||
@ -200,7 +200,8 @@ class YamlConfigHandler(ConfigParserConfigHandler):
|
||||
existing config settings. If the file does not exist, returns False.
|
||||
|
||||
Args:
|
||||
file_path (str): The file system path to the Yaml configuration file.
|
||||
file_path (str): The file system path to the Yaml configuration
|
||||
file.
|
||||
|
||||
"""
|
||||
self.merge(yaml.load(open(file_path)))
|
||||
|
||||
@ -175,7 +175,8 @@ def minimal_logger(namespace, debug=False):
|
||||
|
||||
def is_true(item):
|
||||
"""
|
||||
Given a value, determine if it is one of ``[True, 'True', 'true', 1, '1']``.
|
||||
Given a value, determine if it is one of
|
||||
``[True, 'True', 'true', 1, '1']``.
|
||||
|
||||
Args:
|
||||
item: The item to convert to a boolean.
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
"""Cement testing utilities."""
|
||||
|
||||
# flake8: noqa
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from pytest import raises, skip
|
||||
@ -7,123 +9,3 @@ from ..core.foundation import TestApp
|
||||
from ..core.exc import *
|
||||
from ..utils.misc import rando
|
||||
from ..utils import fs, shell
|
||||
|
||||
|
||||
#
|
||||
# import os
|
||||
# import unittest
|
||||
# import shutil
|
||||
# from tempfile import mkstemp, mkdtemp
|
||||
# from ..core.foundation import App
|
||||
# from ..core import backend
|
||||
# from ..utils.misc import rando
|
||||
|
||||
# shortcuts
|
||||
# from nose import SkipTest # noqa
|
||||
# from nose.tools import raises # noqa
|
||||
# from nose.tools import ok_ as ok
|
||||
# from nose.tools import eq_ as eq
|
||||
# from nose.plugins.attrib import attr
|
||||
|
||||
|
||||
# class TestApp(App):
|
||||
#
|
||||
# """
|
||||
# Basic app for generic testing.
|
||||
#
|
||||
# """
|
||||
# class Meta:
|
||||
# label = "app-%s" % rando()[:12]
|
||||
# config_files = []
|
||||
# argv = []
|
||||
# base_controller = None
|
||||
# arguments = []
|
||||
# exit_on_close = False
|
||||
|
||||
|
||||
# class CementTestCase(unittest.TestCase):
|
||||
#
|
||||
# """
|
||||
# A sub-class of unittest.TestCase.
|
||||
#
|
||||
# """
|
||||
#
|
||||
# app_class = TestApp
|
||||
# """The test class that is used by self.make_app to create an app."""
|
||||
#
|
||||
# def __init__(self, *args, **kw):
|
||||
# super(CementTestCase, self).__init__(*args, **kw)
|
||||
# self.tmp_file_handle = None
|
||||
# self.tmp_file = None
|
||||
# self.tmp_dir = None
|
||||
# self.rando = None
|
||||
#
|
||||
# def setUp(self):
|
||||
# """
|
||||
# Sets up self.app with a generic ``TestApp()``. Also resets the backend
|
||||
# hooks and handlers so that everytime an app is created it is setup
|
||||
# clean each time.
|
||||
#
|
||||
# """
|
||||
# self.app = self.make_app()
|
||||
#
|
||||
# # recreate temp file and dir for each test
|
||||
# _prefix = "cement.tests.%s.tmp" % self.__class__.__name__
|
||||
# self.tmp_file_handle, self.tmp_file = mkstemp(prefix=_prefix)
|
||||
# self.tmp_dir = mkdtemp(prefix=_prefix)
|
||||
#
|
||||
# # create a random string for each test (useful to verify things
|
||||
# # uniquely so every test isn't using the same "My Test String")
|
||||
# self.rando = rando()[:12]
|
||||
#
|
||||
# def tearDown(self):
|
||||
# """
|
||||
# Tears down the test environment (if necessary), removes any temporary
|
||||
# files/directories, etc.
|
||||
# """
|
||||
# if os.path.exists(self.tmp_file):
|
||||
# os.close(self.tmp_file_handle)
|
||||
# os.remove(self.tmp_file)
|
||||
# if os.path.exists(self.tmp_dir):
|
||||
# shutil.rmtree(self.tmp_dir)
|
||||
#
|
||||
# def make_app(self, *args, **kw):
|
||||
# """
|
||||
# Create a generic app using TestApp. Arguments and Keyword Arguments
|
||||
# are passed to the app.
|
||||
#
|
||||
# """
|
||||
# self.reset_backend()
|
||||
# return self.app_class(*args, **kw)
|
||||
#
|
||||
# def reset_backend(self):
|
||||
# """
|
||||
# Remove all registered hooks and handlers from the backend.
|
||||
#
|
||||
# """
|
||||
#
|
||||
# # FIXME: This should not be needed anymore once we fully remove
|
||||
# # backend_globals (Cement 3)
|
||||
# for _handler in backend.__handlers__.copy():
|
||||
# del backend.__handlers__[_handler]
|
||||
# for _hook in backend.__hooks__.copy():
|
||||
# del backend.__hooks__[_hook]
|
||||
#
|
||||
# def ok(self, expr, msg=None):
|
||||
# """Shorthand for assert."""
|
||||
# return ok(expr, msg)
|
||||
#
|
||||
# def eq(self, a, b, msg=None):
|
||||
# """Shorthand for 'assert a == b, "%r != %r" % (a, b)'. """
|
||||
# return eq(a, b, msg)
|
||||
#
|
||||
#
|
||||
# # The following are for internal, Cement unit testing only
|
||||
# @attr('core')
|
||||
# class CementCoreTestCase(CementTestCase):
|
||||
# pass
|
||||
#
|
||||
#
|
||||
# @attr('ext')
|
||||
# class CementExtTestCase(CementTestCase):
|
||||
# pass
|
||||
|
||||
@ -5,6 +5,7 @@ import pytest
|
||||
from cement.utils.misc import rando as _rando
|
||||
from tempfile import mkstemp, mkdtemp
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def tmp(request):
|
||||
class Tmp(object):
|
||||
@ -18,10 +19,12 @@ def tmp(request):
|
||||
if os.path.exists(t.dir):
|
||||
shutil.rmtree(t.dir)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def key(request):
|
||||
yield _rando()
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def rando(request):
|
||||
yield _rando()
|
||||
|
||||
@ -1,12 +1,8 @@
|
||||
|
||||
from pytest import raises
|
||||
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.core.arg import ArgumentHandlerBase, ArgumentHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestArgumentHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -30,4 +26,4 @@ class TestArgumentHandler(object):
|
||||
assert h._meta.label == 'my_argument_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
|
||||
from cement.core import backend
|
||||
|
||||
|
||||
def test_version():
|
||||
### ensure that we bump things properly on version changes
|
||||
# ensure that we bump things properly on version changes
|
||||
assert backend.VERSION[0] == 2
|
||||
assert backend.VERSION[1] == 99
|
||||
assert backend.VERSION[2] == 1
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
from cement.core.cache import CacheHandlerBase, CacheHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestCacheHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -31,4 +31,4 @@ class TestCacheHandler(object):
|
||||
assert h._meta.interface == 'cache'
|
||||
assert h._meta.label == 'my_cache_handler'
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
|
||||
from pytest import raises
|
||||
from cement.core.config import ConfigHandlerBase, ConfigHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class MyConfigHandler(ConfigHandler):
|
||||
class Meta:
|
||||
@ -20,7 +19,7 @@ class MyConfigHandler(ConfigHandler):
|
||||
|
||||
def get_dict(self, *args, **kw):
|
||||
pass
|
||||
|
||||
|
||||
def get_sections(self, *args, **kw):
|
||||
pass
|
||||
|
||||
@ -59,4 +58,4 @@ class TestConfigHandler(object):
|
||||
assert h.parse_file(tmp.file)
|
||||
assert not h.parse_file('/path/to/some/bogus/file')
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
from cement.core.controller import ControllerHandlerBase, ControllerHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestControllerHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -22,4 +22,4 @@ class TestControllerHandler(object):
|
||||
assert h._meta.interface == 'controller'
|
||||
assert h._meta.label == 'my_controller_handler'
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
@ -2,13 +2,14 @@
|
||||
from pytest import raises
|
||||
from cement.core.exc import FrameworkError, InterfaceError, CaughtSignal
|
||||
|
||||
|
||||
class TestExceptions(object):
|
||||
def test_frameworkerror(self):
|
||||
with raises(FrameworkError, match=".*framework exception.*") as e:
|
||||
with raises(FrameworkError, match=".*framework exception.*"):
|
||||
raise FrameworkError("test framework exception message")
|
||||
|
||||
def test_interfaceerror(self):
|
||||
with raises(InterfaceError, match=".*interface exception.*") as e:
|
||||
with raises(InterfaceError, match=".*interface exception.*"):
|
||||
raise InterfaceError("test interface exception message")
|
||||
|
||||
def test_caughtsignal(self):
|
||||
|
||||
@ -7,7 +7,7 @@ from cement.core.exc import FrameworkError
|
||||
from cement.core.extension import ExtensionHandlerBase, ExtensionHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestExtensionHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -31,7 +31,7 @@ class TestExtensionHandler(object):
|
||||
assert h._meta.label == 'my_extension_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
|
||||
class Bogus(Handler):
|
||||
@ -76,6 +76,7 @@ def test_load_bogus_extension():
|
||||
ext._setup(app)
|
||||
ext.load_extensions(['bogus'])
|
||||
|
||||
|
||||
def test_get_loaded_extensions():
|
||||
with TestApp() as app:
|
||||
ext = ExtensionHandler()
|
||||
|
||||
@ -17,6 +17,7 @@ from cement.core.foundation import cement_signal_handler
|
||||
from cement.utils.misc import minimal_logger, init_defaults
|
||||
from cement.utils import test, fs, misc
|
||||
|
||||
|
||||
def test_add_handler_override_options():
|
||||
class MyApp(TestApp):
|
||||
class Meta:
|
||||
@ -29,7 +30,7 @@ def test_add_handler_override_options():
|
||||
|
||||
# coverage for case where the interface doesn't exist
|
||||
app._meta.handler_override_options = {
|
||||
'bogus' : ( ['--bogus'], { 'help' : 'bogus handler' } ),
|
||||
'bogus': (['--bogus'], {'help': 'bogus handler'}),
|
||||
}
|
||||
add_handler_override_options(app)
|
||||
|
||||
@ -68,13 +69,11 @@ def test_cement_signal_handler():
|
||||
|
||||
class TestFoundation(object):
|
||||
|
||||
|
||||
def test_basic(self):
|
||||
with TestApp() as app:
|
||||
assert re.match('app-.*', app._meta.label)
|
||||
app.run()
|
||||
|
||||
|
||||
def test_loaded(self):
|
||||
class MyApp(TestApp):
|
||||
class Meta:
|
||||
@ -98,7 +97,6 @@ class TestFoundation(object):
|
||||
with MyApp() as app:
|
||||
app.run()
|
||||
|
||||
|
||||
def test_argv(self):
|
||||
with TestApp(argv=None) as app:
|
||||
assert app.argv == list(sys.argv[1:])
|
||||
@ -106,41 +104,38 @@ class TestFoundation(object):
|
||||
with TestApp(argv=['bogus', 'args']) as app:
|
||||
assert app.argv == ['bogus', 'args']
|
||||
|
||||
|
||||
def test_framework_logging(self):
|
||||
### is true
|
||||
# is true
|
||||
|
||||
del os.environ['CEMENT_FRAMEWORK_LOGGING']
|
||||
|
||||
with TestApp(framework_logging=True) as app:
|
||||
with TestApp(framework_logging=True):
|
||||
assert os.environ['CEMENT_FRAMEWORK_LOGGING'] == '1'
|
||||
|
||||
ml = minimal_logger(__name__)
|
||||
assert ml.logging_is_enabled is True
|
||||
|
||||
### is false
|
||||
# is false
|
||||
|
||||
del os.environ['CEMENT_FRAMEWORK_LOGGING']
|
||||
|
||||
with TestApp(framework_logging=False) as app:
|
||||
with TestApp(framework_logging=False):
|
||||
assert os.environ['CEMENT_FRAMEWORK_LOGGING'] == '0'
|
||||
|
||||
ml = minimal_logger(__name__)
|
||||
assert ml.logging_is_enabled is False
|
||||
|
||||
|
||||
def test_bootstrap(self):
|
||||
with TestApp(bootstrap='tests.bootstrap') as app:
|
||||
assert app._loaded_bootstrap.__name__ == 'tests.bootstrap'
|
||||
|
||||
### reload
|
||||
# reload
|
||||
|
||||
app = TestApp(bootstrap='cement.utils.test')
|
||||
app._loaded_bootstrap = test
|
||||
app.setup()
|
||||
assert app._loaded_bootstrap.__name__ == 'cement.utils.test'
|
||||
|
||||
|
||||
def test_resolve_bad_handler(self):
|
||||
class Bogus(object):
|
||||
pass
|
||||
@ -149,7 +144,6 @@ class TestFoundation(object):
|
||||
with TestApp() as app:
|
||||
app._resolve_handler('output', Bogus)
|
||||
|
||||
|
||||
def test_passed_handlers(self):
|
||||
# forces App._resolve_handler to register the handler by class
|
||||
from cement.core.extension import ExtensionHandler
|
||||
@ -169,12 +163,11 @@ class TestFoundation(object):
|
||||
plugin_handler = CementPluginHandler()
|
||||
output_handler = JsonOutputHandler()
|
||||
mail_handler = DummyMailHandler()
|
||||
argv = [ __file__, '--debug' ]
|
||||
argv = [__file__, '--debug']
|
||||
|
||||
with MyApp() as app:
|
||||
with MyApp():
|
||||
pass
|
||||
|
||||
|
||||
def test_debug(self):
|
||||
# default
|
||||
with TestApp() as app:
|
||||
@ -190,7 +183,6 @@ class TestFoundation(object):
|
||||
with TestApp('my-app-test', config_defaults=defaults) as app:
|
||||
assert app.debug is True
|
||||
|
||||
|
||||
def test_render(self, tmp):
|
||||
# defaults
|
||||
with TestApp() as app:
|
||||
@ -223,7 +215,6 @@ class TestFoundation(object):
|
||||
app.run()
|
||||
app.render(dict(foo='bar'), out='bogus type')
|
||||
|
||||
|
||||
def test_label(self):
|
||||
# bad label
|
||||
with pytest.raises(FrameworkError):
|
||||
@ -233,27 +224,26 @@ class TestFoundation(object):
|
||||
with pytest.raises(FrameworkError, match="alpha-numeric"):
|
||||
App('some!bogus()label')
|
||||
|
||||
|
||||
|
||||
def test_add_arg_shortcut(self):
|
||||
with TestApp() as app:
|
||||
app.add_arg('--foo', action='store')
|
||||
|
||||
|
||||
def test_reset_output_handler(self):
|
||||
class ThisApp(TestApp):
|
||||
class Meta:
|
||||
extensions = ['mustache']
|
||||
output_handler = 'mustache'
|
||||
|
||||
with TestApp(extensions=['mustache'], output_handler='mustache') as app:
|
||||
with ThisApp() as app:
|
||||
app.run()
|
||||
app.output = None
|
||||
app._meta.output_handler = None
|
||||
app._setup_output_handler()
|
||||
|
||||
|
||||
def test_without_signals(self):
|
||||
with TestApp(catch_signals=None) as app:
|
||||
assert app._meta.catch_signals is None
|
||||
|
||||
|
||||
def test_extend(self):
|
||||
def my_extended_func():
|
||||
return 'KAPLA!'
|
||||
@ -266,13 +256,11 @@ class TestFoundation(object):
|
||||
with pytest.raises(FrameworkError, match=".* already exists!"):
|
||||
app.extend('kapla', my_extended_func)
|
||||
|
||||
|
||||
def test_no_handler(self):
|
||||
# coverage
|
||||
with TestApp() as app:
|
||||
app._resolve_handler('cache', None, raise_error=False)
|
||||
|
||||
|
||||
def test_config_files_is_none(self):
|
||||
# verify the autogenerated config files list
|
||||
with TestApp('test-app', config_files=None) as app:
|
||||
@ -285,35 +273,31 @@ class TestFoundation(object):
|
||||
for f in files:
|
||||
assert f in app._meta.config_files
|
||||
|
||||
|
||||
def test_base_controller_label(self):
|
||||
class BogusBaseController(Controller):
|
||||
class Meta:
|
||||
label = 'bad_base_controller_label'
|
||||
|
||||
with pytest.raises(FrameworkError, match="must have a label of 'base'"):
|
||||
with TestApp(base_controller=BogusBaseController) as app:
|
||||
msg = "must have a label of 'base'"
|
||||
with pytest.raises(FrameworkError, match=msg):
|
||||
with TestApp(base_controller=BogusBaseController):
|
||||
pass
|
||||
|
||||
|
||||
def test_pargs(self):
|
||||
with TestApp(argv=['--debug']) as app:
|
||||
app.run()
|
||||
assert app.pargs.debug is True
|
||||
|
||||
|
||||
def test_last_rendered(self):
|
||||
with TestApp() as app:
|
||||
output_text = app.render({'foo': 'bar'})
|
||||
assert app.last_rendered == ( {'foo': 'bar'}, output_text )
|
||||
|
||||
assert app.last_rendered == ({'foo': 'bar'}, output_text)
|
||||
|
||||
def test_get_last_rendered(self):
|
||||
# DEPRECATED - REMOVE AFTER THE FUNCTION IS REMOVED
|
||||
with TestApp() as app:
|
||||
output_text = app.render({'foo': 'bar'})
|
||||
assert app.get_last_rendered() == ( {'foo': 'bar'}, output_text )
|
||||
|
||||
assert app.get_last_rendered() == ({'foo': 'bar'}, output_text)
|
||||
|
||||
def test_close_with_code(self):
|
||||
with pytest.raises(SystemExit) as e:
|
||||
@ -322,13 +306,12 @@ class TestFoundation(object):
|
||||
app.close(114)
|
||||
assert e.value.code == 114
|
||||
|
||||
### test bad code
|
||||
# test bad code
|
||||
with pytest.raises(AssertionError, match='Invalid exit status code'):
|
||||
with TestApp() as app:
|
||||
app.run()
|
||||
app.close('Not An Int')
|
||||
|
||||
|
||||
# def test_suppress_output_while_debug(self):
|
||||
# # coverage?
|
||||
# with TestApp(debug=True) as app:
|
||||
@ -342,12 +325,10 @@ class TestFoundation(object):
|
||||
# with TestApp(config_defaults=defaults) as app:
|
||||
# app.run()
|
||||
|
||||
|
||||
def test_define_hooks_via_meta(self):
|
||||
with TestApp(define_hooks=['my_custom_hook']) as app:
|
||||
assert app.hook.defined('my_custom_hook') is True
|
||||
|
||||
|
||||
def test_register_hooks_via_meta(self):
|
||||
def my_custom_hook_func():
|
||||
return 'OK'
|
||||
@ -358,7 +339,6 @@ class TestFoundation(object):
|
||||
for res in app.hook.run('my_custom_hook'):
|
||||
assert res == "OK"
|
||||
|
||||
|
||||
def test_register_hooks_via_meta_retry(self):
|
||||
# hooks registered this way for non-framework hooks need to be retried
|
||||
# so we make sure it's actually being registered.
|
||||
@ -370,7 +350,6 @@ class TestFoundation(object):
|
||||
with app:
|
||||
assert len(app.hook.__hooks__['watchdog_pre_start']) == 1
|
||||
|
||||
|
||||
def test_define_handlers_via_meta(self):
|
||||
class MyTestHandler(Handler):
|
||||
class Meta:
|
||||
@ -380,7 +359,6 @@ class TestFoundation(object):
|
||||
with TestApp(define_handlers=[MyTestHandler]) as app:
|
||||
assert app.handler.defined('my_test_interface')
|
||||
|
||||
|
||||
def test_register_handlers_via_meta(self):
|
||||
class MyTestHandler(Handler):
|
||||
class Meta:
|
||||
@ -390,8 +368,8 @@ class TestFoundation(object):
|
||||
app = TestApp(define_handlers=[MyTestHandler],
|
||||
handlers=[MyTestHandler])
|
||||
with app:
|
||||
assert app.handler.registered('my_test_interface', 'my_test_handler')
|
||||
|
||||
assert app.handler.registered(
|
||||
'my_test_interface', 'my_test_handler')
|
||||
|
||||
def test_reload(self):
|
||||
class MyTestHandler(Handler):
|
||||
@ -415,7 +393,6 @@ class TestFoundation(object):
|
||||
|
||||
app.run()
|
||||
|
||||
|
||||
def test_run_forever(self):
|
||||
class MyController(Controller):
|
||||
class Meta:
|
||||
@ -440,7 +417,6 @@ class TestFoundation(object):
|
||||
|
||||
signal.alarm(0)
|
||||
|
||||
|
||||
def test_add_remove_template_directory(self, tmp):
|
||||
with TestApp() as app:
|
||||
app.add_template_dir(tmp.dir)
|
||||
@ -449,14 +425,12 @@ class TestFoundation(object):
|
||||
app.remove_template_dir(tmp.dir)
|
||||
assert tmp.dir not in app._meta.template_dirs
|
||||
|
||||
|
||||
def test_alternative_module_mapping(self):
|
||||
# coverage
|
||||
with TestApp(alternative_module_mapping=dict(time='time')) as app:
|
||||
app.__import__('time')
|
||||
app.__import__('sleep', from_module='time')
|
||||
|
||||
|
||||
def test_meta_defaults(self):
|
||||
DEBUG_FORMAT = "TEST DEBUG FORMAT - %s" % misc.rando
|
||||
META = {}
|
||||
|
||||
@ -2,16 +2,15 @@
|
||||
from pytest import raises
|
||||
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.core.handler import Handler, HandlerManager
|
||||
from cement.core.handler import Handler
|
||||
from cement.core.meta import MetaMixin
|
||||
from cement.core.exc import FrameworkError, InterfaceError
|
||||
from cement.core.output import OutputHandler
|
||||
from cement.utils import test
|
||||
from cement.ext.ext_configparser import ConfigParserConfigHandler
|
||||
from cement.ext.ext_dummy import DummyOutputHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestHandler(object):
|
||||
def test_subclassing(self):
|
||||
@ -29,8 +28,7 @@ class TestHandlerManager(object):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
|
||||
def test_get_invalid_handler():
|
||||
@ -53,13 +51,13 @@ def test_register_invalid_handlers():
|
||||
interface = 'output'
|
||||
# label = 'bogus4'
|
||||
|
||||
|
||||
with TestApp() as app:
|
||||
msg = 'Class .*BogusHandlerNoMeta.* does not implement Handler'
|
||||
with raises(InterfaceError, match=msg):
|
||||
app.handler.register(BogusHandlerNoMeta)
|
||||
|
||||
msg = 'Class .*BogusHandlerNoMetaInterface.* does not implement Handler'
|
||||
msg = 'Class .*BogusHandlerNoMetaInterface.* does not implement ' + \
|
||||
'Handler'
|
||||
with raises(InterfaceError, match=msg):
|
||||
app.handler.register(BogusHandlerNoMetaInterface)
|
||||
|
||||
|
||||
@ -1,19 +1,17 @@
|
||||
"""Tests for cement.core.hook."""
|
||||
|
||||
from pytest import raises
|
||||
|
||||
from cement.core.hook import HookManager
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.core.foundation import TestApp
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestHookManager(object):
|
||||
pass
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
def test_define():
|
||||
with TestApp() as app:
|
||||
|
||||
@ -7,7 +7,7 @@ from cement.core.foundation import TestApp
|
||||
from cement.core.log import LogHandlerBase, LogHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestLogHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -23,31 +23,24 @@ class TestLogHandler(object):
|
||||
class Meta:
|
||||
label = 'my_log_handler'
|
||||
|
||||
|
||||
def set_level(self):
|
||||
pass
|
||||
|
||||
|
||||
def get_level(self):
|
||||
pass
|
||||
|
||||
|
||||
def info(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
def warning(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
def error(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
def fatal(self, msg):
|
||||
pass
|
||||
|
||||
|
||||
def debug(self, msg):
|
||||
pass
|
||||
|
||||
@ -56,7 +49,7 @@ class TestLogHandler(object):
|
||||
assert h._meta.label == 'my_log_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
|
||||
def test_unproviding_handler():
|
||||
|
||||
@ -1,12 +1,8 @@
|
||||
|
||||
from pytest import raises
|
||||
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.core.mail import MailHandlerBase, MailHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestMailHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -27,4 +23,4 @@ class TestMailHandler(object):
|
||||
assert h._meta.label == 'my_mail_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
from cement.core.meta import Meta, MetaMixin
|
||||
|
||||
|
||||
class TestMeta(object):
|
||||
def test_meta(self):
|
||||
m = Meta(key='value')
|
||||
|
||||
@ -4,10 +4,11 @@ from pytest import raises
|
||||
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.core.output import OutputHandlerBase, OutputHandler, TemplateOutputHandler
|
||||
from cement.core.output import OutputHandlerBase, OutputHandler
|
||||
from cement.core.output import TemplateOutputHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestOutputHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -23,7 +24,6 @@ class TestOutputHandler(object):
|
||||
def render(self, *args, **kw):
|
||||
pass
|
||||
|
||||
|
||||
h = MyOutputHandler()
|
||||
assert h._meta.interface == 'output'
|
||||
assert h._meta.label == 'my_output_handler'
|
||||
@ -38,13 +38,12 @@ class TestTemplateOutputHandler(object):
|
||||
def render(self, *args, **kw):
|
||||
pass
|
||||
|
||||
|
||||
h = MyTemplateOutputHandler()
|
||||
assert h._meta.interface == 'output'
|
||||
assert h._meta.label == 'my_template_output_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
TEST_TEMPLATE = "%(foo)s"
|
||||
|
||||
@ -73,8 +72,8 @@ def test_load_template_from_file(tmp):
|
||||
|
||||
with MyApp() as app:
|
||||
app.run()
|
||||
assert app.render({'foo' : 'bar'}, 'mytemplate.txt') == 'bar'
|
||||
assert app.render({'foo': 'bar'}, 'mytemplate.txt') == 'bar'
|
||||
|
||||
# try and render a missing template
|
||||
with raises(FrameworkError, match='Could not locate template: .*'):
|
||||
app.render({'foo' : 'bar'}, 'missing-template.txt')
|
||||
app.render({'foo': 'bar'}, 'missing-template.txt')
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from pytest import raises
|
||||
|
||||
from cement import init_defaults
|
||||
@ -10,7 +9,7 @@ from cement.core.exc import FrameworkError
|
||||
from cement.core.plugin import PluginHandlerBase, PluginHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestPluginHandlerBase(object):
|
||||
def test_interface(self):
|
||||
@ -25,23 +24,18 @@ class TestPluginHandler(object):
|
||||
class Meta:
|
||||
label = 'my_plugin_handler'
|
||||
|
||||
|
||||
def load_plugin(plugin_name):
|
||||
pass
|
||||
|
||||
|
||||
def load_plugins(self, plugins):
|
||||
pass
|
||||
|
||||
|
||||
def get_loaded_plugins(self):
|
||||
pass
|
||||
|
||||
|
||||
def get_enabled_plugins(self):
|
||||
pass
|
||||
|
||||
|
||||
def get_disabled_plugins(self):
|
||||
pass
|
||||
|
||||
@ -50,7 +44,7 @@ class TestPluginHandler(object):
|
||||
assert h._meta.label == 'my_plugin_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
CONF1 = """
|
||||
[myplugin]
|
||||
@ -117,8 +111,8 @@ def test_load_plugins_from_files(tmp):
|
||||
|
||||
|
||||
def test_load_order_presedence_one(tmp):
|
||||
# app config defines it as enabled, but the plugin config has it disabled...
|
||||
# app trumps the config
|
||||
# app config defines it as enabled, but the plugin config has it
|
||||
# disabled... app trumps the config
|
||||
defaults = init_defaults('myplugin')
|
||||
defaults['myplugin']['enable_plugin'] = True
|
||||
|
||||
@ -347,9 +341,10 @@ def test_bad_plugin_dir(tmp):
|
||||
plugin_bootstrap = None
|
||||
|
||||
with raises(FrameworkError, match="Unable to load plugin 'myplugin'."):
|
||||
with MyApp() as app:
|
||||
with MyApp():
|
||||
pass
|
||||
|
||||
|
||||
def test_load_plugin_from_module(tmp):
|
||||
# We mock this out by loading a cement ext, but it is essentially the
|
||||
# same type of code.
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
import time
|
||||
import signal
|
||||
from pytest import raises
|
||||
from mock import Mock
|
||||
from cement.core.exc import CaughtSignal
|
||||
from cement.core.foundation import TestApp
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
|
||||
import sys
|
||||
import re
|
||||
from pytest import raises, skip
|
||||
from argparse import ArgumentError
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.ext.ext_argparse import ArgparseArgumentHandler
|
||||
from cement.ext.ext_argparse import ArgparseController, expose
|
||||
from cement.ext.ext_argparse import _clean_label, _clean_func
|
||||
from cement.core.exc import InterfaceError, FrameworkError
|
||||
from cement.core.exc import FrameworkError
|
||||
|
||||
|
||||
if (sys.version_info[0] >= 3 and sys.version_info[1] >= 4):
|
||||
@ -234,7 +233,7 @@ class Aliases(ArgparseController):
|
||||
class ArgparseApp(TestApp):
|
||||
class Meta:
|
||||
argument_handler = ArgparseArgumentHandler
|
||||
handlers=[
|
||||
handlers = [
|
||||
Sixth,
|
||||
Base,
|
||||
Second,
|
||||
@ -242,7 +241,7 @@ class ArgparseApp(TestApp):
|
||||
Fourth,
|
||||
Fifth,
|
||||
Seventh,
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
def test_clean_label():
|
||||
@ -286,7 +285,7 @@ def test_controller_commands():
|
||||
|
||||
with ArgparseApp(argv=['third', 'cmd4']) as app:
|
||||
res = app.run()
|
||||
assert res =="Inside Fourth.cmd4"
|
||||
assert res == "Inside Fourth.cmd4"
|
||||
|
||||
with ArgparseApp(argv=['third', 'fifth', 'cmd5']) as app:
|
||||
res = app.run()
|
||||
@ -446,7 +445,7 @@ def test_alternative_default():
|
||||
class MyApp(ArgparseApp):
|
||||
class Meta:
|
||||
argv = ['alternative-default']
|
||||
handlers=[
|
||||
handlers = [
|
||||
Base,
|
||||
AlternativeDefault,
|
||||
]
|
||||
@ -463,12 +462,11 @@ def test_bad_alternative_default_command():
|
||||
class MyApp(ArgparseApp):
|
||||
class Meta:
|
||||
argv = ['bad-alternative-default']
|
||||
handlers=[
|
||||
handlers = [
|
||||
Base,
|
||||
BadAlternativeDefault,
|
||||
]
|
||||
|
||||
|
||||
with MyApp() as app:
|
||||
msg = "(.*)does not exist(.*)bogus_default(.*)"
|
||||
with raises(FrameworkError, match=msg):
|
||||
@ -479,12 +477,11 @@ def test_invalid_stacked_type():
|
||||
class MyApp(ArgparseApp):
|
||||
class Meta:
|
||||
argv = ['bad-alternative-default']
|
||||
handlers=[
|
||||
handlers = [
|
||||
Base,
|
||||
BadStackType,
|
||||
]
|
||||
|
||||
|
||||
with MyApp() as app:
|
||||
with raises(FrameworkError, match="(.*)Invalid stacked type(.*)"):
|
||||
app.run()
|
||||
@ -494,12 +491,11 @@ def test_duplicate_arguments():
|
||||
class MyApp(ArgparseApp):
|
||||
class Meta:
|
||||
argv = ['bad-alternative-default']
|
||||
handlers=[
|
||||
handlers = [
|
||||
Base,
|
||||
DuplicateArguments,
|
||||
]
|
||||
|
||||
|
||||
with MyApp() as app:
|
||||
with raises(ArgumentError, match="(.*)conflicting option string(.*)"):
|
||||
app.run()
|
||||
@ -509,12 +505,11 @@ def test_controller_command_duplicate_arguments():
|
||||
class MyApp(ArgparseApp):
|
||||
class Meta:
|
||||
argv = ['bad-alternative-default']
|
||||
handlers=[
|
||||
handlers = [
|
||||
Base,
|
||||
ControllerCommandDuplicateArguments,
|
||||
]
|
||||
|
||||
|
||||
with MyApp() as app:
|
||||
with raises(ArgumentError, match="(.*)conflicting option string(.*)"):
|
||||
app.run()
|
||||
@ -527,12 +522,11 @@ def test_aliases():
|
||||
class MyApp(ArgparseApp):
|
||||
class Meta:
|
||||
argv = ['bad-alternative-default']
|
||||
handlers=[
|
||||
handlers = [
|
||||
Base,
|
||||
Aliases,
|
||||
]
|
||||
|
||||
|
||||
with MyApp() as app:
|
||||
app._meta.argv = ['aliases', 'aliases-cmd1']
|
||||
res = app.run()
|
||||
|
||||
@ -4,7 +4,6 @@ import logging
|
||||
from tempfile import mkstemp
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.ext.ext_colorlog import ColoredFormatter
|
||||
from cement.utils import test
|
||||
from cement.utils.misc import init_defaults
|
||||
|
||||
|
||||
@ -77,7 +76,6 @@ def test_colorize_console_log(tmp):
|
||||
klass = app.log._get_console_formatter(_format)
|
||||
assert isinstance(klass, ColoredFormatter)
|
||||
|
||||
|
||||
# then test with colorize_file_log=false
|
||||
defaults['log.colorlog']['colorize_console_log'] = False
|
||||
|
||||
|
||||
@ -1,13 +1,10 @@
|
||||
|
||||
import os
|
||||
from pytest import raises
|
||||
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.ext.ext_configparser import ConfigParserConfigHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestConfigParserConfigHandler(object):
|
||||
def test_subclassing(self):
|
||||
@ -15,13 +12,12 @@ class TestConfigParserConfigHandler(object):
|
||||
class Meta:
|
||||
label = 'my_config_handler'
|
||||
|
||||
|
||||
h = MyConfigHandler()
|
||||
assert h._meta.interface == 'config'
|
||||
assert h._meta.label == 'my_config_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
def test_get_dict():
|
||||
with TestApp() as app:
|
||||
@ -44,7 +40,7 @@ def test_env_var_override():
|
||||
section_dict = app.config.get_section_dict('testapp')
|
||||
assert section_dict['foo'] == 'not-bar'
|
||||
|
||||
### do again but in another config namespace
|
||||
# do again but in another config namespace
|
||||
|
||||
app.config.add_section('dummy')
|
||||
app.config.set('dummy', 'foo', 'bar')
|
||||
|
||||
@ -45,6 +45,8 @@ def test_bogus_user(rando):
|
||||
env.switch()
|
||||
|
||||
# @test.raises(exc.FrameworkError)
|
||||
|
||||
|
||||
def test_bogus_group(rando):
|
||||
with raises(FrameworkError, match='Daemon group'):
|
||||
env = ext_daemon.Environment(group='cement_test_group%s' % rando)
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
|
||||
import os
|
||||
import jinja2
|
||||
from shutil import copyfile
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp, raises
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.utils import fs
|
||||
|
||||
|
||||
class Jinja2App(TestApp):
|
||||
@ -12,6 +15,7 @@ class Jinja2App(TestApp):
|
||||
template_dirs = []
|
||||
handlebars_helpers = {}
|
||||
|
||||
|
||||
def test_jinja2(rando):
|
||||
with Jinja2App() as app:
|
||||
res = app.render(dict(foo=rando), 'test_template.jinja2')
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
|
||||
import os
|
||||
import json
|
||||
from tempfile import mkstemp
|
||||
from cement.utils.test import *
|
||||
|
||||
from cement.utils.test import TestApp
|
||||
from cement.utils import fs
|
||||
|
||||
CONFIG_PARSED = dict(
|
||||
section=dict(
|
||||
@ -15,7 +15,9 @@ CONFIG_PARSED = dict(
|
||||
)
|
||||
|
||||
|
||||
CONFIG = fs.join(os.path.dirname(__file__), '..', 'data', 'config', 'config.json')
|
||||
CONFIG = fs.join(os.path.dirname(__file__), '..',
|
||||
'data', 'config', 'config.json')
|
||||
|
||||
|
||||
class JsonApp(TestApp):
|
||||
class Meta:
|
||||
@ -46,7 +48,7 @@ def test_keys():
|
||||
|
||||
def test_parse_file_bad_path():
|
||||
# coverage...
|
||||
with JsonApp(config_files=['./some_bogus_path']) as app:
|
||||
with JsonApp(config_files=['./some_bogus_path']):
|
||||
pass
|
||||
|
||||
|
||||
@ -54,7 +56,7 @@ def test_parse_file():
|
||||
with JsonApp() as app:
|
||||
assert app.config.get('section', 'key1') == 'ok1'
|
||||
assert app.config.get_section_dict('section') == \
|
||||
CONFIG_PARSED['section']
|
||||
CONFIG_PARSED['section']
|
||||
|
||||
|
||||
def test_handler_override_options_is_none():
|
||||
@ -68,6 +70,7 @@ def test_handler_override_options_is_none():
|
||||
app.run()
|
||||
app.render(dict(foo='bar'))
|
||||
|
||||
|
||||
def test_get_dict():
|
||||
with JsonApp() as app:
|
||||
_config = app.config.get_dict()
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from cement.core import handler
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.ext.ext_logging import LoggingLogHandler
|
||||
from cement.utils.test import *
|
||||
from cement.utils.misc import init_defaults
|
||||
|
||||
|
||||
@ -108,5 +107,5 @@ def test_missing_log_dir(tmp):
|
||||
file=os.path.join(tmp.dir, 'test.log'),
|
||||
)
|
||||
|
||||
with TestApp(config_defaults=defaults) as app:
|
||||
with TestApp(config_defaults=defaults):
|
||||
pass
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
import os
|
||||
from time import sleep
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
from cement.utils.misc import init_defaults
|
||||
|
||||
if 'MEMCACHED_HOST' in os.environ.keys():
|
||||
@ -16,6 +16,7 @@ defaults['cache.memcached']['hosts'] = [
|
||||
memcached_host
|
||||
]
|
||||
|
||||
|
||||
class MemcachedApp(TestApp):
|
||||
class Meta:
|
||||
extensions = ['memcached']
|
||||
@ -26,7 +27,7 @@ class MemcachedApp(TestApp):
|
||||
def test_memcache_list_type_config():
|
||||
with MemcachedApp() as app:
|
||||
assert app.config.get('cache.memcached', 'hosts') == \
|
||||
[memcached_host, memcached_host]
|
||||
[memcached_host, memcached_host]
|
||||
|
||||
|
||||
def test_memcache_str_type_config():
|
||||
@ -35,7 +36,7 @@ def test_memcache_str_type_config():
|
||||
memcached_host)
|
||||
with MemcachedApp(config_defaults=defaults) as app:
|
||||
assert app.config.get('cache.memcached', 'hosts') == \
|
||||
[memcached_host, memcached_host]
|
||||
[memcached_host, memcached_host]
|
||||
|
||||
|
||||
def test_memcached_set(key):
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
import random
|
||||
|
||||
from cement.utils.test import *
|
||||
from cement.core.foundation import TestApp
|
||||
from cement.utils.test import raises
|
||||
from cement.core.exc import FrameworkError
|
||||
|
||||
|
||||
class MustacheApp(TestApp):
|
||||
@ -12,7 +12,6 @@ class MustacheApp(TestApp):
|
||||
# template_dirs = []
|
||||
|
||||
|
||||
|
||||
def test_mustache(rando):
|
||||
with MustacheApp() as app:
|
||||
res = app.render(dict(foo=rando), 'test_template.mustache')
|
||||
@ -26,12 +25,13 @@ def test_mustache_partials(rando):
|
||||
mustache_res = "Inside partial > foo equals %s\n" % rando
|
||||
assert res == mustache_res
|
||||
|
||||
### derks@20180116: FIXME > Mustache is no longer raising a SyntaxError?
|
||||
# derks@20180116: FIXME > Mustache is no longer raising a SyntaxError?
|
||||
|
||||
# def test_mustache_bad_template():
|
||||
# with MustacheApp() as app:
|
||||
# app.render(dict(foo='bar'), 'bad_template.mustache')
|
||||
|
||||
|
||||
def test_mustache_nonexistent_template():
|
||||
with MustacheApp() as app:
|
||||
msg = "Could not locate template: missing_template.mustache"
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
|
||||
from cement.utils.test import *
|
||||
from cement.ext.ext_plugin import CementPluginHandler
|
||||
|
||||
|
||||
### module tests
|
||||
# module tests
|
||||
|
||||
class TestCementPluginHandler(object):
|
||||
def test_subclassing(self):
|
||||
@ -11,10 +10,9 @@ class TestCementPluginHandler(object):
|
||||
class Meta:
|
||||
label = 'my_plugin_handler'
|
||||
|
||||
|
||||
h = MyPluginHandler()
|
||||
assert h._meta.interface == 'plugin'
|
||||
assert h._meta.label == 'my_plugin_handler'
|
||||
|
||||
|
||||
### app functionality and coverage tests
|
||||
# app functionality and coverage tests
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
|
||||
|
||||
class PrintApp(TestApp):
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
import os
|
||||
from time import sleep
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
from cement.utils.misc import init_defaults
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ defaults['cache.redis']['host'] = redis_host
|
||||
defaults['cache.redis']['port'] = 6379
|
||||
defaults['cache.redis']['db'] = 0
|
||||
|
||||
|
||||
class RedisApp(TestApp):
|
||||
class Meta:
|
||||
extensions = ['redis']
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
|
||||
|
||||
class ScrubApp(TestApp):
|
||||
@ -8,7 +8,8 @@ class ScrubApp(TestApp):
|
||||
scrub = [
|
||||
('foo', '$$$'),
|
||||
('bar', '***'),
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
def test_scrub():
|
||||
with ScrubApp(argv=['--scrub']) as app:
|
||||
@ -17,4 +18,4 @@ def test_scrub():
|
||||
assert app.last_rendered[1] == '$$$*** $$$ ***\n'
|
||||
|
||||
# coverage
|
||||
assert app.scrub(None) == None
|
||||
assert app.scrub(None) is None
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
|
||||
import mock
|
||||
import sys
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
from cement.utils.misc import init_defaults
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ def test_smtp_defaults():
|
||||
else:
|
||||
assert instance.sendmail.call_count == 1
|
||||
|
||||
|
||||
def test_smtp_ssl_tls():
|
||||
defaults = init_defaults('mail.smtp')
|
||||
defaults['mail.smtp']['ssl'] = True
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
|
||||
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
|
||||
|
||||
class TabulateApp(TestApp):
|
||||
class Meta:
|
||||
extensions = ['tabulate']
|
||||
output_handler = 'tabulate'
|
||||
extensions = ['tabulate']
|
||||
output_handler = 'tabulate'
|
||||
|
||||
|
||||
def test_tabulate():
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
|
||||
import os
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp, raises
|
||||
from cement.ext.ext_watchdog import WatchdogEventHandler
|
||||
from cement.core.exc import FrameworkError
|
||||
from cement.utils import fs
|
||||
|
||||
|
||||
class MyEventHandler(WatchdogEventHandler):
|
||||
@ -51,7 +53,7 @@ def test_watchdog_app_paths_bad_spec(tmp):
|
||||
]
|
||||
|
||||
with raises(FrameworkError, match="Watchdog path spec must be a tuple"):
|
||||
with MyApp() as app:
|
||||
with MyApp():
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
|
||||
import os
|
||||
import yaml
|
||||
from cement.utils.test import *
|
||||
from cement.utils.test import TestApp
|
||||
from cement.utils import fs
|
||||
|
||||
|
||||
# CONFIG = '''
|
||||
@ -26,7 +28,9 @@ CONFIG_PARSED = dict(
|
||||
),
|
||||
)
|
||||
|
||||
CONFIG = fs.join(os.path.dirname(__file__), '..', 'data', 'config', 'config.yml')
|
||||
CONFIG = fs.join(os.path.dirname(__file__), '..',
|
||||
'data', 'config', 'config.yml')
|
||||
|
||||
|
||||
class YamlApp(TestApp):
|
||||
class Meta:
|
||||
@ -56,7 +60,7 @@ def test_keys():
|
||||
|
||||
|
||||
def test_parse_file_bad_path():
|
||||
with YamlApp(config_files=['./some_bogus_path']) as app:
|
||||
with YamlApp(config_files=['./some_bogus_path']):
|
||||
pass
|
||||
|
||||
|
||||
@ -64,7 +68,7 @@ def test_parse_file():
|
||||
with YamlApp() as app:
|
||||
assert app.config.get('section', 'key1') == 'ok1'
|
||||
assert app.config.get_section_dict('section') == \
|
||||
CONFIG_PARSED['section']
|
||||
CONFIG_PARSED['section']
|
||||
|
||||
|
||||
def test_handler_override_options_is_none():
|
||||
@ -78,6 +82,7 @@ def test_handler_override_options_is_none():
|
||||
app.run()
|
||||
app.render(dict(foo='bar'))
|
||||
|
||||
|
||||
def test_get_dict():
|
||||
with YamlApp() as app:
|
||||
_config = app.config.get_dict()
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
# ensure we don't break imports from cement namespace
|
||||
|
||||
|
||||
def test_import():
|
||||
from cement import App, Controller, ex, init_defaults
|
||||
from cement import App, Controller, ex, init_defaults # noqa: F401
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
from cement.utils import fs
|
||||
|
||||
|
||||
@ -8,6 +7,7 @@ def test_abspath():
|
||||
path = fs.abspath('.')
|
||||
assert path.startswith('/')
|
||||
|
||||
|
||||
def test_backup(tmp):
|
||||
bkfile = fs.backup(tmp.file)
|
||||
assert "%s.bak" % os.path.basename(tmp.file) == os.path.basename(bkfile)
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pytest import raises
|
||||
|
||||
from cement.core.foundation import TestApp
|
||||
@ -13,7 +12,7 @@ def test_defaults():
|
||||
defaults['section2']['foo'] = 'bar'
|
||||
with TestApp(config_defaults=defaults) as app:
|
||||
assert app.config.get('section1', 'debug') is True
|
||||
assert app.config.get_section_dict('section2') == {'foo' : 'bar'}
|
||||
assert app.config.get_section_dict('section2') == {'foo': 'bar'}
|
||||
|
||||
|
||||
def test_minimal_logger():
|
||||
@ -34,7 +33,7 @@ def test_minimal_logger():
|
||||
|
||||
# coverage ...
|
||||
kw = {}
|
||||
kw['extra'] = {'namespace' : __name__}
|
||||
kw['extra'] = {'namespace': __name__}
|
||||
log._get_logging_kwargs(__name__, **kw)
|
||||
|
||||
kw['extra'] = {}
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
|
||||
import sys
|
||||
import time
|
||||
import mock
|
||||
from pytest import raises
|
||||
|
||||
Loading…
Reference in New Issue
Block a user