Application¶
Base application class¶
-
class
noseapp.app.base.
NoseApp
(name, argv=None, exit=True, config=None, plugins=None, context=None, sub_apps=None, suites_path=None, is_sub_app=False)[source]¶ Base application class
Usage:
>>> app = NoseApp('my_app') >>> app.load_suites('/path/to/suites') >>> app.run()
-
__init__
(name, argv=None, exit=True, config=None, plugins=None, context=None, sub_apps=None, suites_path=None, is_sub_app=False)[source]¶ Parameters: name – application name. - application name is prefix to suite name.
- namespace pattern: <application_name>.<suite_name>:<test_case_name>
for example:
>>> from noseapp import Suite
>>> app = NoseApp('my_app') >>> suite = Suite('my_suite') >>> suite.name >>> 'my_suite'
>>> app.register_suite(suite) >>> suite.name >>> 'my_app.my_suite'
Parameters: - argv (list) – argv to sys.argv
- exit (bool) – do exit after run?
- config – import path or absolute file path
- for example:
- config=’project.etc.config’
- config=’/home/user/project/etc/config.py’
Parameters: - plugins (list or tuple) – plugins instances
- context (noseapp.app.context.AppContext) – inctance of AppContext. you can create own context instance to run.
- suites_path (str) – path to directory where contains suites
- is_sub_app (bool) – is application a sub application?
- sub_apps (list or tuple) – sub application instances. for master application only.
-
addOptions
(parser)[source]¶ Add options to command line interface.
Example:
from optparse import OptionGroup class MyApp(NoseApp): def addOptions(parser): group = OptionGroup(parser, 'My Application options') group.add_option( '--project-url', dest='project_url', default=None, help='Web URL', ) parser.add_option_group(group)
Parameters: parser (optparse.OptionParser) – options parser
-
add_setup
(func)[source]¶ Add setup callback to context.
Example:
app = NoseApp('my_app') @app.add_setup def setup(): # do something pass # or app.add_setup(lambda: None)
-
add_teardown
(func)[source]¶ Add teardown callback to context.
Example:
app = NoseApp('my_app') @app.add_teardown def teardown(): # do something pass # or app.add_teardown(lambda: None)
-
classmethod
as_master_app
(name, *sub_apps, **kwargs)[source]¶ Alternative constructor. Create application as master application.
Example:
sub_app = NoseApp.as_sub_app('my_sub_app') app = NoseApp.as_master_app('my_app', sub_app, config='etc.config') sub_app.load_suites('/path/to/suites') app.load_suites('/path/to/suites', merge_suites=True)
-
classmethod
as_sub_app
(name, **kwargs)[source]¶ Alternative constructor. Create application as sub application. See as_master_app.
-
context
¶ Context of application instance
Return type: noseapp.app.context.AppContext
-
is_master_app
¶ Flag to definition: is it master application?
Return type: bool
-
is_sub_app
¶ Flag to definition: is it sub application?
Return type: bool
-
load_suites
(path, recursive=True, merge_suites=False)[source]¶ Auto load suites. Path can be package or simple dir.
Parameters: - path (str) – path to suites dir
- recursive (bool) – recursive load from path or load from simple dir
- merge_suites (bool) – merge suites from sub application to self context. for master application only.
-
name
¶ Application name
-
options
¶ Command line options. Will be available after create instance.
Raises: RuntimeError
-
plugins
¶ Plugins storage of context
Return type: list
-
run
()[source]¶ To perform run suites. If was success after run and not exit param is False then return True.
Make run from command line:
noseapp-manage run project.app:create_app
Return type: bool Raises: RuntimeError
-
setUpApp
()[source]¶ For setup extensions end prepare program. Will be called after creating instance.
Shared data to Suite and TestCase instances. Data will be copied during installation.
Example:
data = { 'a': 1, 'b': 2, 'c': 3, } app = NoseApp('my_app') add.shared_data('data', data)
Parameters: - name (str) – extension name
- data – any object
Shared extension to Suite and TestCase instances. Use require param on noseapp.Suite class for connect.
Example:
import random app = NoseApp('my_app') app.shared_extension(name='random_int', cls=random.randint, args=(0, 100))
Parameters: - name (str) – extension name
- cls (object, callable) – extension class or callable object
- args (tuple) – cls init args
- kwargs (dict) – cls init kwargs
Raises: ValueError, AttributeError
-
show_tree
(show_docs=False, doc_lines=1)[source]¶ Show tree of suites.
Parameters: - show_docs (bool) – print or not print docs
- doc_lines (int) – number lines of doc
-
status
¶ Status of application.
Example:
>>> app = NoseApp.as_master_app('my_app') >>> app.status >>> 'master' >>> app = NoseApp.as_sub_app('my_app') >>> app.status >>> 'sub'
-
sub_apps
¶ Sub application storage
Return type: list
-
suites
¶ Suites storage of context
Return type: list
-
Config¶
-
noseapp.app.config.
get_config_path_by_env
(env_name, default=None, base_path=None)[source]¶ To set config by env name.
>>> config_path = get_config_path_by_env('MY_CONFIG', 'base', base_path='project.etc.')
Parameters: - env_name (str) – environment name
- base_path (str) – base path
- default (str) – default value
Return type: str
Context¶
-
noseapp.app.context.
merge_context
(master_app, merge_setup=False, merge_suites=False, merge_plugins=False, merge_teardown=False)[source]¶ Merge context from sub apps to master app.
Parameters: - master_app (noseapp.app.base.NoseApp) – master app instance
- merge_setup (bool) – merge setup callbacks?
- merge_suites (bool) – merge suites?
- merge_plugins (bool) – merge plugins?
- merge_teardown (bool) – merge teardown callbacks?
Raises: RuntimeError
-
class
noseapp.app.context.
AppContext
[source]¶ Context storage of NoseApp instance.
Class is storage for application data. Callback functions is here.
Usage:
>>> context = AppContext() >>> context.add_setup(lambda: print 'Hello World!') >>> ...
-
add_setup
(func)[source]¶ Add setup callback to setup callback storage
Parameters: func (callable) – function to call
-
add_suite
(suite)[source]¶ Add suite to suite storage
Parameters: suite (noseapp.suite.base.Suite) – suite instance
-
add_teardown
(func)[source]¶ Add teardown callback to teardown callback storage
Parameters: func (callable) – function to call
-
plugins
¶ Plugins storage. After add plugin to application he will be here.
-
setup
()[source]¶ Method make call to chain of setup callback storage before run suites. For nose.suite.ContextSuite.
-
setup_callbacks
¶ Setup callback storage
-
suites
¶ Suites storage. After register on application suite will be here.
-
teardown
()[source]¶ Method make call to chain of teardown callback storage after run suites. For nose.suite.ContextSuite.
-
teardown_callbacks
¶ Teardown callback storage
-