nose2-0.6.4/0000775000175000017500000000000012672050226012155 5ustar travistravisnose2-0.6.4/bin/0000775000175000017500000000000012672050226012725 5ustar travistravisnose2-0.6.4/bin/nose20000775000175000017500000000015712672050004013676 0ustar travistravis#! /usr/bin/env python __unittest = True from nose2 import discover if __name__ == '__main__': discover() nose2-0.6.4/docs/0000775000175000017500000000000012672050226013105 5ustar travistravisnose2-0.6.4/docs/dev/0000775000175000017500000000000012672050226013663 5ustar travistravisnose2-0.6.4/docs/dev/compat.rst0000664000175000017500000000012312672050004015666 0ustar travistravis============ nose2.compat ============ .. automodule :: nose2.compat :members: nose2-0.6.4/docs/dev/contributing.rst0000664000175000017500000000464412672050004017126 0ustar travistravisContributing to nose2 ===================== Exhortation ----------- Please do! nose2 cannot move forward without contributions from the testing community. The Basics ---------- nose2 is hosted on `github`_. Our home there is https://github.com/nose-devs/nose2. We use github's issue tracking and collaboration tools *exclusively* for managing nose2's development. This means: * Please report issues here: https://github.com/nose-devs/nose2/issues * Please make feature requests in the same place. * Please submit all patches as github pull requests. Get started ----------- The ``bootstrap.sh`` script in the root of the nose2 distribution can be used to get a new local clone up and running quickly. It requires that you have `virtualenvwrapper`_ installed. Run this script once to set up a nose2 virtualenv, install nose2's dependencies, and set up the git submodule that pulls in the `Sphinx`_ theme that the docs use. Coding Guidelines ----------------- Our style is `pep8`_ except: for consistency with unittest, please use CamelCase for class names, methods, attributes and function parameters that map directly to class attributes. Beyond style, the main rule is: *any patch that touches code must include tests.* And of course all tests must pass under all supported versions of Python. Fortunately that's easy to check: nose2 uses `tox`_ to manage its test scenarios, so simply running ``tox`` in nose2's root directory will run all of the tests with all supported python versions. When your patch gets all green, send a pull request! Merging Guidelines ------------------ The github Merge Button(tm) should be used only for trivial changes. Other merges, even those that can be automatically merged, should be merged manually, so that you have an opportunity to run tests on the merged changes before pushing them. When you merge manually, please use ``--no-ff`` so that we have a record of all merges. Also, core devs should not merge their own work -- again, unless it's trivial -- without giving other developers a chance to review it. The basic workflow should be to do the work in a topic branch in your fork then post a pull request for that branch, whether you're a core developer or other contributor. .. _github: https://github.com/ .. _pep8: http://www.python.org/dev/peps/pep-0008/ .. _tox: http://pypi.python.org/pypi/tox .. _virtualenvwrapper: http://pypi.python.org/pypi/virtualenvwrapper .. _Sphinx: http://sphinx.pocoo.org/ nose2-0.6.4/docs/dev/documenting_plugins.rst0000664000175000017500000000244712672050004020473 0ustar travistravis=================== Documenting plugins =================== You should do it. Nobody will use your plugins if you don't. Or if they do use them, they will curse you whenever things go wrong. One easy way to document your plugins is to use nose2's `Sphinx`_ extension, which provides an ``autoplugin`` directive that will produce decent reference documentation from your plugin classes. To use it, add ``nose2.sphinxext`` to the ``extensions`` list in the ``conf.py`` file in your docs directory. Then add an ``autoplugin`` directive to a ``*.rst`` file, like this:: .. autoplugin :: mypackage.plugins.PluginClass This will produce output that includes the config vars your plugin loads in ``__init__``, as well as any command line options your plugin registers. This is why you *really* should extract config vars and register command-line options in ``__init__``. The output will also include an ``autoclass`` section for your plugin class, so you can put more narrative documentation in the plugin's docstring for users to read. Of course you can, and should, write some words before the reference docs explaining what your plugin does and how to use it. You can put those words in the ``*.rst`` file itself, or in the docstring of the module where your plugin lives. .. _Sphinx : http://sphinx.pocoo.org/ nose2-0.6.4/docs/dev/event_reference.rst0000664000175000017500000000023612672050004017547 0ustar travistravisEvent reference =============== .. automodule :: nose2.events :members: :undoc-members: :exclude-members: Hook, Plugin, PluginInterface, PluginMeta nose2-0.6.4/docs/dev/exceptions.rst0000664000175000017500000000014312672050004016566 0ustar travistravis================ nose2.exceptions ================ .. automodule :: nose2.exceptions :members: nose2-0.6.4/docs/dev/hook_reference.rst0000664000175000017500000003603312672050004017372 0ustar travistravisHook reference ============== .. note :: Hooks are listed here in order of execution. Pre-registration Hooks ---------------------- .. function :: pluginsLoaded(self, event) :param event: :class:`nose2.events.PluginsLoadedEvent` The ``pluginsLoaded`` hook is called after all config files have been read, and all plugin classes loaded. Plugins that register automatically (those that call :meth:`nose2.events.Plugin.register` in ``__init__`` or have ``always-on = True`` set in their config file sections) will have already been registered with the hooks they implement. Plugins waiting for command-line activation will not yet be registered. Plugins can use this hook to examine or modify the set of loaded plugins, inject their own hook methods using :meth:`nose2.events.PluginInterface.addMethod`, or take other actions to set up or configure themselves or the test run. Since ``pluginsLoaded`` is a pre-registration hook, it is called for *all plugins* that implement the method, whether they have registered or not. Plugins that do not automatically register themselves should limit their actions in this hook to configuration, since they may not actually be active during the test run. .. function :: handleArgs(self, event) :param event: :class:`nose2.events.CommandLineArgsEvent` The ``handleArgs`` hook is called after all arguments from the command line have been parsed. Plugins can use this hook to handle command-line arguments in non-standard ways. They should not use it to try to modify arguments seen by other plugins, since the order in which plugins execute in a hook is not guaranteed. Since ``handleArgs`` is a pre-registration hook, it is called for *all plugins* that implement the method, whether they have registered or not. Plugins that do not automatically register themselves should limit their actions in this hook to configuration, since they may not actually be active during the test run. Standard Hooks -------------- These hooks are called for registered plugins only. .. function :: createTests(self, event) :param event: A :class:`nose2.events.CreateTestsEvent` instance Plugins can take over test loading by returning a test suite and setting ``event.handled`` to True. .. function :: loadTestsFromNames(self, event) :param event: A :class:`nose2.events.LoadFromNamesEvent` instance Plugins can return a test suite or list of test suites and set ``event.handled`` to ``True`` to prevent other plugins from loading tests from the given names, or append tests to ``event.extraTests``. Plugins can also remove names from ``event.names`` to prevent other plugins from acting on those names. .. function :: loadTestsFromName(self, event) :param event: A :class:`nose2.events.LoadFromNameEvent` instance Plugins can return a test suite and set ``event.handled`` to ``True`` to prevent other plugins from loading tests from the given name, or append tests to ``event.extraTests``. .. function :: handleFile(self, event) :param event: A :class:`nose2.events.HandleFileEvent` instance Plugins can use this hook to load tests from files that are not Python modules. Plugins may either append tests to ``event.extraTest``, or, if they want to prevent other plugins from processing the file, set ``event.handled`` to True and return a test case or test suite. .. function :: matchPath(self, event) :param event: A :class:`nose2.events.MatchPathEvent` instance Plugins can use this hook to prevent python modules from being loaded by the test loader or force them to be loaded by the test loader. Set ``event.handled`` to ``True`` and return ``False`` to cause the loader to skip the module. Set ``event.handled`` to ``True`` and return ``True`` to cause the loader to load the module. .. function :: loadTestsFromModule(self, event) :param event: A :class:`nose2.events.LoadFromModuleEvent` instance Plugins can use this hook to load tests from test modules. To prevent other plugins from loading from the module, set ``event.handled`` and return a test suite. Plugins can also append tests to ``event.extraTests`` -- usually that's what you want to do, since that will allow other plugins to load their tests from the module as well. See also :ref:`this warning ` about test cases not defined in the module. .. function :: loadTestsFromTestCase(self, event) :param event: A :class:`nose2.events.LoadFromTestCaseEvent` instance Plugins can use this hook to load tests from a :class:`unittest.TestCase`. To prevent other plugins from loading tests from the test case, set ``event.handled`` to ``True`` and return a test suite. Plugins can also append tests to ``event.extraTests`` -- usually that's what you want to do, since that will allow other plugins to load their tests from the test case as well. .. function :: getTestCaseNames(self, event) :param event: A :class:`nose2.events.GetTestCaseNamesEvent` instance Plugins can use this hook to limit or extend the list of test case names that will be loaded from a :class:`unittest.TestCase` by the standard nose2 test loader plugins (and other plugins that respect the results of the hook). To force a specific list of names, set ``event.handled`` to ``True`` and return a list: this exact list will be the only test case names loaded from the test case. Plugins can also extend the list of names by appending test names to ``event.extraNames``, and exclude names by appending test names to ``event.excludedNames``. .. function :: runnerCreated(self, event) :param event: A :class:`nose2.events.RunnerCreatedEvent` instance Plugins can use this hook to wrap, capture or replace the test runner. To replace the test runner, set ``event.runner``. .. function :: resultCreated(self, event) :param event: A :class:`nose2.events.ResultCreatedEvent` instance Plugins can use this hook to wrap, capture or replace the test result. To replace the test result, set ``event.result``. .. function :: startTestRun(self, event) :param event: A :class:`nose2.events.StartTestRunEvent` instance Plugins can use this hook to take action before the start of the test run, and to replace or wrap the test executor. To replace the executor, set ``event.executeTests``. This must be a callable that takes two arguments: the top-level test and the test result. To prevent the test executor from running at all, set ``event.handled`` to ``True``. .. function :: startTest(self, event) :param event: A :class:`nose2.events.StartTestEvent` instance Plugins can use this hook to take action immediately before a test runs. .. function :: reportStartTest(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to produce output for the user at the start of a test. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: describeTest(self, event) :param event: A :class:`nose2.events.DescribeTestEvent` instance Plugins can use this hook to alter test descriptions. To return a nonstandard description for a test, set ``event.description``. Be aware that other plugins may have set this also! .. function :: setTestOutcome(self, event) :param event: A :class:`nose2.events.TestOutcomeEvent` instance Plugins can use this hook to alter test outcomes. Plugins can ``event.outcome`` to change the outcome of the event, tweak, change or remove ``event.exc_info``, set or clear ``event.expected``, and so on. .. function :: testOutcome(self, event) :param event: A :class:`nose2.events.TestOutcomeEvent` instance Plugins can use this hook to take action based on the outcome of tests. Plugins *must not* alter test outcomes in this hook: that's what :func:`setTestOutcome` is for. Here, plugins may only react to the outcome event, not alter it. .. function :: reportSuccess(self, event) :param event: A :class:`nose2.events.LoadFromNamesEvent` instance Plugins can use this hook to report test success to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: reportError(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to report a test error to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: reportFailure(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to report test failure to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: reportSkip(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to report a skipped test to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: reportExpectedFailure(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to report an expected failure to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: reportUnexpectedSuccess(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to report an unexpected success to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: reportOtherOutcome(self, event) :param event: A :class:`nose2.events.ReportTestEvent` instance Plugins can use this hook to report a custom test outcome to the user. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. To prevent other plugins from reporting to the user, set ``event.handled`` to ``True``. .. function :: stopTest(self, event) :param event: A :class:`nose2.events.StopTestEvent` instance Plugins can use this hook to take action after a test has completed running and reported its outcome. .. function :: stopTestRun(self, event) :param event: A :class:`nose2.events.StopTestRunEvent` instance Plugins can use this hook to take action at the end of a test run. .. function :: afterTestRun(self, event) :param event: A :class:`nose2.events.StopTestRunEvent` instance .. note :: New in version 0.2 Plugins can use this hook to take action *after* the end of a test run, such as printing summary reports like the builtin result reporter plugin :class:`nose2.plugins.result.ResultReporter`. .. function :: resultStop(self, event) :param event: A :class:`nose2.events.ResultStopEvent` instance Plugins can use this hook to *prevent* other plugins from stopping a test run. This hook fires when something calls :meth:`nose2.result.PluggableTestResult.stop`. If you want to prevent this from stopping the test run, set ``event.shouldStop`` to ``False``. .. function :: beforeErrorList(self, event) :param event: A :class:`nose2.events.ReportSummaryEvent` instance Plugins can use this hook to output or modify summary information before the list of errors and failures is output. To modify the categories of outcomes that will be reported, plugins can modify the ``event.reportCategories`` dictionary. Plugins can set, wrap, or capture the output stream by reading or setting ``event.stream``. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. .. function :: outcomeDetail(self, event) :param event: A :class:`nose2.events.OutcomeDetailEvent` instance Plugins can use this hook to add additional elements to error list output. Append extra detail lines to ``event.extraDetail``; these will be joined together with newlines before being output as part of the detailed error/failure message, after the traceback. .. function :: beforeSummaryReport(self, event) :param event: A :class:`nose2.events.ReportSummaryEvent` instance Plugins can use this hook to output or modify summary information before the summary lines are output. To modify the categories of outcomes that will be reported in the summary, plugins can modify the ``event.reportCategories`` dictionary. Plugins can set, wrap or capture the output stream by reading or setting ``event.stream``. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. .. function :: wasSuccessful(self, event) :param event: A :class:`nose2.events.ResultSuccessEvent` instance Plugins can use this hook to mark a test run as successful or unsuccessful. If not plugin marks the run as successful, the default state is failure. To mark a run as successful, set ``event.success`` to ``True``. Be ware that other plugins may set this attribute as well! .. function :: afterSummaryReport(self, event) :param event: A :class:`nose2.events.ReportSummaryEvent` instance Plugins can use this hook to output a report to the user after the summary line is output. If you want to print to the console, write to ``event.stream``. Remember to respect ``self.session.verbosity`` when printing to the console. User Interaction Hooks ---------------------- These hooks are called when plugins want to interact with the user. .. function :: beforeInteraction(event) :param event: A :class:`nose2.events.UserInteractionEvent` Plugins should respond to this hook by getting out of the way of user interaction, if the need to, or setting ``event.handled`` and returning ``False``, if they need to but can't. .. function :: afterInteraction(event) :param event: A :class:`nose2.events.UserInteractionEvent` Plugins can respond to this hook by going back to whatever they were doing before the user stepped in and started poking around. nose2-0.6.4/docs/dev/internals.rst0000664000175000017500000000035412672050004016410 0ustar travistravis========= Internals ========= Reference material for things you probably only need to care about if you want to contribute to nose2. .. toctree:: :maxdepth: 2 main compat exceptions loader result runner utils nose2-0.6.4/docs/dev/loader.rst0000664000175000017500000000012312672050004015651 0ustar travistravis============ nose2.loader ============ .. automodule :: nose2.loader :members: nose2-0.6.4/docs/dev/main.rst0000664000175000017500000000011312672050004015326 0ustar travistravis========== nose2.main ========== .. automodule :: nose2.main :members: nose2-0.6.4/docs/dev/plugin_class_reference.rst0000664000175000017500000000060212672050004021106 0ustar travistravisPlugin class reference ====================== The plugin system in nose2 is based on the plugin system in unittest2's ``plugins`` branch. Plugin base class ----------------- .. autoclass :: nose2.events.Plugin :members: Plugin interface classes ------------------------ .. autoclass :: nose2.events.PluginInterface :members: .. autoclass :: nose2.events.Hook :members: nose2-0.6.4/docs/dev/result.rst0000664000175000017500000000012312672050004015721 0ustar travistravis============ nose2.result ============ .. automodule :: nose2.result :members: nose2-0.6.4/docs/dev/runner.rst0000664000175000017500000000012412672050004015715 0ustar travistravis============ nose2.runner ============ .. automodule :: nose2.runner :members: nose2-0.6.4/docs/dev/session_reference.rst0000664000175000017500000000102012672050004020101 0ustar travistravisSession reference ================= Session ------- In nose2, all configuration for a test run is encapsulated in a ``Session`` instance. Plugins always have the session available as ``self.session``. .. autoclass :: nose2.session.Session :members: Config ------ Configuration values loaded from config file sections are made available to plugins in ``Config`` instances. Plugins that set ``configSection`` will have a ``Config`` instance available as ``self.config``. .. autoclass :: nose2.config.Config :members: nose2-0.6.4/docs/dev/utils.rst0000664000175000017500000000011312672050004015542 0ustar travistravis========== nose2.util ========== .. automodule :: nose2.util :members: nose2-0.6.4/docs/dev/writing_plugins.rst0000664000175000017500000001635512672050004017645 0ustar travistravis=============== Writing Plugins =============== nose2 supports plugins for test collection, selection, observation and reporting -- among other things. There are two basic rules for plugins: * Plugin classes must subclass :class:`nose2.events.Plugin`. * Plugins may implement any of the methods described in the :doc:`hook_reference`. Hello World =========== Here's a basic plugin. It doesn't do anything besides log a message at the start of a test run. .. code-block:: python import logging import os from nose2.events import Plugin log = logging.getLogger('nose2.plugins.helloworld') class HelloWorld(Plugin): configSection = 'helloworld' commandLineSwitch = (None, 'hello-world', 'Say hello!') def startTestRun(self, event): log.info('Hello pluginized world!') To see this plugin in action, save it into an importable module, then add that module to the ``plugins`` key in the ``[unittest]`` section of a config file loaded by nose2, such as ``unittest.cfg``. Then run nose2:: nose2 --log-level=INFO --hello-world And you should see the log message before the first dot appears. Loading plugins =============== As mentioned above, for nose2 to find a plugin, it must be in an importable module, and the module must be listed under the ``plugins`` key in the ``[unittest]`` section of a config file loaded by nose2: .. code-block:: ini [unittest] plugins = mypackage.someplugin otherpackage.thatplugin thirdpackage.plugins.metoo As you can see, plugin *modules* are listed, one per line. All plugin classes in those modules will be loaded -- but not necessarily active. Typically plugins do not activate themselves ("register") without seeing a command-line flag, or ``always-on = True`` in their config file section. Command-line Options ==================== nose2 uses `argparse`_ for command-line argument parsing. Plugins may enable command-line options that register them as active, or take arguments or flags controlling their operation. The most basic thing to do is to set the plugin's ``commandLineSwitch`` attribute, which will automatically add a command-line flag that registers the plugin. To add other flags or arguments, you can use the Plugin methods :meth:`nose2.events.Plugin.addFlag`, :meth:`nose2.events.Plugin.addArgument` or :meth:`nose2.events.Plugin.addOption`. If those don't offer enough flexibility, you can directly manipulate the argument parser by accessing ``self.session.argparse`` or the plugin option group by accessing ``self.session.pluginargs``. Please note though that the *majority* of your plugin's configuration should be done via config file options, not command line options. Config File Options =================== Plugins may specify a config file section that holds their configuration by setting their ``configSection`` attribute. All plugins, regardless of whether they specify a config section, have a ``config`` attribute that holds a :class:`nose2.config.Config` instance. This will be empty of values if the plugin does not specify a config section or if no loaded config file includes that section. Plugins should extract the user's configuration selections from their config attribute in their ``__init__`` methods. Plugins that want to use nose2's `Sphinx`_ extension to automatically document themselves **must** do so. Config file options may be extracted as strings, ints, booleans or lists. You should provide reasonable defaults for all config options. Guidelines ========== Events ------ in one major area: what it passes to hooks. Where nose passes a variety of arguments, nose2 *always passes an event*. The events are listed in the :doc:`event_reference`. nose2's plugin API is based on the API in unittest2's ``plugins`` branch (under-development). Its differs from nose's Here's the key thing about that: *event attributes are read-write*. Unless stated otherwise in the documentation for a hook, you can set a new value for any event attribute, and *this will do something*. Plugins and nose2 systems will see that new value and either use it instead of what was originally set in the event (example: the reporting stream or test executor), or use it to supplement something they find elsewhere (example: extraTests on a test loading event). "Handling" events ~~~~~~~~~~~~~~~~~ Many hooks give plugins a chance to completely handle events, bypassing other plugins and any core nose2 operations. To do this, a plugin sets ``event.handled`` to True and, generally, returns an appropriate value from the hook method. What is an appropriate value varies by hook, and some hooks *can't* be handled in this way. But even for hooks where handling the event doesn't stop all processing, it *will* stop subsequently-loaded plugins from seeing the event. Logging ------- nose2 uses the logging classes from the standard library. To enable users to view debug messages easily, plugins should use ``logging.getLogger()`` to acquire a logger in the ``nose2.plugins`` namespace. .. todo :: more guidelines Recipes ======= * Writing a plugin that monitors or controls test result output Implement any of the ``report*`` hook methods, especially if you want to output to the console. If outputing to file or other system, you might implement :func:`testOutcome` instead. Example: :class:`nose2.plugins.result.ResultReporter` * Writing a plugin that handles exceptions If you just want to handle some exceptions as skips or failures instead of errors, see :class:`nose2.plugins.outcomes.Outcomes`, which offers a simple way to do that. Otherwise, implement :func:`setTestOutcome` to change test outcomes. Example: :class:`nose2.plugins.outcomes.Outcomes` * Writing a plugin that adds detail to error reports Implement :func:`testOutcome` and put your extra information into ``event.metadata``, then implement :func:`outcomeDetail` to extract it and add it to the error report. Examples: :class:`nose2.plugins.buffer.OutputBufferPlugin`, :class:`nose2.plugins.logcapture.LogCapture` * Writing a plugin that loads tests from files other than python modules Implement :func:`handleFile`. Example: :class:`nose2.plugins.doctests.DocTestLoader` * Writing a plugin that loads tests from python modules Implement at least :func:`loadTestsFromModule`. .. _loading-from-module: .. warning :: One thing to beware of here is that if you return tests as dynamically-generated test cases, or instances of a testcase class that is defined *anywhere* but the module being loaded, you *must* use :func:`nose2.util.transplant_class` to make the test case class appear to have originated in that module. Otherwise, module-level fixtures will not work for that test, and may be ignored entirely for the module if there are no test cases that are or appear to be defined there. * Writing a plugin that prints a report Implement :func:`beforeErrorList`, :func:`beforeSummaryReport` or :func:`afterSummaryReport` Example: :class:`nose2.plugins.prof.Profiler` * Writing a plugin that selects or rejects tests Implement :class:`matchPath` or :class:`getTestCaseNames`. Example: :class:`nose2.plugins.loader.parameters.Parameters` .. _argparse : http://pypi.python.org/pypi/argparse/1.2.1 .. _Sphinx : http://sphinx.pocoo.org/ nose2-0.6.4/docs/plugins/0000775000175000017500000000000012672050226014566 5ustar travistravisnose2-0.6.4/docs/plugins/attrib.rst0000664000175000017500000000653412672050004016607 0ustar travistravis=============================== Selecting tests with attributes =============================== .. note :: New in version 0.2 Filter tests by attribute, excluding any tests whose attributes do not match any of the specified attributes. Attributes may be simple values or lists, and may be attributes of a test method (or function), a test case class, or the callable yielded by a generator test. Given the following test module, the attrib plugin can be used to select tests in the following ways (and others!): .. note :: All examples assume the attrib plugin has been activated in a config file: .. code-block :: ini [unittest] plugins = nose2.plugins.attrib .. literalinclude :: attrib_example.py :language: python Select tests having an attribute ________________________________ Running nose2 like this:: nose2 -v -A fast Runs these tests:: test_fast (attrib_example.Test) ... ok test_faster (attrib_example.Test) ... ok This selects all tests that define the attribute as any ``True`` value. Select tests that do not have an attribute __________________________________________ Running nose2 like this:: nose2 -v -A '!fast' Runs these tests:: test_slow (attrib_example.Test) ... ok test_slower (attrib_example.Test) ... ok This selects all tests that define the attribute as a ``False`` value, *and those tests that do not have the attribute at all*. Select tests having an attribute with a particular value -------------------------------------------------------- Running nose2 like this:: nose2 -v -A layer=2 Runs these tests:: test_fast (attrib_example.Test) ... ok test_slow (attrib_example.Test) ... ok This selects all tests that define the attribute with a matching value. The attribute value of each test case is converted to a string before comparison with the specified value. Comparison is case-insensitive. Select tests having a value in a list attribute ----------------------------------------------- Running nose2 like this:: nose2 -v -A flags=red Runs these tests:: test_faster (attrib_example.Test) ... ok test_slower (attrib_example.Test) ... ok Since the ``flags`` attribute is a list, this test selects all tests with the value ``red`` in their ``flags`` attribute. Comparison done after string conversion and is case-insensitive. Select tests that do not have a value in a list attribute --------------------------------------------------------- Running nose2 like this:: nose2 -v -A '!flags=red' Runs these tests:: test_fast (attrib_example.Test) ... ok The result in this case can be somewhat counter-intuitive. What the ``attrib`` plugin selects when you negate an attribute that is in a list are only those tests that *have the list attribute* but *without the value* specified. Tests that do not have the attribute at all are *not* selected. Select tests using Python expressions ------------------------------------- For more complex cases, you can use the :option:`-E` command-line option to pass a Python expression that will be evaluated in the context of each test case. Only those test cases where the expression evaluates to ``True`` (and don't raise an exception) will be selected. Running nose2 like this:: nose2 -v -E '"blue" in flags and layer > 2' Runs only one test:: test_slower (attrib_example.Test) ... ok .. autoplugin :: nose2.plugins.attrib.AttributeSelector nose2-0.6.4/docs/plugins/attrib_example.py0000664000175000017500000000104512672050004020132 0ustar travistravisimport unittest class Test(unittest.TestCase): def test_fast(self): pass test_fast.fast = 1 test_fast.layer = 2 test_fast.flags = ['blue', 'green'] def test_faster(self): pass test_faster.fast = 1 test_faster.layer = 1 test_faster.flags = ['red', 'green'] def test_slow(self): pass test_slow.fast = 0 test_slow.slow = 1 test_slow.layer = 2 def test_slower(self): pass test_slower.slow = 1 test_slower.layer = 3 test_slower.flags = ['blue', 'red'] nose2-0.6.4/docs/plugins/buffer.rst0000664000175000017500000000017412672050004016565 0ustar travistravis===================== Buffering test output ===================== .. autoplugin :: nose2.plugins.buffer.OutputBufferPlugin nose2-0.6.4/docs/plugins/collect.rst0000664000175000017500000000024712672050004016742 0ustar travistravis===================================== Collecting tests without running them ===================================== .. autoplugin :: nose2.plugins.collect.CollectOnly nose2-0.6.4/docs/plugins/coverage.rst0000664000175000017500000000017212672050004017105 0ustar travistravis======================= Test coverage reporting ======================= .. autoplugin :: nose2.plugins.coverage.Coverage nose2-0.6.4/docs/plugins/debugger.rst0000664000175000017500000000020312672050004017071 0ustar travistravis========================== Dropping Into the Debugger ========================== .. autoplugin :: nose2.plugins.debugger.Debugger nose2-0.6.4/docs/plugins/discovery.rst0000664000175000017500000000020612672050004017317 0ustar travistravis====================== Loader: Test discovery ====================== .. autoplugin :: nose2.plugins.loader.discovery.DiscoveryLoader nose2-0.6.4/docs/plugins/doctests.rst0000664000175000017500000000015412672050004017142 0ustar travistravis================ Loader: Doctests ================ .. autoplugin :: nose2.plugins.doctests.DocTestLoader nose2-0.6.4/docs/plugins/dundertests.rst0000664000175000017500000000023712672050004017660 0ustar travistravis================================ Default filter: :attr:`__test__` ================================ .. autoplugin :: nose2.plugins.dundertest.DunderTestFilter nose2-0.6.4/docs/plugins/eggdiscovery.rst0000664000175000017500000000175712672050004020016 0ustar travistravis========================== Loader: Egg Test discovery ========================== What is Egg Discovery --------------------- Sometimes Python Eggs are marked as zip-safe and they can be installed zipped, instead of unzipped in an ``.egg`` folder. See http://peak.telecommunity.com/DevCenter/PythonEggs for more details. The normal ``nose2.plugins.loader.discovery`` plugin ignores modules located inside zip files. The Egg Discovery plugin allows nose2 to discover tests within these zipped egg files. This plugin requires ``pkg_resources`` (from ``setuptools``) to work correctly. Usage ----- To activate the plugin, include the plugin module in the plugins list in ``[unittest]`` section in a config file:: [unittest] plugins = nose2.plugins.loader.eggdiscovery Or pass the module with the :option:`--plugin` command-line option:: nose2 --plugin=nose2.plugins.loader.eggdiscovery module_in_egg Reference --------- .. autoplugin :: nose2.plugins.loader.eggdiscovery.EggDiscoveryLoader nose2-0.6.4/docs/plugins/failfast.rst0000664000175000017500000000026012672050004017101 0ustar travistravis========================================= Stopping After the First Error or Failure ========================================= .. autoplugin :: nose2.plugins.failfast.FailFast nose2-0.6.4/docs/plugins/functions.rst0000664000175000017500000000020112672050004017313 0ustar travistravis====================== Loader: Test Functions ====================== .. autoplugin :: nose2.plugins.loader.functions.Functions nose2-0.6.4/docs/plugins/generators.rst0000664000175000017500000000020512672050004017460 0ustar travistravis======================= Loader: Test Generators ======================= .. autoplugin :: nose2.plugins.loader.generators.Generators nose2-0.6.4/docs/plugins/junitxml.rst0000664000175000017500000001122112672050004017161 0ustar travistravis=========================== Outputting XML Test Reports =========================== .. note :: New in version 0.2 .. autoplugin :: nose2.plugins.junitxml.JUnitXmlReporter Sample output ------------- The XML test report for nose2's sample scenario with tests in a package looks like this: .. code-block :: xml Traceback (most recent call last): File "nose2/plugins/loader/parameters.py", line 162, in func return obj(*argSet) File "nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py", line 64, in test_params_func assert a == 1 AssertionError Traceback (most recent call last): File "nose2/plugins/loader/parameters.py", line 162, in func return obj(*argSet) File "nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py", line 69, in test_params_func_multi_arg assert a == b AssertionError Traceback (most recent call last): File "nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py", line 17, in test_failed assert False, "I failed" AssertionError: I failed Traceback (most recent call last): File "nose2/plugins/loader/parameters.py", line 144, in _method return method(self, *argSet) File "nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py", line 29, in test_params_method self.assertEqual(a, 1) AssertionError: 2 != 1 Traceback (most recent call last): File "nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py", line 13, in test_typeerr raise TypeError("oops") TypeError: oops Traceback (most recent call last): File "nose2/plugins/loader/generators.py", line 145, in method return func(*args) File "nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py", line 24, in check assert x == 1 AssertionError nose2-0.6.4/docs/plugins/layers.rst0000664000175000017500000001713612672050004016621 0ustar travistravis==================================== Organizing Test Fixtures into Layers ==================================== .. note :: New in version 0.4 Layers allow more flexible organization of test fixtures than test-, class- and module- level fixtures. Layers in nose2 are inspired by and aim to be compatible with the layers used by Zope's testrunner. Using layers, you can do things like: * Implement package-level fixtures by sharing a layer among all test cases in the package. * Share fixtures across tests in different modules without having them run multiple times. * Create a fixture tree deeper than three levels (test, class and module). * Make fixtures available for other packages or projects to use. A layer is a *new-style* class that implements at least a ``setUp`` classmethod: .. code-block :: python class Layer(object): @classmethod def setUp(cls): # ... It may also implement ``tearDown``, ``testSetUp`` and ``testTearDown``, all as classmethods. To assign a layer to a test case, set the test case's ``layer`` property:: class Test(unittest.TestCase): layer = Layer Note that the layer *class* is assigned, not an instance of the layer. Typically layer classes are not instantiated. Sub-layers ========== Layers may subclass other layers: .. code-block :: python class SubLayer(Layer): @classmethod def setUp(cls): # ... In this case, all tests that belong to the sub-layer also belong to the base layer. For example for this test case:: class SubTest(unittest.TestCase): layer = SubLayer The ``setUp`` methods from *both* ``SubLayer`` and ``Layer`` will run before any tests are run. The superclass's setup will always run before the subclass's setup. For ``teardown``, the reverse: the subclass's ``teardown`` runs before the superclass's. .. warning :: One important thing to note: layers that subclass other layers *must not* call their superclass's ``setUp``, ``tearDown``, etc. The test runner will take care of organizing tests so that the superclass's methods are called in the right order:: Layer.setUp -> SubLayer.setUp -> Layer.testSetUp -> SubLayer.testSetUp -> TestCase.setUp TestCase.run TestCase.tearDown SubLayer.testTearDown <- Layer.testTearDown <- SubLayer.tearDown <- Layer.tearDown <- If a sublayer calls it superclass's methods directly, *those methods will be called twice*. Layer method reference ====================== .. class :: Layer Not an actual class, but reference documentation for the methods layers can implement. There is no layer base class. Layers must be subclasses of :class:`object` or other layers. .. classmethod :: setUp(cls) The layer's ``setUp`` method is called before any tests belonging to that layer are executed. If no tests belong to the layer (or one of its sub-layers) then the ``setUp`` method will not be called. .. classmethod :: tearDown(cls) The layer's ``tearDown`` method is called after any tests belonging to the layer are executed, if the layer's ``setUp`` method was called and did not raise an exception. It will not be called if the layer has no ``setUp`` method, or if that method did not run or did raise an exception. .. classmethod :: testSetUp(cls[, test]) The layer's ``testSetUp`` method is called before each test belonging to the layer (and its sub-layers). If the method is defined to accept an argument, the test case instance is passed to the method. The method may also be defined to take no arguments. .. classmethod :: testTearDown(cls[, test]) The layer's ``testTearDown`` method is called after each test belonging to the layer (and its sub-layers), if the layer also defines a ``setUpTest`` method and that method ran successfully (did not raise an exception) for this test case. Layers DSL ========== nose2 includes a DSL for setting up layer-using tests called "such". Read all about it here: :doc:`../such_dsl`. Pretty reports ============== The layers plugin module includes a second plugin that alters test report output to make the layer groupings more clear. When activated with the :option:`--layer-reporter` command-line option (or via a config file), test output that normally looks like this:: test (test_layers.NoLayer) ... ok test (test_layers.Outer) ... ok test (test_layers.InnerD) ... ok test (test_layers.InnerA) ... ok test (test_layers.InnerA_1) ... ok test (test_layers.InnerB_1) ... ok test (test_layers.InnerC) ... ok test2 (test_layers.InnerC) ... ok ---------------------------------------------------------------------- Ran 8 tests in 0.001s OK Will instead look like this:: test (test_layers.NoLayer) ... ok Base test (test_layers.Outer) ... ok LayerD test (test_layers.InnerD) ... ok LayerA test (test_layers.InnerA) ... ok LayerB LayerC test (test_layers.InnerC) ... ok test2 (test_layers.InnerC) ... ok LayerB_1 test (test_layers.InnerB_1) ... ok LayerA_1 test (test_layers.InnerA_1) ... ok ---------------------------------------------------------------------- Ran 8 tests in 0.002s OK The layer reporter plugin can also optionally colorize the keywords (by default, 'A', 'having', and 'should') in output from tests defined with the :doc:`such DSL <../such_dsl>`. If you would like to change how the layer is displayed, set the ``description`` attribute. .. code-block :: python class LayerD(Layer): description = '*** This is a very important custom layer description ***' Now the output will be the following:: test (test_layers.NoLayer) ... ok Base test (test_layers.Outer) ... ok *** This is a very important custom layer description *** test (test_layers.InnerD) ... ok LayerA test (test_layers.InnerA) ... ok LayerB LayerC test (test_layers.InnerC) ... ok test2 (test_layers.InnerC) ... ok LayerB_1 test (test_layers.InnerB_1) ... ok LayerA_1 test (test_layers.InnerA_1) ... ok ---------------------------------------------------------------------- Ran 8 tests in 0.002s OK Warnings and Caveats ==================== Test case order and module isolation ------------------------------------ Test cases that use layers will not execute in the same order as test cases that do not. In order to execute the layers efficiently, the test runner must reorganize *all* tests in the loaded test suite to group those having like layers together (and sub-layers under their parents). If you share layers across modules this may result in tests from one module executing interleaved with tests from a different module. Mixing layers with ``setUpClass`` and module fixtures ------------------------------------------------- **Don't cross the streams.** The implementation of class- and module-level fixtures in unittest2 depends on introspecting the class hierarchy inside of the ``unittest.TestSuite``. Since the suites that the ``layers`` plugin uses to organize tests derive from :class:`unittest.BaseTestSuite` (instead of :class:`unittest.TestSuite`), class- and module- level fixtures in TestCase classes that use layers will be ignored. Mixing layers and multiprocess testing -------------------------------------- In the initial release, *test suites using layers are incompatible with the multiprocess plugin*. This should be fixed in a future release. Plugin reference ================ .. autoplugin :: nose2.plugins.layers nose2-0.6.4/docs/plugins/loadtests.rst0000664000175000017500000000022512672050004017313 0ustar travistravis=========================== Loader: load_tests protocol =========================== .. autoplugin :: nose2.plugins.loader.loadtests.LoadTestsLoader nose2-0.6.4/docs/plugins/logcapture.rst0000664000175000017500000000024512672050004017460 0ustar travistravis====================== Capturing log messages ====================== .. todo :: Document all the things. .. autoplugin :: nose2.plugins.logcapture.LogCapture nose2-0.6.4/docs/plugins/mp.rst0000664000175000017500000002335712672050004015740 0ustar travistravis================================================= Running Tests in Parallel with Multiple Processes ================================================= .. note :: New in version 0.3 Use the ``mp`` plugin to enable distribution of tests across multiple processes. Doing his may speed up your test run if your tests are heavily IO or CPU bound. But it *imposes an overhead cost* that is not trivial, and it *complicates the use of test fixtures* and may *conflict with plugins that are not designed to work with it*. Usage ----- To activate the plugin, include the plugin module in the plugins list in ``[unittest]`` section in a config file:: [unittest] plugins = nose2.plugins.mp Or pass the module with the :option:`--plugin` command-line option:: nose2 --plugin=nose2.plugins.mp Then configure the number of processes to run. You can do that either with the :option:`-N` option:: nose2 -N 2 or by setting ``processes`` in the ``[multiprocess]`` section of a config file:: [multiprocess] processes = 2 .. note :: If you make the plugin always active by setting ``always-on`` in the ``[multiprocess]`` section of a config file, but do not set ``processes`` or pass :option:`-N`, the number of processes defaults to the number of CPUs available. Should one wish to specify the use of internet sockets for interprocess communications, specify the ``bind_address`` setting in the ``[multiprocess]`` section of the config file, for example:: [multiprocess] bind_address = 127.0.0.1:1024 This will bind to port 1024 of ``127.0.0.1``. Also:: [multiprocess] bind_address = 127.1.2.3 will bind to any random open port on ``127.1.2.3``. Any internet address or host-name which python can recognize as such, bind, *and* connect is acceptable. While ``0.0.0.0`` can be use for listening, it is not necessarily an address to which the OS can connect. When the port address is ``0`` or omitted, a random open port is used. If the setting is omitted or or blank, then sockets are not used unless nose is being executed on Windows. In which case, an address on the loop back interface and a random port are used. Whenever used, processes employ a random shared key for authentication. Guidelines for Test Authors --------------------------- Not every test suite will work well, or work at all, when run in parallel. For some test suites, parallel execution makes no sense. For others, it will expose bugs and ordering dependencies test cases and test modules. Overhead Cost ~~~~~~~~~~~~~ Starting subprocesses and dispatching tests takes time. A test run that includes a relatively small number of tests that are not I/O or CPU bound (or calling ``time.sleep()``) is likely to be *slower* when run in parallel. As of this writing, for instance, nose2's test suite takes about 10 times as long to run when using ``multiprocessing``, due to the overhead cost. Shared Fixtures ~~~~~~~~~~~~~~~ The individual test processes do not share state or data after launch. This means *tests that share a fixture* -- tests that are loaded from modules where ``setUpModule`` is defined, and tests in test classes that define ``setUpClass`` -- *must all be dispatched to the same process at the same time*. So if you use these kinds of fixtures, your test runs may be less parallel than you expect. Tests Load Twice ~~~~~~~~~~~~~~~~ Test cases may not be pickleable, so nose2 can't transmit them directly to its test runner processes. Tests are distributed by name. This means that *tests always load twice* -- once in the main process, during initial collection, and then again in the test runner process, where they are loaded by name. This may be problematic for some test suites. Random Execution Order ~~~~~~~~~~~~~~~~~~~~~~ Tests do not execute in the same order when run in parallel. Results will be returned in effectively random order, and tests in the same module (*as long as they do not share fixtures*) may execute in any order and in different processes. Some tests suites have ordering dependencies, intentional or not, and those that do will fail randomly when run with this plugin. Guidelines for Plugin Authors ----------------------------- The MultiProcess plugin is designed to work with other plugins. But other plugins may have to return the favor, especially if they load tests or care about something that happens *during* test execution. New Methods ~~~~~~~~~~~ The ``MultiProcess`` plugin adds a few plugin hooks that other plugins can use to set themselves up for multiprocess test runs. Plugins don't have to do anything special to register for these hooks, just implement the methods as normal. .. function :: registerInSubprocess(self, event) :param event: :class:`nose2.plugins.mp.RegisterInSubprocessEvent` The ``registerInSubprocess`` hook is called after plugin registration to enable plugins that need to run in subprocesses to register that fact. The most common thing to do, for plugins that need to run in subprocesses, is:: def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) It is not required that plugins append their own class. If for some reason there is a different plugin class, or set of classes, that should run in the test-running subprocesses, add that class or those classes instead. .. function :: startSubprocess(self, event) :param event: :class:`nose2.plugins.mp.SubprocessEvent` The ``startSubprocess`` hook fires in each test-running subprocess after it has loaded its plugins but before any tests are executed. Plugins can customize test execution here in the same way as in :func:`startTestRun`, by setting ``event.executeTests``, and prevent test execution by setting ``event.handled`` to True and returning False. .. function :: stopSubprocess(self, event) :param event: :class:`nose2.plugins.mp.SubprocessEvent` The ``stopSubprocess`` event fires just before each test running subprocess shuts down. Plugins can use this hook for any per-process finalization that they may need to do. The same event instance is passed to ``startSubprocess`` and ``stopSubprocess``, which enables plugins to use that event's metadata to communicate state or other information from the start to the stop hooks, if needed. New Events ~~~~~~~~~~ The ``MultiProcess`` plugin's new hooks come with custom event classes. .. autoclass :: nose2.plugins.mp.RegisterInSubprocessEvent :members: .. autoclass :: nose2.plugins.mp.SubprocessEvent :members: Stern Warning ~~~~~~~~~~~~~ All event attributes, *including ``event.metadata``, must be pickleable*. If your plugin sets any event attributes or puts anything into ``event.metadata``, it is your responsibility to ensure that anything you can possibly put in is pickleable. Do I Really Care? ~~~~~~~~~~~~~~~~~ If you answer *yes* to any of the following questions, then your plugin will not work with multiprocess testing without modification: * Does your plugin load tests? * Does your plugin capture something that happens during test execution? * Does your plugin require user interaction during test execution? * Does your plugin set executeTests in startTestRun? Here's how to handle each of those cases. Loading Tests ^^^^^^^^^^^^^ * Implement :func:`registerInSubprocess` as suggested to enable your plugin in the test runner processes. Capturing Test Execution State ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ * Implement :func:`registerInSubprocess` as suggested to enable your plugin in the test runner processes. * Be wary of setting ``event.metadata`` unconditionally. Your plugin will execute in the main process and in the test runner processes, and will see :func:`setTestOutcome` and :func:`testOutcome` events *in both processes*. If you unconditionally set a key in ``event.metadata``, the plugin instance in the main process will overwrite anything set in that key by the instance in the subprocess. * If you need to write something to a file, implement :func:`stopSubprocess` to write a file in each test runner process. Overriding Test Execution ^^^^^^^^^^^^^^^^^^^^^^^^^ * Implement :func:`registerInSubprocess` as suggested to enable your plugin in the test runner processes and make a note that your plugin is running under a multiprocess session. * When running multiprocess, *do not* set ``event.executeTests`` in :func:`startTestRun` -- instead, set it in :func:`startSubprocess` instead. This will allow the multiprocess plugin to install its test executor in the main process, while your plugin takes over test execution in the test runner subprocesses. Interacting with Users ^^^^^^^^^^^^^^^^^^^^^^ * You are probably safe because as a responsible plugin author you are already firing the interaction hooks (:func:`beforeInteraction`, :func:`afterInteraction`) around your interactive bits, and skipping them when the :func:`beforeInteraction` hook returns ``False`` and sets ``event.handled``. If you're not doing that, start! Possible Issues On Windows -------------------------- On windows, there are a few know bugs with respect to multiprocessing. First, on python 2.X or old versions of 3.X, if the __main__ module accessing nose2 is a __main__.py, an assertion in python code module ``multiprocessing.forking`` may fail. The bug for 3.2 is http://bugs.python.org/issue10845. Secondly, python on windows does not use fork(). It bootstraps from a separate interpreter invocation. In certain contexts, the "value" for a parameter will be taken as a "count" and subprocess use this to build the flag for the command-line. E.g., If this value is 2 billion (like a hash seed), subprocess.py may attempt to built a 2gig string, and possibly throw a MemoryError exception. The related bug is http://bugs.python.org/issue20954. Reference --------- .. autoplugin :: nose2.plugins.mp.MultiProcess nose2-0.6.4/docs/plugins/outcomes.rst0000664000175000017500000000023712672050004017152 0ustar travistravis=================================== Mapping exceptions to test outcomes =================================== .. autoplugin :: nose2.plugins.outcomes.Outcomes nose2-0.6.4/docs/plugins/parameters.rst0000664000175000017500000000022112672050004017450 0ustar travistravis=========================== Loader: Parameterized Tests =========================== .. autoplugin :: nose2.plugins.loader.parameters.Parameters nose2-0.6.4/docs/plugins/printhooks.rst0000664000175000017500000001170112672050004017512 0ustar travistravis====================== Tracing hook execution ====================== .. autoplugin :: nose2.plugins.printhooks.PrintHooks Sample output ------------- PrintHooks output for a test run that discovers one standard TestCase test in a python module. Hooks that appear indented are called from within other hooks. :: handleArgs: CommandLineArgsEvent(handled=False, args=Namespace(collect_only=None, config=['unittest.cfg', 'nose2.cfg'], debugger=None, fail_fast=None, load_plugins=True, log_level=30, print_hooks=None, profile=None, start_dir='.', testNames=[], top_level_directory=None, user_config=True, verbose=0, with_id=None)) createTests: CreateTestsEvent(loader=, testNames=[], module=) loadTestsFromNames: LoadFromNames(names=[], module=None) handleFile: HandleFileEvent(handled=False, loader=, name='tests.py', path='nose2/tests/functional/support/scenario/one_test/tests.py', pattern='test*.py', topLevelDirectory='nose2/tests/functional/support/scenario/one_test') matchPath: MatchPathEvent(handled=False, name='tests.py', path='nose2/tests/functional/support/scenario/one_test/tests.py', pattern='test*.py') loadTestsFromModule: LoadFromModuleEvent(handled=False, loader=, module=, extraTests=[]) loadTestsFromTestCase: LoadFromTestCaseEvent(handled=False, loader=, testCase=, extraTests=[]) getTestCaseNames: GetTestCaseNamesEvent(handled=False, loader=, testCase=, testMethodPrefix=None, extraNames=[], excludedNames=[], isTestMethod=) handleFile: HandleFileEvent(handled=False, loader=, name='tests.pyc', path='nose2/tests/functional/support/scenario/one_test/tests.pyc', pattern='test*.py', topLevelDirectory='nose2/tests/functional/support/scenario/one_test') runnerCreated: RunnerCreatedEvent(handled=False, runner=) resultCreated: ResultCreatedEvent(handled=False, result=) startTestRun: StartTestRunEvent(handled=False, runner=, suite=]>]>]>, result=, startTime=1327346684.77457, executeTests= at 0x1fccf50>) startTest: StartTestEvent(handled=False, test=, result=, startTime=1327346684.774765) reportStartTest: ReportTestEvent(handled=False, testEvent=, stream=) setTestOutcome: TestOutcomeEvent(handled=False, test=, result=, outcome='passed', exc_info=None, reason=None, expected=True, shortLabel=None, longLabel=None) testOutcome: TestOutcomeEvent(handled=False, test=, result=, outcome='passed', exc_info=None, reason=None, expected=True, shortLabel=None, longLabel=None) reportSuccess: ReportTestEvent(handled=False, testEvent=, stream=) . stopTest: StopTestEvent(handled=False, test=, result=, stopTime=1327346684.775064) stopTestRun: StopTestRunEvent(handled=False, runner=, result=, stopTime=1327346684.77513, timeTaken=0.00056004524230957031) afterTestRun: StopTestRunEvent(handled=False, runner=, result=, stopTime=1327346684.77513, timeTaken=0.00056004524230957031) beforeErrorList: ReportSummaryEvent(handled=False, stopTestEvent=, stream=, reportCategories={'failures': [], 'skipped': [], 'errors': [], 'unexpectedSuccesses': [], 'expectedFailures': []}) ---------------------------------------------------------------------- beforeSummaryReport: ReportSummaryEvent(handled=False, stopTestEvent=, stream=, reportCategories={'failures': [], 'skipped': [], 'errors': [], 'unexpectedSuccesses': [], 'expectedFailures': []}) Ran 1 test in 0.001s wasSuccessful: ResultSuccessEvent(handled=False, result=, success=False) OK afterSummaryReport: ReportSummaryEvent(handled=False, stopTestEvent=, stream=, reportCategories={'failures': [], 'skipped': [], 'errors': [], 'unexpectedSuccesses': [], 'expectedFailures': []}) nose2-0.6.4/docs/plugins/prof.rst0000664000175000017500000000011412672050004016254 0ustar travistravis========= Profiling ========= .. autoplugin :: nose2.plugins.prof.Profiler nose2-0.6.4/docs/plugins/result.rst0000664000175000017500000000017312672050004016631 0ustar travistravis====================== Reporting test results ====================== .. autoplugin :: nose2.plugins.result.ResultReporter nose2-0.6.4/docs/plugins/testcases.rst0000664000175000017500000000017112672050004017307 0ustar travistravis================== Loader: Test Cases ================== .. autoplugin :: nose2.plugins.loader.testcases.TestCaseLoader nose2-0.6.4/docs/plugins/testclasses.rst0000664000175000017500000000020212672050004017641 0ustar travistravis==================== Loader: Test Classes ==================== .. autoplugin :: nose2.plugins.loader.testclasses.TestClassLoader nose2-0.6.4/docs/plugins/testid.rst0000664000175000017500000000013412672050004016604 0ustar travistravis============== Using Test IDs ============== .. autoplugin :: nose2.plugins.testid.TestId nose2-0.6.4/docs/Makefile0000664000175000017500000001075212672050004014544 0ustar travistravis# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/nose2.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/nose2.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/nose2" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/nose2" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." make -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." nose2-0.6.4/docs/changelog.rst0000664000175000017500000001101012672050004015551 0ustar travistravisChangelog ========= 0.6.4 ----- * Fixed * fix deadlock in mp plugin 0.6.3 ----- * Added * python 3.5 support 0.6.2 ----- * Fixed * fix the coverage plugin tests for coverage==3.7.1 0.6.1 ----- * Fixed * missing test files added to package. 0.6.0 ----- * Added * Junit XML report support properties * Improve test coverage * Improve CI * Add a `createdTestSuite` event, fired after test loading * Fixed * Junit-xml plugin fixed on windows * Ensure tests are importable before trying to load them * Fail test instead of skipping it, when setup fails * When test loading fails, print the traceback * Make the ``collect`` plugin work with layers * Fix coverage plugin to take import-time coverage into account 0.4.7 ----- * Feature: Added start-dir config option. Thanks to Stéphane Klein. * Bug: Fixed broken import in collector.py. Thanks to Shaun Crampton. * Bug: Fixed processes command line option in mp plugin. Thanks to Tim Sampson. * Bug: Fixed handling of class fixtures in multiprocess plugin. Thanks to Tim Sampson. * Bug: Fixed intermittent test failure caused by nondeterministic key ordering. Thanks to Stéphane Klein. * Bug: Fixed syntax error in printhooks. Thanks to Tim Sampson. * Docs: Fixed formatting in changelog. Thanks to Omer Katz. * Docs: Added help text for verbose flag. Thanks to Tim Sampson. * Docs: Fixed typos in docs and examples. Thanks to Tim Sampson. * Docs: Added badges to README. Thanks to Omer Katz. * Updated six version requirement to be less Restrictive. Thanks to Stéphane Klein. * Cleaned up numerous PEP8 violations. Thanks to Omer Katz. 0.4.6 ----- * Bug: fixed DeprecationWarning for compiler package on python 2.7. Thanks Max Arnold. * Bug: fixed lack of timing information in junitxml exception reports. Thanks Viacheslav Dukalskiy. * Bug: cleaned up junitxml xml output. Thanks Philip Thiem. * Docs: noted support for python 3.3. Thanks Omer Katz for the bug report. 0.4.5 ----- * Bug: fixed broken interaction between attrib and layers plugins. They can now be used together. Thanks @fajpunk. * Bug: fixed incorrect calling order of layer setup/teardown and test setup/test teardown methods. Thanks again @fajpunk for tests and fixes. 0.4.4 ----- * Bug: fixed sort key generation for layers. 0.4.3 ----- * Bug: fixed packaging for non-setuptools, pre-python 2.7. Thanks to fajpunk for the patch. 0.4.2 ----- * Bug: fixed unpredictable ordering of layer tests. * Added ``uses`` method to ``such.Scenario`` to allow use of externally-defined layers in such DSL tests. 0.4.1 ----- * Fixed packaging bug. 0.4 --- * New plugin: Added nose2.plugins.layers to support Zope testing style fixture layers. * New tool: Added nose2.tools.such, a spec-like DSL for writing tests with layers. * New plugin: Added nose2.plugins.loader.loadtests to support the unittest2 load_tests protocol. 0.3 --- * New plugin: Added nose2.plugins.mp to support distributing test runs across multiple processes. * New plugin: Added nose2.plugins.testclasses to support loading tests from ordinary classes that are not subclasses of unittest.TestCase. * The default script target was changed from ``nose2.main`` to ``nose2.discover``. The former may still be used for running a single module of tests, unittest-style. The latter ignores the ``module`` argument. Thanks to @dtcaciuc for the bug report (#32). * ``nose2.main.PluggableTestProgram`` now accepts an ``extraHooks`` keyword argument, which allows attaching arbitrary objects to the hooks system. * Bug: Fixed bug that caused Skip reason to always be set to ``None``. 0.2 --- * New plugin: Added nose2.plugins.junitxml to support jUnit XML output. * New plugin: Added nose2.plugins.attrib to support test filtering by attributes. * New hook: Added afterTestRun hook, moved result report output calls to that hook. This prevents plugin ordering issues with the stopTestRun hook (which still exists, and fires before afterTestRun). * Bug: Fixed bug in loading of tests by name that caused ImportErrors to be silently ignored. * Bug: Fixed missing __unittest flag in several modules. Thanks to Wouter Overmeire for the patch. * Bug: Fixed module fixture calls for function, generator and param tests. * Bug: Fixed passing of command-line argument values to list options. Before this fix, lists of lists would be appended to the option target. Now, the option target list is extended with the new values. Thanks to memedough for the bug report. 0.1 --- Initial release. nose2-0.6.4/docs/conf.py0000664000175000017500000001625712672050004014411 0ustar travistravis# -*- coding: utf-8 -*- # # nose2 documentation build configuration file, created by # sphinx-quickstart on Thu Oct 7 15:16:09 2010. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys, os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('..')) sys.path.append(os.path.abspath('_themes')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.todo', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', 'nose2.sphinxext'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = u'nose2' copyright = u'2010, Jason Pellerin' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = '0.4' # The full version, including alpha/beta/rc tags. release = '0.4.7' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['_build'] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. html_theme_path = ['_themes'] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". #html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'nose2doc' # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). #latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). #latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'nose2.tex', u'nose2 Documentation', u'Jason Pellerin', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Additional stuff for the LaTeX preamble. #latex_preamble = '' # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'nose2', u'nose2 Documentation', [u'Jason Pellerin'], 1) ] # Example configuration for intersphinx: refer to the Python standard library. intersphinx_mapping = {'python': ('http://docs.python.org/', None)} nose2-0.6.4/docs/configuration.rst0000664000175000017500000001506712672050004016511 0ustar travistravisConfiguring nose2 ================= Configuration Files ------------------- Most configuration of nose2 is done via config files. These are standard, .ini-style config files, with sections marked off by brackets ("``[unittest]``") and ``key = value`` pairs within those sections. Two command line options, :option:`-c` and :option:`--no-user-config` may be used to determine which config files are loaded. .. cmdoption :: -c CONFIG, --config CONFIG Config files to load. Default behavior is to look for ``unittest.cfg`` and ``nose2.cfg`` in the start directory, as well as any user config files (unless :option:`--no-user-config` is selected). .. cmdoption :: --no-user-config Do not load user config files. If not specified, in addition to the standard config files and any specified with :option:`-c`, nose2 will look for ``.unittest.cfg`` and ``.nose2.cfg`` in the user's $HOME directory. Configuring Test Discovery ~~~~~~~~~~~~~~~~~~~~~~~~~~ The ``[unittest]`` section of nose2 config files is used to configure nose2 itself. The following options are available to configure test discovery: .. rst:configvar :: start-dir This option configures the default directory to start discovery. The default value is ``"."`` (the current directory where nose2 is executed). This directory is where nose2 will start looking for tests. .. rst:configvar :: code-directories This option configures nose2 to add the named directories to sys.path and the discovery path. Use this if your project has code in a location other than the top level of the project, or the directories ``lib`` or ``src``. The value here may be a list: put each directory on its own line in the config file. .. rst:configvar :: test-file-pattern This option configures how nose detects test modules. It is a file glob. .. rst:configvar :: test-method-prefix This option configures how nose detects test functions and methods. The prefix set here will be matched (via simple string matching) against the start of the name of each method in test cases and each function in test modules. Examples: .. code-block :: ini [unittest] start-dir = tests code-directories = source more_source test-file-pattern = *_test.py test-method-prefix = t Specifying Plugins to Load ~~~~~~~~~~~~~~~~~~~~~~~~~~ To avoid loading any plugins, use the :option:`--no-plugins` option. Beware, though: nose2 does all test discovery and loading via plugins, so unless you are patching in a custom test loader and runner, when run with :option:`--no-plugins`, nose2 will do nothing. .. cmdoption :: --no-plugins Do not load any plugins. *This kills the nose2.* To specify plugins to load beyond the builtin plugins automatically loaded, add a :config:`plugins` entry under the ``[unittest]`` section in a config file. .. rst:configvar :: plugins List of plugins to load. Put one plugin module on each line. To exclude some plugins that would otherwise be loaded, add an :config:`exclude-plugins` entry under the ``[unittest]`` section in a config file. .. rst:configvar :: exclude-plugins List of plugins to exclude. Put one plugin module on each line. .. note :: It bears repeating that in both :config:`plugins` and :config:`exclude-plugins` entries, you specify the plugin *module*, not the plugin *class*. Examples: .. code-block :: ini [unittest] plugins = myproject.plugins.frobulate otherproject.contrib.plugins.derper exclude-plugins = nose2.plugins.loader.functions nose2.plugins.outcomes Configuring Plugins ------------------- Most plugins specify a config file section that may be used to configure the plugin. If nothing else, any plugin that specifies a config file section can be set to automatically register by including ``always-on = True`` in its config: .. code-block :: ini [my-plugin] always-on = True Plugins may accept any number of other config values, which may be booleans, strings, integers or lists. A polite plugin will document these options somewhere. Plugins that want to make use of nose2's `Sphinx`_ extension as detailed in :doc:`dev/documenting_plugins` *must* extract all of their config values in their ``__init__`` methods. .. _Sphinx : http://sphinx.pocoo.org/ Test Runner Tips and Tweaks --------------------------- Running Tests in a Single Module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can use ``nose2.main`` in the same way that ``unittest.main`` (and ``unittest2.main``) have historically worked: to run the tests in a single module. Just put a block like the following at the end of the module:: if __name__ == '__main__': import nose2 nose2.main() Then *run the module directly* -- In other words, do not run the ``nose2`` script. Rolling Your Own Runner ~~~~~~~~~~~~~~~~~~~~~~~ You can take more control over the test runner by foregoing the ``nose2`` script and rolling your own. To do that, you just need to write a script that calls ``nose2.discover``, for instance:: if __name__ == '__main__': import nose2 nose2.discover() You can pass several keyword arguments to ``nose2.discover``, all of which are detailed in the documentation for :class:`nose2.main.PluggableTestProgram`. Altering the Default Plugin Set ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To add plugin *modules* to the list of those automatically loaded, you can pass a list of module names to add (the ``plugins``) argument or exclude (``excludedPlugins``). You can also subclass :class:`nose2.main.PluggableTestProgram` and set the class-level ``defaultPlugins`` and ``excludePlugins`` attributes to alter plugin loading. When Loading Plugins from Modules is not Enough ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ **None of which will help** if you need to register a plugin *instance* that you've loaded yourself. For that, use the ``extraHooks`` keyword argument to ``nose2.discover``. Here, you pass in a list of 2-tuples, each of which contains a hook name and a plugin *instance* to register for that hook. This allows you to register plugins that need runtime configuration that is not easily passed in through normal channels -- and also to register *objects that are not nose2 plugins* as hook targets. Here's a trivial example:: if __name__ == '__main__': import nose2 class Hello(object): def startTestRun(self, event): print("hello!") nose2.discover(extraHooks=[('startTestRun', Hello())]) This can come in handy when integrating with other systems that expect you to provide a test runner that they execute, rather than executing tests yourself (django, for instance). nose2-0.6.4/docs/contents.rst.inc0000664000175000017500000000110412672050004016232 0ustar travistravisUser's Guide ============ .. toctree:: :maxdepth: 2 getting_started usage configuration differences plugins tools changelog Plugin Developer's Guide ======================== .. toctree :: :maxdepth: 2 dev/writing_plugins dev/documenting_plugins dev/event_reference dev/hook_reference dev/session_reference dev/plugin_class_reference Developer's Guide ================= .. toctree:: :maxdepth: 2 dev/contributing dev/internals Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` nose2-0.6.4/docs/decorators.rst0000664000175000017500000000037312672050004016001 0ustar travistravis========== Decorators ========== nose2 ships with various decorators that assist you to write your tests. Setup & Teardown ================ .. autofunction :: nose2.tools.decorators.with_setup .. autofunction :: nose2.tools.decorators.with_teardownnose2-0.6.4/docs/differences.rst0000664000175000017500000001434112672050004016111 0ustar travistravisDifferences: nose2 vs nose vs unittest2 ======================================= nose2 is not nose ----------------- What's Different ~~~~~~~~~~~~~~~~ Python Versions ^^^^^^^^^^^^^^^ nose supports Python 2.4 and above, but nose2 *only supports Python 2.6, 2.7, 3.2, 3.3 and pypy*. Unfortunately, supporting Pythons older than 2.6 along with Python 3 in the same codebase is not practical. Since that is one of the core goals of nose2, support for older versions of Python had to be sacrificed. Test Discovery and Loading ^^^^^^^^^^^^^^^^^^^^^^^^^^ nose loads test modules lazily: tests in the first-loaded module are executed before the second module is imported. *nose2 loads all tests first, then begins test execution*. This has some important implications. First, it means that nose2 does not need a custom importer. nose2 imports test modules with :func:`__import__`. Second, it means that *nose2 does not support all of the test project layouts that nose does*. Specifically, projects that look like this will fail to load tests correctly with nose2:: . `-- tests |-- more_tests | `-- test.py `-- test.py To nose's loader, those two test modules look like different modules. But to nose2's loader, they look the same, and will not load correctly. Test Fixtures ^^^^^^^^^^^^^ nose2 supports only the *same levels of fixtures as unittest2*. This means class level fixtures and module level fixtures are supported, but *package-level fixtures are not*. In addition, unlike nose, nose2 does not attempt to order tests named on the command-line to group those with the same fixtures together. Parameterized and Generator Tests ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ nose2 supports *more kinds of parameterized and generator tests than nose*, and supports all test generators in test functions, test classes, and in unittest TestCase subclasses. nose supports them only in test functions and test classes that do not subclass unittest.TestCase. See: :doc:`plugins/generators` and :doc:`plugins/parameters` for more. Configuration ^^^^^^^^^^^^^ nose expects plugins to make all of their configuration parameters available as command-line options. *nose2 expects almost all configuration to be done via configuration files*. Plugins should generally have only one command-line option: the option to activate the plugin. Other configuration parameters should be loaded from config files. This allows more repeatable test runs and keeps the set of command-line options small enough for humans to read. See: :doc:`configuration` for more. Plugin Loading ^^^^^^^^^^^^^^ nose uses setuptools entry points to find and load plugins. nose2 does not. Instead, *nose2 requires that all plugins be listed in config files*. This ensures that no plugin is loaded into a test system just by virtue of being installed somewhere, and makes it easier to include plugins that are part of the project under test. See: :doc:`configuration` for more. Limited support for ``python setup.py test`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ nose2 supports setuptools' ``python setup.test`` command, but via very different means than nose. To avoid the internal complexity forced on nose by the fact that the setuptools test command can't be configured with a custom test runner, when run this way, *nose2 essentially hijacks the test running process*. The "test suite" that :func:`nose2.collector.collector` returns actually *is* a test runner, cloaked inside of a test case. It loads and runs tests as normal, setting up its own test runner and test result, and calls ``sys.exit()`` itself -- completely bypassing the test runner and test result that setuptools/unittest create. This may be incompatible with some projects. New Plugin API ^^^^^^^^^^^^^^ nose2 implements a new plugin API based on the work done by Michael Foord in unittest2's ``plugins`` branch. This API is greatly superior to the one in nose, especially in how it allows plugins to interact with each other. But it is different enough from the API in nose that supporting nose plugins in nose2 will not be practical: *plugins must be rewritten to work with nose2*. See: :doc:`dev/writing_plugins` for more. Missing Plugins ^^^^^^^^^^^^^^^ *nose2 does not (yet) include some of the more commonly-used plugins in nose*. Most of these should arrive in future releases. However, some of nose's builtin plugins cannot be ported to nose2 due to differences in internals. See: :doc:`plugins` for information on the plugins built in to nose2. Internals ^^^^^^^^^ nose wraps or replaces everything in unittest. nose2 does a bit less: *it does not wrap TestCases*, and does not wrap the test result class with a result proxy. nose2 does subclass :class:`TestProgram`, and install its own loader, runner, and result classes. It does this unconditionally, rather than allowing arguments to ``TestProgram.__init__()`` to specify the test loader and runner. See :doc:`dev/internals` for more information. License ^^^^^^^ While nose was LGPL, nose2 is BSD licensed. This change was made at the request of the majority of nose contributors. What's the Same ~~~~~~~~~~~~~~~ Philosophy ^^^^^^^^^^ nose2 has the same goals as nose: to extend unittest to make testing nicer and easier to understand. It aims to give developers flexibility, power and transparency, so that common test scenarios require no extra work, and uncommon test scenarios can be supported with minimal fuss and magic. People ^^^^^^ nose2 is being developed by the same people who maintain nose. nose2 is not (exactly) unittest2/plugins ---------------------------------------- nose2 is based on the unittest2 ``plugins`` branch, but differs from it in several substantial ways. The *event api not exactly the same* because nose2 can't replace unittest.TestCase, and *does not configure the test run or plugin set globally*. nose2 also has a *wholly different reporting API* from unittest2's plugins, one which we feel better supports some common cases (like adding extra information to error output). nose2 also *defers more work to plugins* than unittest2: the test loader, runner and result are just plugin callers, and all of the logic of test discovery, running and reporting is implemented in plugins. This means that unlike unittest2, *nose2 includes a substantial set of plugins that are active by default*. nose2-0.6.4/docs/getting_started.rst0000664000175000017500000000403512672050004017022 0ustar travistravisGetting started with nose2 ========================== Installation ------------ The recommended way to install nose2 is with `pip`_ :: pip install nose2 You can also install from source by downloading the source distribution from `pypi`_, un-taring it, and running ``python setup.py install`` in the source directory. Note that if you install this way, and do not have distribute or setuptools installed, you must install nose2's dependencies manually. Dependencies ~~~~~~~~~~~~ For Python 2.7, Python 3.2 and pypy, nose2 requires `six`_ version 1.1. For Python 2.6, nose2 also requires `argparse`_ version 1.2.1 and `unittest2`_ version 0.5.1. When installing with pip, distribute or setuptools, these dependencies will be installed automatically. Development version ~~~~~~~~~~~~~~~~~~~ You can install the development version of nose2 from github with `pip`_:: pip install -e git+git://github.com/nose-devs/nose2.git#egg=nose2 You can also download a package from github, or clone the source and install from there with ``python setup.py install``. Running tests ------------- To run tests in a project, use the ``nose2`` script that is installed with nose2:: nose2 This will find and run tests in all packages in the current working directory, and any sub-directories of the current working directory whose names start with 'test'. To find tests, nose2 looks for modules whose names start with 'test'. In those modules, nose2 will load tests from all :class:`unittest.TestCase` subclasses, as well as functions whose names start with 'test'. .. todo :: ... and other classes whose names start with 'Test'. The ``nose2`` script supports a number of command-line options, as well as extensive configuration via config files. For more information see :doc:`usage` and :doc:`configuration`. .. _pip : http://pypi.python.org/pypi/pip/1.0.2 .. _pypi : http://pypi.python.org/pypi .. _six : http://pypi.python.org/pypi/six/1.1.0 .. _argparse : http://pypi.python.org/pypi/argparse/1.2.1 .. _unittest2 : http://pypi.python.org/pypi/unittest2/0.5.1 nose2-0.6.4/docs/index.rst0000664000175000017500000000010612672050004014735 0ustar travistravis:orphan: .. include :: ../README.rst .. include :: contents.rst.inc nose2-0.6.4/docs/params.rst0000664000175000017500000000021012672050004015105 0ustar travistravis=================== Parameterized tests =================== .. autofunction :: nose2.tools.params See also: :doc:`plugins/parameters` nose2-0.6.4/docs/plugins.rst0000664000175000017500000000345512672050004015321 0ustar travistravis================= Plugins for nose2 ================= Built in and Loaded by Default ============================== These plugins are loaded by default. To exclude one of these plugins from loading, add the plugin's module name to the ``exclude-plugins`` list in a config file's ``[unittest]`` section, or pass the plugin module with the ``--exclude-plugin`` argument on the command line. You can also pass plugin module names to exclude to a :class:`nose2.main.PluggableTestProgram` using the ``excludePlugins`` keyword argument. .. toctree:: :maxdepth: 2 plugins/discovery plugins/functions plugins/generators plugins/parameters plugins/testcases plugins/testclasses plugins/loadtests plugins/dundertests plugins/result plugins/buffer plugins/debugger plugins/failfast plugins/logcapture plugins/coverage Built in but *not* Loaded by Default ==================================== These plugins are available as part of the nose2 package but *are not loaded by default*. To load one of these plugins, add the plugin module name to the ``plugins`` list in a config file's ``[unittest]`` section, or pass the plugin module with the ``--plugin`` argument on the command line. You can also pass plugin module names to a :class:`nose2.main.PluggableTestProgram` using the ``plugins`` keyword argument. .. toctree:: :maxdepth: 2 plugins/junitxml plugins/attrib plugins/mp plugins/layers plugins/doctests plugins/outcomes plugins/collect plugins/testid plugins/prof plugins/printhooks plugins/eggdiscovery Third-party Plugins =================== If you are a plugin author, please add your plugin to the list on the `nose2 wiki`_. If you are looking for more plugins, check that list! .. _nose2 wiki : https://github.com/nose-devs/nose2/wiki/Plugins nose2-0.6.4/docs/such_dsl.rst0000664000175000017500000001142612672050004015441 0ustar travistravis====================================== Such: a Functional-Test Friendly DSL ====================================== .. note :: New in version 0.4 Such is a DSL for writing tests with expensive, nested fixtures -- which typically means functional tests. It requires the layers plugin (see :doc:`plugins/layers`). What does it look like? ======================= Unlike some python testing DSLs, such is just plain old python. .. literalinclude :: ../nose2/tests/functional/support/such/test_such.py :language: python The tests it defines are unittest tests, and can be used with nose2 with just the layers plugin. You also have the option of activating a reporting plugin (:class:`nose2.plugins.layers.LayerReporter`) to provide a more discursive brand of output: .. literalinclude :: ../nose2/tests/functional/support/such/output.txt How does it work? ================= Such uses the things in python that are most like anonymous code blocks to allow you to construct tests with meaningful names and deeply-nested fixtures. Compared to DSLs in languages that do allow blocks, it is a little bit more verbose -- the block-like decorators that mark fixture methods and test cases need to decorate *something*, so each fixture and test case has to have a function definition. You can use the same function name over and over here, or give each function a meaningful name. The set of tests begins with a description of the system under test as a whole, marked with the ``A`` context manager: .. code-block :: python from nose2.tools import such with such.A('system described here') as it: # ... Groups of tests are marked by the ``having`` context manager: .. code-block :: python with it.having('a description of a group'): # ... Within a test group (including the top-level group), fixtures are marked with decorators: .. code-block :: python @it.has_setup def setup(): # ... @it.has_test_setup def setup_each_test_case(): # ... And tests are likewise marked with the ``should`` decorator: .. code-block :: python @it.should('exhibit the behavior described here') def test(case): # ... Test cases may optionally take one argument. If they do, they will be passed the :class:`unittest.TestCase` instance generated for the test. They can use this ``TestCase`` instance to execute assert methods, among other things. Test functions can also call assert methods on the top-level scenario instance, if they don't take the ``case`` argument: .. code-block :: python @it.should("be able to use the scenario's assert methods") def test(): it.assertEqual(something, 'a value') @it.should("optionally take an argument") def test(case): case.assertEqual(case.attribute, 'some value') Finally, to actually generate tests, you **must** call ``createTests`` on the top-level scenario instance: .. code-block :: python it.createTests(globals()) This call generates the :class:`unittest.TestCase` instances for all of the tests, and the layer classes that hold the fixtures defined in the test groups. See :doc:`plugins/layers` for more about test layers. Running tests ------------- Since order is often significant in functional tests, **such DSL tests always execute in the order in which they are defined in the module**. Parent groups run before child groups, and sibling groups and sibling tests within a group execute in the order in which they are defined. Otherwise, tests written in the such DSL are collected and run just like any other tests, with one exception: their names. The name of a such test case is the name of its immediately surrounding group, plus the description of the test, prepended with ``test ####:``, where ``####`` is the test's (``0`` -indexed) position within its group. To run a case individually, you must pass in this full name -- usually you'll have to quote it. For example, to run the case ``should do more things`` defined above (assuming the layers plugin is activated by a config file, and the test module is in the normal path of test collection), you would run nose2 like this:: nose2 "test_such.having an expensive fixture.test 0000: should do more things" That is, for the a generated test case, the **group description** is the **class name**, and the **test case description** is the **test case name**. As you can see if you run an individual test with the layer reporter active, all of the group fixtures execute in proper order when a test is run individually:: $ nose2 "test_such.having an expensive fixture.test 0000: should do more things" A system with complex setup having an expensive fixture should do more things ... ok ---------------------------------------------------------------------- Ran 1 test in 0.000s OK Reference ========= .. automodule :: nose2.tools.such :members: A, Scenario nose2-0.6.4/docs/tools.rst0000664000175000017500000000025112672050004014767 0ustar travistravis================= Tools and Helpers ================= Tools for Test Authors ====================== .. toctree :: :maxdepth: 2 decorators params such_dsl nose2-0.6.4/docs/usage.rst0000664000175000017500000001345112672050004014741 0ustar travistravisUsing nose2 =========== Naming Tests ------------ nose2 will look in each directory under the starting directory, unless the configuration modifies the included paths. Within directories and within any Python packages found in the starting directory and any source directories in the starting directory, nose2 will discover test modules and load tests from them. "Test modules" means any modules whose names start with "test". See the Configuration section for ways to modify searching for tests. Directories nose2 will look in: * Directory that contains an ``__init__.py`` file (a Python package) * Directory name that contains "test" after being lowercased. * Directory name that is either ``lib`` or ``src`` Each of the following test files will be run:: test.py test_views.py test_models.py testThingy.py These files will not be run:: not_a_test.py myapp_test.py some_test_file.py Within test modules, nose2 will load tests from :class:`unittest.TestCase` subclasses, and from test functions (functions whose names begin with "test"). Running Tests ------------- In the simplest case, go to the directory that includes your project source and run ``nose2`` there:: nose2 This will discover tests in packages and test directories under that directory, load them, and run them, then output something like:: ............................................................................. ---------------------------------------------------------------------- Ran 77 tests in 1.897s OK .. todo :: ... and test classes (classes whose names begin with "Test") To change the place discovery starts, or to change the top-level importable directory of the project, use the :option:`-s` and :option:`-t` options. .. cmdoption :: -s START_DIR, --start-dir START_DIR Directory to start discovery. Defaults to the current working directory. This directory is where nose2 will start looking for tests. .. cmdoption :: -t TOP_LEVEL_DIRECTORY, --top-level-directory TOP_LEVEL_DIRECTORY, --project-directory TOP_LEVEL_DIRECTORY Top-level directory of the project. Defaults to the starting directory. This is the directory containing importable modules and packages, and is always prepended to ``sys.path`` before test discovery begins. Specifying Tests to Run ~~~~~~~~~~~~~~~~~~~~~~~ Pass *test names* to nose2 on the command line to run individual test modules, classes, or tests. A test name consists of a *python object part* and, for generator or parameterized tests, an *argument part*. The *python object part* is a dotted name, such as ``pkg1.tests.test_things.SomeTests.test_ok``. The argument part is separated from the python object part by a colon (":") and specifies the *index* of the generated test to select, *starting from 1*. For example, ``pkg1.test.test_things.test_params_func:1`` would select the *first* test generated from the parameterized test ``test_params_func``. Plugins may provide other means of test selection. Running Tests with ``python setup.py test`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ nose2 supports distribute/setuptools' ``python setup.py test`` standard for running tests. To use nose2 to run your package's tests, add the following to your setup.py:: setup(... test_suite='nose2.collector.collector', ... ) (Not literally. Don't put the '...' parts in.) Two warnings about running tests this way. One: because the setuptools test command is limited, nose2 returns a "test suite" that actually takes over the test running process completely, bypassing the test result and test runner that call it. This may be incompatible with some packages. Two: because the command line arguments to the test command may not match up properly with nose2's arguments, the nose2 instance started by the collector *does not accept any command line arguments*. This means that it always runs all tests, and that you cannot configure plugins on the command line when running tests this way. As a workaround, when running under the test command, nose2 will read configuration from ``setup.cfg`` if it is present, in addition to ``unittest.cfg`` and ``nose2.cfg``. This enables you to put configuration specific to the setuptools test command in ``setup.cfg`` -- for instance to activate plugins that you would otherwise activate via the command line. Getting Help ------------ Run:: nose2 -h to get help for nose2 itself and all loaded plugins. :: usage: nose2 [-s START_DIR] [-t TOP_LEVEL_DIRECTORY] [--config [CONFIG]] [--no-user-config] [--no-plugins] [--verbose] [--quiet] [-B] [-D] [--collect-only] [--log-capture] [-P] [-h] [testNames [testNames ...]] positional arguments: testNames optional arguments: -s START_DIR, --start-dir START_DIR Directory to start discovery ('.' default) -t TOP_LEVEL_DIRECTORY, --top-level-directory TOP_LEVEL_DIRECTORY, --project-directory TOP_LEVEL_DIRECTORY Top level directory of project (defaults to start dir) --config [CONFIG], -c [CONFIG] Config files to load, if they exist. ('unittest.cfg' and 'nose2.cfg' in start directory default) --no-user-config Do not load user config files --no-plugins Do not load any plugins. Warning: nose2 does not do anything if no plugins are loaded --verbose, -v --quiet -h, --help Show this help message and exit plugin arguments: Command-line arguments added by plugins: -B, --output-buffer Enable output buffer -D, --debugger Enter pdb on test fail or error --collect-only Collect and output test names, do not run any tests --log-capture Enable log capture -P, --print-hooks Print names of hooks in order of execution nose2-0.6.4/nose2/0000775000175000017500000000000012672050226013203 5ustar travistravisnose2-0.6.4/nose2/backports/0000775000175000017500000000000012672050226015173 5ustar travistravisnose2-0.6.4/nose2/backports/__init__.py0000664000175000017500000000000012672050004017264 0ustar travistravisnose2-0.6.4/nose2/backports/ordereddict.py0000664000175000017500000002140312672050004020027 0ustar travistravis# {{{ http://code.activestate.com/recipes/576693/ (r9) # Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and pypy. # Passes Python2.7's test suite and incorporates all the latest updates. try: from thread import get_ident as _get_ident except ImportError: from dummy_thread import get_ident as _get_ident try: from _abcoll import KeysView, ValuesView, ItemsView except ImportError: pass class OrderedDict(dict): 'Dictionary that remembers insertion order' # An inherited dict maps keys to values. # The inherited dict provides __getitem__, __len__, __contains__, and get. # The remaining methods are order-aware. # Big-O running times for all methods are the same as for regular # dictionaries. # The internal self.__map dictionary maps keys to links in a doubly linked list. # The circular doubly linked list starts and ends with a sentinel element. # The sentinel element never gets deleted (this simplifies the algorithm). # Each link is stored as a list of length three: [PREV, NEXT, KEY]. def __init__(self, *args, **kwds): '''Initialize an ordered dictionary. Signature is the same as for regular dictionaries, but keyword arguments are not recommended because their insertion order is arbitrary. ''' if len(args) > 1: raise TypeError('expected at most 1 arguments, got %d' % len(args)) try: self.__root except AttributeError: self.__root = root = [] # sentinel node root[:] = [root, root, None] self.__map = {} self.__update(*args, **kwds) def __setitem__(self, key, value, dict_setitem=dict.__setitem__): 'od.__setitem__(i, y) <==> od[i]=y' # Setting a new item creates a new link which goes at the end of the linked # list, and the inherited dictionary is updated with the new key/value # pair. if key not in self: root = self.__root last = root[0] last[1] = root[0] = self.__map[key] = [last, root, key] dict_setitem(self, key, value) def __delitem__(self, key, dict_delitem=dict.__delitem__): 'od.__delitem__(y) <==> del od[y]' # Deleting an existing item uses self.__map to find the link which is # then removed by updating the links in the predecessor and successor # nodes. dict_delitem(self, key) link_prev, link_next, key = self.__map.pop(key) link_prev[1] = link_next link_next[0] = link_prev def __iter__(self): 'od.__iter__() <==> iter(od)' root = self.__root curr = root[1] while curr is not root: yield curr[2] curr = curr[1] def __reversed__(self): 'od.__reversed__() <==> reversed(od)' root = self.__root curr = root[0] while curr is not root: yield curr[2] curr = curr[0] def clear(self): 'od.clear() -> None. Remove all items from od.' try: for node in self.__map.itervalues(): del node[:] root = self.__root root[:] = [root, root, None] self.__map.clear() except AttributeError: pass dict.clear(self) def popitem(self, last=True): '''od.popitem() -> (k, v), return and remove a (key, value) pair. Pairs are returned in LIFO order if last is true or FIFO order if false. ''' if not self: raise KeyError('dictionary is empty') root = self.__root if last: link = root[0] link_prev = link[0] link_prev[1] = root root[0] = link_prev else: link = root[1] link_next = link[1] root[1] = link_next link_next[0] = root key = link[2] del self.__map[key] value = dict.pop(self, key) return key, value # -- the following methods do not depend on the internal structure -- def keys(self): 'od.keys() -> list of keys in od' return list(self) def values(self): 'od.values() -> list of values in od' return [self[key] for key in self] def items(self): 'od.items() -> list of (key, value) pairs in od' return [(key, self[key]) for key in self] def iterkeys(self): 'od.iterkeys() -> an iterator over the keys in od' return iter(self) def itervalues(self): 'od.itervalues -> an iterator over the values in od' for k in self: yield self[k] def iteritems(self): 'od.iteritems -> an iterator over the (key, value) items in od' for k in self: yield (k, self[k]) def update(*args, **kwds): '''od.update(E, **F) -> None. Update od from dict/iterable E and F. If E is a dict instance, does: for k in E: od[k] = E[k] If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] Or if E is an iterable of items, does: for k, v in E: od[k] = v In either case, this is followed by: for k, v in F.items(): od[k] = v ''' if len(args) > 2: raise TypeError('update() takes at most 2 positional ' 'arguments (%d given)' % (len(args),)) elif not args: raise TypeError('update() takes at least 1 argument (0 given)') self = args[0] # Make progressively weaker assumptions about "other" other = () if len(args) == 2: other = args[1] if isinstance(other, dict): for key in other: self[key] = other[key] elif hasattr(other, 'keys'): for key in other.keys(): self[key] = other[key] else: for key, value in other: self[key] = value for key, value in kwds.items(): self[key] = value __update = update # let subclasses override update without breaking __init__ __marker = object() def pop(self, key, default=__marker): '''od.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised. ''' if key in self: result = self[key] del self[key] return result if default is self.__marker: raise KeyError(key) return default def setdefault(self, key, default=None): 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od' if key in self: return self[key] self[key] = default return default def __repr__(self, _repr_running={}): 'od.__repr__() <==> repr(od)' call_key = id(self), _get_ident() if call_key in _repr_running: return '...' _repr_running[call_key] = 1 try: if not self: return '%s()' % (self.__class__.__name__,) return '%s(%r)' % (self.__class__.__name__, self.items()) finally: del _repr_running[call_key] def __reduce__(self): 'Return state information for pickling' items = [[k, self[k]] for k in self] inst_dict = vars(self).copy() for k in vars(OrderedDict()): inst_dict.pop(k, None) if inst_dict: return (self.__class__, (items,), inst_dict) return self.__class__, (items,) def copy(self): 'od.copy() -> a shallow copy of od' return self.__class__(self) @classmethod def fromkeys(cls, iterable, value=None): '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S and values equal to v (which defaults to None). ''' d = cls() for key in iterable: d[key] = value return d def __eq__(self, other): '''od.__eq__(y) <==> od==y. Comparison to another OD is order-sensitive while comparison to a regular mapping is order-insensitive. ''' if isinstance(other, OrderedDict): return len(self) == len(other) and self.items() == other.items() return dict.__eq__(self, other) def __ne__(self, other): return not self == other # -- the following methods are only used in Python 2.7 -- def viewkeys(self): "od.viewkeys() -> a set-like object providing a view on od's keys" return KeysView(self) def viewvalues(self): "od.viewvalues() -> an object providing a view on od's values" return ValuesView(self) def viewitems(self): "od.viewitems() -> a set-like object providing a view on od's items" return ItemsView(self) # end of http://code.activestate.com/recipes/576693/ }}} nose2-0.6.4/nose2/plugins/0000775000175000017500000000000012672050226014664 5ustar travistravisnose2-0.6.4/nose2/plugins/loader/0000775000175000017500000000000012672050226016132 5ustar travistravisnose2-0.6.4/nose2/plugins/loader/__init__.py0000664000175000017500000000000012672050004020223 0ustar travistravisnose2-0.6.4/nose2/plugins/loader/discovery.py0000664000175000017500000002235312672050004020512 0ustar travistravis""" Discovery-based test loader. This plugin implements nose2's automatic test module discovery. It looks for test modules in packages and directories whose names start with ``test``, then fires the :func:`loadTestsFromModule` hook for each one to allow other plugins to load the actual tests. It also fires :func:`handleFile` for every file that it sees, and :func:`matchPath` for every Python module, to allow other plugins to load tests from other kinds of files and to influence which modules are examined for tests. """ # Adapted from unittest2/loader.py from the unittest2 plugins branch. # This module contains some code copied from unittest2/loader.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html from fnmatch import fnmatch import logging import os import sys from nose2 import events, util __unittest = True log = logging.getLogger(__name__) class DirectoryHandler(object): def __init__(self, session): self.session = session self.event_handled = False def handle_dir(self, event, full_path, top_level): dirname = os.path.basename(full_path) pattern = self.session.testFilePattern evt = events.HandleFileEvent( event.loader, dirname, full_path, pattern, top_level) result = self.session.hooks.handleDir(evt) if evt.extraTests: for test in evt.extraTests: yield test if evt.handled: if result: yield result self.event_handled = True return evt = events.MatchPathEvent(dirname, full_path, pattern) result = self.session.hooks.matchDirPath(evt) if evt.handled and not result: self.event_handled = True class Discoverer(object): def loadTestsFromName(self, event): """Load tests from module named by event.name""" # turn name into path or module name # fire appropriate hooks (handle file or load from module) if event.module: return name = event.name module = None _, top_level_dir = self._getStartDirs() try: # try name as a dotted module name first __import__(name) module = sys.modules[name] except ImportError: # if that fails, try it as a file or directory event.extraTests.extend( self._find_tests(event, name, top_level_dir)) else: event.extraTests.extend( self._find_tests_in_module(event, module, top_level_dir)) def loadTestsFromNames(self, event): """Discover tests if no test names specified""" log.debug("Received event %s", event) if event.names or event.module: return event.handled = True # I will handle discovery return self._discover(event) def _checkIfPathIsOK(self, start_dir): if not os.path.isdir(os.path.abspath(start_dir)): raise OSError("%s is not a directory" % os.path.abspath(start_dir)) def _getStartDirs(self): start_dir = self.session.startDir top_level_dir = self.session.topLevelDir if start_dir is None: start_dir = '.' if top_level_dir is None: top_level_dir = start_dir self._checkIfPathIsOK(start_dir) is_not_importable = False start_dir = os.path.abspath(start_dir) top_level_dir = os.path.abspath(top_level_dir) if start_dir != top_level_dir: is_not_importable = not os.path.isfile( os.path.join(start_dir, '__init__.py')) if is_not_importable: raise ImportError( 'Start directory is not importable: %r' % start_dir) # this is redundant in some cases, but that's ok self.session.prepareSysPath() return start_dir, top_level_dir def _discover(self, event): loader = event.loader try: start_dir, top_level_dir = self._getStartDirs() except (OSError, ImportError): _, ev, _ = sys.exc_info() return loader.suiteClass( loader.failedLoadTests(self.session.startDir, ev)) log.debug("_discover in %s (%s)", start_dir, top_level_dir) tests = list(self._find_tests(event, start_dir, top_level_dir)) return loader.suiteClass(tests) def _find_tests(self, event, start, top_level): """Used by discovery. Yields test suites it loads.""" log.debug('_find_tests(%r, %r)', start, top_level) if start == top_level: full_path = start else: full_path = os.path.join(top_level, start) if os.path.isdir(start): for test in self._find_tests_in_dir( event, full_path, top_level): yield test elif os.path.isfile(start): for test in self._find_tests_in_file( event, start, full_path, top_level): yield test def _find_tests_in_dir(self, event, full_path, top_level): if not os.path.isdir(full_path): return log.debug("find in dir %s (%s)", full_path, top_level) dir_handler = DirectoryHandler(self.session) for test in dir_handler.handle_dir(event, full_path, top_level): yield test if dir_handler.event_handled: return for path in os.listdir(full_path): entry_path = os.path.join(full_path, path) if os.path.isfile(entry_path): for test in self._find_tests_in_file( event, path, entry_path, top_level): yield test elif os.path.isdir(entry_path): if ('test' in path.lower() or util.ispackage(entry_path) or path in self.session.libDirs): for test in self._find_tests(event, entry_path, top_level): yield test def _find_tests_in_file(self, event, filename, full_path, top_level, module_name=None): log.debug("find in file %s (%s)", full_path, top_level) pattern = self.session.testFilePattern loader = event.loader evt = events.HandleFileEvent( loader, filename, full_path, pattern, top_level) result = self.session.hooks.handleFile(evt) if evt.extraTests: yield loader.suiteClass(evt.extraTests) if evt.handled: if result: yield result return if not util.valid_module_name(filename): # valid Python identifiers only return evt = events.MatchPathEvent(filename, full_path, pattern) result = self.session.hooks.matchPath(evt) if evt.handled: if not result: return elif not self._match_path(filename, full_path, pattern): return if module_name is None: module_name, package_path = util.name_from_path(full_path) util.ensure_importable(package_path) try: module = util.module_from_name(module_name) except: yield loader.failedImport(module_name) else: mod_file = os.path.abspath( getattr(module, '__file__', full_path)) realpath = os.path.splitext(mod_file)[0] fullpath_noext = os.path.splitext(full_path)[0] if realpath.lower() != fullpath_noext.lower(): module_dir = os.path.dirname(realpath) mod_name = os.path.splitext(os.path.basename(full_path))[0] expected_dir = os.path.dirname(full_path) msg = ("%r module incorrectly imported from %r. " "Expected %r. Is this module globally installed?" ) raise ImportError( msg % (mod_name, module_dir, expected_dir)) yield loader.loadTestsFromModule(module) def _find_tests_in_module(self, event, module, top_level_dir): # only called from loadTestsFromName yield event.loader.loadTestsFromModule(module) # may be a package; recurse into __path__ if so pkgpath = getattr(module, '__path__', None) if pkgpath: for entry in pkgpath: full_path = os.path.abspath(os.path.join(top_level_dir, entry)) for test in self._find_tests_in_dir( event, full_path, top_level_dir): yield test def _match_path(self, path, full_path, pattern): # override this method to use alternative matching strategy return fnmatch(path, pattern) class DiscoveryLoader(events.Plugin, Discoverer): """Loader plugin that can discover tests""" alwaysOn = True configSection = 'discovery' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def loadTestsFromName(self, event): """Load tests from module named by event.name""" return Discoverer.loadTestsFromName(self, event) def loadTestsFromNames(self, event): """Discover tests if no test names specified""" return Discoverer.loadTestsFromNames(self, event) nose2-0.6.4/nose2/plugins/loader/eggdiscovery.py0000664000175000017500000000574512672050004021203 0ustar travistravis""" Egg-based discovery test loader. This plugin implements nose2's automatic test module discovery inside Egg Files. It looks for test modules in packages whose names start with ``test``, then fires the :func:`loadTestsFromModule` hook for each one to allow other plugins to load the actual tests. It also fires :func:`handleFile` for every file that it sees, and :func:`matchPath` for every Python module, to allow other plugins to load tests from other kinds of files and to influence which modules are examined for tests. """ import logging import os from nose2 import events from nose2.plugins.loader import discovery __unittest = True log = logging.getLogger(__name__) try: import pkg_resources except ImportError: pkg_resources = None class EggDiscoveryLoader(events.Plugin, discovery.Discoverer): """Loader plugin that can discover tests inside Egg Files""" alwaysOn = True configSection = 'discovery' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def loadTestsFromName(self, event): """Load tests from module named by event.name""" return discovery.Discoverer.loadTestsFromName(self, event) def loadTestsFromNames(self, event): """Discover tests if no test names specified""" return discovery.Discoverer.loadTestsFromNames(self, event) def _checkIfPathIsOK(self, start_dir): if not os.path.exists(os.path.abspath(start_dir)): raise OSError("%s does not exist" % os.path.abspath(start_dir)) def _find_tests_in_egg_dir(self, event, rel_path, dist): log.debug("find in egg dir %s %s (%s)", dist.location, rel_path, dist.project_name) full_path = os.path.join(dist.location, rel_path) dir_handler = discovery.DirectoryHandler(self.session) for test in dir_handler.handle_dir(event, full_path, dist.location): yield test if dir_handler.event_handled: return for path in dist.resource_listdir(rel_path): entry_path = os.path.join(rel_path, path) if dist.resource_isdir(entry_path): for test in self._find_tests_in_egg_dir(event, entry_path, dist): yield test else: modname = os.path.splitext(entry_path)[0].replace(os.sep, '.') for test in self._find_tests_in_file( event, path, os.path.join(dist.location, entry_path), dist.location, modname): yield test def _find_tests_in_dir(self, event, full_path, top_level): if os.path.exists(full_path): return elif pkg_resources and full_path.find('.egg') != -1: egg_path = full_path.split('.egg')[0] + '.egg' for dist in pkg_resources.find_distributions(egg_path): for modname in dist._get_metadata('top_level.txt'): for test in self._find_tests_in_egg_dir( event, modname, dist): yield test nose2-0.6.4/nose2/plugins/loader/functions.py0000664000175000017500000001041712672050004020511 0ustar travistravis""" Load tests from test functions in modules. This plugin responds to :func:`loadTestsFromModule` by adding test cases for all test functions in the module to ``event.extraTests``. It uses ``session.testMethodPrefix`` to find test functions. Functions that are generators, have param lists, or take arguments are not collected. This plugin also implements :func:`loadTestsFromName` to enable loading tests from dotted function names passed on the command line. Fixtures -------- Test functions can specify setup and teardown fixtures as attributes on the function, for example: .. code :: python x = 0 def test(): assert x def setup(): global x x = 1 def teardown(): global x x = 1 test.setup = setup test.teardown = teardown The setup attribute may be named ``setup``, ``setUp`` or ``setUpFunc``. The teardown attribute may be named ``teardown``, 'tearDown`` or ``tearDownFunc``. Other attributes ---------------- The other significant attribute that may be set on a test function is ``paramList``. When ``paramList`` is set, the function will be collected by the :doc:`parameterized test loader `. The easiest way to set ``paramList`` is with the :func:`nose2.tools.params` decorator. """ # This module contains some code copied from unittest2/ and other code # developed in reference to unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import inspect import types from nose2 import util from nose2.events import Plugin from nose2.compat import unittest __unittest = True class Functions(Plugin): """Loader plugin that loads test functions""" alwaysOn = True configSection = 'functions' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def loadTestsFromName(self, event): """Load test if event.name is the name of a test function""" name = event.name module = event.module try: result = util.test_from_name(name, module) except (AttributeError, ImportError) as e: event.handled = True return event.loader.failedLoadTests(name, e) if result is None: return parent, obj, name, index = result if (isinstance(obj, types.FunctionType) and not util.isgenerator(obj) and not hasattr(obj, 'paramList') and not inspect.getargspec(obj).args): suite = event.loader.suiteClass() suite.addTests(self._createTests(obj)) event.handled = True return suite def loadTestsFromModule(self, event): """Load test functions from event.module""" module = event.module def is_test(obj): if not obj.__name__.startswith(self.session.testMethodPrefix): return False if inspect.getargspec(obj).args: return False return True tests = [] for name in dir(module): obj = getattr(module, name) if isinstance(obj, types.FunctionType) and is_test(obj): tests.extend(self._createTests(obj)) event.extraTests.extend(tests) def _createTests(self, obj): if not hasattr(obj, 'setUp'): if hasattr(obj, 'setup'): obj.setUp = obj.setup elif hasattr(obj, 'setUpFunc'): obj.setUp = obj.setUpFunc if not hasattr(obj, 'tearDown'): if hasattr(obj, 'teardown'): obj.tearDown = obj.teardown elif hasattr(obj, 'tearDownFunc'): obj.tearDown = obj.tearDownFunc tests = [] args = {} setUp = getattr(obj, 'setUp', None) tearDown = getattr(obj, 'tearDown', None) if setUp is not None: args['setUp'] = setUp if tearDown is not None: args['tearDown'] = tearDown paramList = getattr(obj, 'paramList', None) isGenerator = util.isgenerator(obj) if paramList is not None or isGenerator: return tests else: case = util.transplant_class( unittest.FunctionTestCase, obj.__module__)(obj, **args) tests.append(case) return tests nose2-0.6.4/nose2/plugins/loader/generators.py0000664000175000017500000002163112672050004020652 0ustar travistravis""" Load tests from generators. This plugin implements :func:`loadTestFromTestCase`, :func:`loadTestsFromName` and :func:`loadTestFromModule` to enable loading tests from generators. Generators may be functions or methods in test cases. In either case, they must yield a callable and arguments for that callable once for each test they generate. The callable and arguments may all be in one tuple, or the arguments may be grouped into a separate tuple:: def test_gen(): yield check, 1, 2 yield check, (1, 2) To address a particular generated test via a command-line test name, append a colon (':') followed by the index (*starting from 1*) of the generated case you want to execute. """ # This module contains some code copied from unittest2 and other code # developed in reference to unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import functools import logging import sys import types import unittest from nose2 import exceptions, util from nose2.events import Plugin from nose2.compat import unittest as ut2 log = logging.getLogger(__name__) __unittest = True class Generators(Plugin): """Loader plugin that loads generator tests""" alwaysOn = True configSection = 'generators' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def unpack(self, generator): for index, func_args in enumerate(generator): try: func, args = func_args if not isinstance(args, tuple): args = (args,) yield index, (func, args) except ValueError: func, args = func_args[0], func_args[1:] yield index, (func, args) def loadTestsFromTestCase(self, event): """Load generator tests from test case""" log.debug('loadTestsFromTestCase %s', event.testCase) testCaseClass = event.testCase for name in dir(testCaseClass): method = getattr(testCaseClass, name) if (name.startswith(self.session.testMethodPrefix) and hasattr(getattr(testCaseClass, name), '__call__') and util.isgenerator(method)): instance = testCaseClass(name) event.extraTests.extend( self._testsFromGenerator( event, name, method(instance), testCaseClass) ) def loadTestsFromTestClass(self, event): testCaseClass = event.testCase for name in dir(testCaseClass): method = getattr(testCaseClass, name) if (name.startswith(self.session.testMethodPrefix) and hasattr(getattr(testCaseClass, name), '__call__') and util.isgenerator(method)): instance = testCaseClass() event.extraTests.extend( self._testsFromGeneratorMethod( event, name, method, instance) ) def getTestCaseNames(self, event): """Get generator test case names from test case class""" log.debug('getTestCaseNames %s', event.testCase) names = filter(event.isTestMethod, dir(event.testCase)) klass = event.testCase for name in names: method = getattr(klass, name) if util.isgenerator(method): event.excludedNames.append(name) def getTestMethodNames(self, event): return self.getTestCaseNames(event) def loadTestsFromName(self, event): """Load tests from generator named on command line""" original_name = name = event.name module = event.module try: result = util.test_from_name(name, module) except (AttributeError, ImportError) as e: event.handled = True return event.loader.failedLoadTests(name, e) if result is None: # we can't find it - let the default case handle it return parent, obj, name, index = result if not util.isgenerator(obj): return if (index is None and not isinstance(parent, type) and not isinstance(obj, types.FunctionType)): log.debug("Don't know how to load generator tests from %s", obj) return if (parent and isinstance(parent, type) and issubclass(parent, unittest.TestCase)): # generator method in test case instance = parent(obj.__name__) tests = list( self._testsFromGenerator( event, obj.__name__, obj(instance), parent) ) elif (parent and isinstance(parent, type)): # generator method in test class method = obj instance = parent() tests = list( self._testsFromGeneratorMethod(event, name, method, instance) ) else: # generator func tests = list(self._testsFromGeneratorFunc(event, obj)) if index is not None: try: tests = [tests[index - 1]] except IndexError: raise exceptions.TestNotFoundError(original_name) suite = event.loader.suiteClass() suite.addTests(tests) event.handled = True return suite def loadTestsFromModule(self, event): """Load tests from generator functions in a module""" module = event.module def is_test(obj): return (obj.__name__.startswith(self.session.testMethodPrefix) and util.isgenerator(obj)) tests = [] for name in dir(module): obj = getattr(module, name) if isinstance(obj, types.FunctionType) and is_test(obj): tests.extend(self._testsFromGeneratorFunc(event, obj)) event.extraTests.extend(tests) def _testsFromGenerator(self, event, name, generator, testCaseClass): try: for index, (func, args) in self.unpack(generator): method_name = util.name_from_args(name, index, args) setattr(testCaseClass, method_name, None) instance = testCaseClass(method_name) delattr(testCaseClass, method_name) def method(func=func, args=args): return func(*args) method = functools.update_wrapper(method, func) setattr(instance, method_name, method) yield instance except Exception as e: test_name = '%s.%s.%s' % (testCaseClass.__module__, testCaseClass.__name__, name) yield event.loader.failedLoadTests(test_name, e) def _testsFromGeneratorFunc(self, event, obj): extras = list(obj()) name = '%s.%s' % (obj.__module__, obj.__name__) args = {} setUp = getattr(obj, 'setUp', None) tearDown = getattr(obj, 'tearDown', None) if setUp is not None: args['setUp'] = setUp if tearDown is not None: args['tearDown'] = tearDown def createTest(name): return util.transplant_class( GeneratorFunctionCase, obj.__module__)(name, **args) for test in self._testsFromGenerator(event, name, extras, createTest): yield test def _testsFromGeneratorMethod(self, event, name, method, instance): extras = list(method(instance)) name = "%s.%s.%s" % (instance.__class__.__module__, instance.__class__.__name__, method.__name__) args = {} setUp = getattr(instance, 'setUp', None) tearDown = getattr(instance, 'tearDown', None) if setUp is not None: args['setUp'] = setUp if tearDown is not None: args['tearDown'] = tearDown def createTest(name): return util.transplant_class( GeneratorMethodCase(instance.__class__), instance.__class__.__module__)(name, **args) for test in self._testsFromGenerator(event, name, extras, createTest): yield test class GeneratorFunctionCase(ut2.FunctionTestCase): def __init__(self, name, **args): self._funcName = name ut2.FunctionTestCase.__init__(self, None, **args) _testFunc = property(lambda self: getattr(self, self._funcName), lambda self, func: None) def __repr__(self): return self._funcName id = __str__ = __repr__ def GeneratorMethodCase(cls): class _GeneratorMethodCase(GeneratorFunctionCase): @classmethod def setUpClass(klass): if hasattr(cls, 'setUpClass'): cls.setUpClass() @classmethod def tearDownClass(klass): if hasattr(cls, 'tearDownClass'): cls.tearDownClass() return _GeneratorMethodCase nose2-0.6.4/nose2/plugins/loader/loadtests.py0000664000175000017500000000554012672050004020504 0ustar travistravis""" Loader that implements the ``load_tests`` protocol. This plugin implements the ``load_tests`` protocol as detailed in the documentation for :mod:`unittest2`. See the `load_tests protocol`_ documentation for more information. .. warning :: Test suites using the ``load_tests`` protocol do not work correctly with the :mod:`multiprocess` plugin as of nose2 04. This will be fixed in a future release. .. _load_tests protocol: http://docs.python.org/library/unittest.html#load-tests-protocol """ from fnmatch import fnmatch import logging from nose2 import events, util log = logging.getLogger(__name__) class LoadTestsLoader(events.Plugin): """Loader plugin that implements load_tests.""" alwaysOn = True configSection = 'load_tests' _loading = False def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def moduleLoadedSuite(self, event): """Run ``load_tests`` in a module. May add to or filter tests loaded in module. """ module = event.module load_tests = getattr(module, 'load_tests', None) if not load_tests: return try: event.suite = load_tests( event.loader, event.suite, self.session.testFilePattern) except Exception as exc: log.exception( "Failed to load tests from %s via load_tests", module) suite = event.loader.suiteClass() suite.addTest(event.loader.failedLoadTests(module.__name__, exc)) event.handled = True return suite def handleDir(self, event): """Run ``load_tests`` in packages. If a package itself matches the test file pattern, run ``load_tests`` in its :file:`__init__.py`, and stop default test discovery for that package. """ if self._loading: return if (self._match(event.name, event.pattern) and util.ispackage(event.path)): name, _package_path = util.name_from_path(event.path) module = util.module_from_name(name) load_tests = getattr(module, 'load_tests', None) if not load_tests: return self._loading = True try: suite = event.loader.suiteClass() try: suite = load_tests(event.loader, suite, event.pattern) except Exception as exc: log.exception( "Failed to load tests from %s via load_tests", module) suite.addTest( event.loader.failedLoadTests(module.__name__, exc)) event.handled = True return suite finally: self._loading = False def _match(self, filename, pattern): return fnmatch(filename, pattern) nose2-0.6.4/nose2/plugins/loader/parameters.py0000664000175000017500000001542512672050004020650 0ustar travistravis""" Load tests from parameterized functions and methods. This plugin implements :func:`getTestCaseNames`, :func:`loadTestsFromModule`, and :func:`loadTestsFromName` to support loading tests from parameterized test functions and methods. To parameterize a function or test case method, use :func:`nose2.tools.params`. To address a particular parameterized test via a command-line test name, append a colon (':') followed by the index (*starting from 1*) of the case you want to execute. Such And The Parameters Plugin ------------------------------ The parameters plugin can work with the Such DSL, as long as the first argument of the test function is the "case" argument, followed by the other parameters:: from nose2.tools import such from nose2.tools.params import params with such.A('foo') as it: @it.should('do bar') @params(1,2,3) def test(case, bar): case.assert_(isinstance(bar, int)) @it.should('do bar and extra') @params((1, 2), (3, 4) ,(5, 6)) def testExtraArg(case, bar, foo): case.assert_(isinstance(bar, int)) case.assert_(isinstance(foo, int)) it.createTests(globals()) """ # This module contains some code copied from unittest2 and other code # developed in reference to unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import functools import logging import types import unittest from nose2 import exceptions, util from nose2.events import Plugin from nose2.compat import unittest as ut2 from nose2.plugins.loader.testclasses import MethodTestCase log = logging.getLogger(__name__) __unittest = True class ParamsFunctionCase(ut2.FunctionTestCase): def __init__(self, name, func, **args): self._funcName = name ut2.FunctionTestCase.__init__(self, func, **args) def __repr__(self): return self._funcName id = __str__ = __repr__ class Parameters(Plugin): """Loader plugin that loads parameterized tests""" alwaysOn = True configSection = 'parameters' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def getTestCaseNames(self, event): """Generate test case names for all parameterized methods""" log.debug('getTestCaseNames %s', event) names = filter(event.isTestMethod, dir(event.testCase)) testCaseClass = event.testCase for name in names: method = getattr(testCaseClass, name) paramList = getattr(method, 'paramList', None) if paramList is None: continue # exclude this method from normal collection event.excludedNames.append(name) # generate the methods to be loaded by the testcase loader self._generate(event, name, method, testCaseClass) def getTestMethodNames(self, event): return self.getTestCaseNames(event) def loadTestsFromModule(self, event): """Load tests from parameterized test functions in the module""" module = event.module def is_test(obj): return (obj.__name__.startswith(self.session.testMethodPrefix) and hasattr(obj, 'paramList')) tests = [] for name in dir(module): obj = getattr(module, name) if isinstance(obj, types.FunctionType) and is_test(obj): tests.extend( self._generateFuncTests(obj) ) event.extraTests.extend(tests) def loadTestsFromName(self, event): """Load parameterized test named on command line""" original_name = name = event.name module = event.module try: result = util.test_from_name(name, module) except (AttributeError, ImportError) as e: event.handled = True return event.loader.failedLoadTests(name, e) if result is None: # we can't find it - let the default case handle it return parent, obj, fqname, index = result if not hasattr(obj, 'paramList'): return if (index is None and not isinstance(parent, type) and not isinstance(obj, types.FunctionType)): log.debug( "Don't know how to load parameterized tests from %s", obj) return if (parent and isinstance(parent, type) and issubclass(parent, unittest.TestCase)): # generator method names = self._generate(event, obj.__name__, obj, parent) tests = [parent(n) for n in names] elif (parent and isinstance(parent, type)): names = self._generate(event, name, obj, parent) tests = [MethodTestCase(parent)(name) for name in names] else: # generator func tests = list(self._generateFuncTests(obj)) if index is not None: try: tests = [tests[index - 1]] except IndexError: raise exceptions.TestNotFoundError(original_name) suite = event.loader.suiteClass() suite.addTests(tests) event.handled = True return suite def _generate(self, event, name, method, testCaseClass): names = [] for index, argSet in enumerate_params(method.paramList): method_name = util.name_from_args(name, index, argSet) if not hasattr(testCaseClass, method_name): # not already generated def _method(self, method=method, argSet=argSet): return method(self, *argSet) _method = functools.update_wrapper(_method, method) delattr(_method, 'paramList') setattr(testCaseClass, method_name, _method) names.append(method_name) return names def _generateFuncTests(self, obj): args = {} setUp = getattr(obj, 'setUp', None) tearDown = getattr(obj, 'tearDown', None) if setUp is not None: args['setUp'] = setUp if tearDown is not None: args['tearDown'] = tearDown for index, argSet in enumerate_params(obj.paramList): def func(argSet=argSet, obj=obj): return obj(*argSet) func = functools.update_wrapper(func, obj) delattr(func, 'paramList') name = '%s.%s' % (obj.__module__, obj.__name__) func_name = util.name_from_args(name, index, argSet) yield util.transplant_class( ParamsFunctionCase, obj.__module__)(func_name, func, **args) def enumerate_params(paramList): for index, argSet in enumerate(paramList): if not isinstance(argSet, tuple): argSet = (argSet,) yield index, argSet nose2-0.6.4/nose2/plugins/loader/testcases.py0000664000175000017500000001035612672050004020501 0ustar travistravis""" Load tests from :class:`unittest.TestCase` subclasses. This plugin implements :func:`loadTestsFromName` and :func:`loadTestsFromModule` to load tests from :class:`unittest.TestCase` subclasses found in modules or named on the command line. """ # Adapted from unittest2/loader.py from the unittest2 plugins branch. # This module contains some code copied from unittest2/loader.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import logging import unittest from nose2 import events, util __unittest = True log = logging.getLogger(__name__) class TestCaseLoader(events.Plugin): """Loader plugin that loads from test cases""" alwaysOn = True configSection = 'testcases' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def loadTestsFromModule(self, event): """Load tests in :class:`unittest.TestCase` subclasses""" seen = set() module = event.module for name in dir(module): obj = getattr(module, name) if id(obj) in seen: continue seen.add(id(obj)) if isinstance(obj, type) and issubclass(obj, unittest.TestCase): event.extraTests.append( self._loadTestsFromTestCase(event, obj)) def loadTestsFromName(self, event): """Load tests from event.name if it names a test case/method""" name = event.name module = event.module log.debug("load %s from %s", name, module) try: result = util.test_from_name(name, module) except (AttributeError, ImportError) as e: event.handled = True return event.loader.failedLoadTests(name, e) if result is None: return parent, obj, name, index = result if isinstance(obj, type) and issubclass(obj, unittest.TestCase): # name is a test case class event.extraTests.append(self._loadTestsFromTestCase(event, obj)) elif (isinstance(parent, type) and issubclass(parent, unittest.TestCase) and not util.isgenerator(obj) and not hasattr(obj, 'paramList')): # name is a single test method event.extraTests.append(parent(obj.__name__)) def _loadTestsFromTestCase(self, event, testCaseClass): evt = events.LoadFromTestCaseEvent(event.loader, testCaseClass) result = self.session.hooks.loadTestsFromTestCase(evt) if evt.handled: loaded_suite = result or event.loader.suiteClass() else: names = self._getTestCaseNames(event, testCaseClass) if not names and hasattr(testCaseClass, 'runTest'): names = ['runTest'] # FIXME return failure test case if name not in testcase class loaded_suite = event.loader.suiteClass(map(testCaseClass, names)) if evt.extraTests: loaded_suite.addTests(evt.extraTests) return loaded_suite def _getTestCaseNames(self, event, testCaseClass): excluded = set() def isTestMethod(attrname, testCaseClass=testCaseClass, excluded=excluded): prefix = evt.testMethodPrefix or self.session.testMethodPrefix return ( attrname.startswith(prefix) and hasattr(getattr(testCaseClass, attrname), '__call__') and attrname not in excluded ) evt = events.GetTestCaseNamesEvent( event.loader, testCaseClass, isTestMethod) result = self.session.hooks.getTestCaseNames(evt) if evt.handled: test_names = result or [] else: excluded.update(evt.excludedNames) test_names = [entry for entry in dir(testCaseClass) if isTestMethod(entry)] if evt.extraNames: test_names.extend(evt.extraNames) sortkey = getattr( testCaseClass, 'sortTestMethodsUsing', event.loader.sortTestMethodsUsing) if sortkey: test_names.sort( key=sortkey) return test_names nose2-0.6.4/nose2/plugins/loader/testclasses.py0000664000175000017500000002034312672050004021035 0ustar travistravis""" Load tests from classes that are *not* :class:`unittest.TestCase` subclasses. This plugin responds to :func:`loadTestsFromModule` by adding test cases for test methods found in classes in the module that are *not* sublcasses of :class:`unittest.TestCase`, but whose names (lowercased) match the configured test method prefix. Test class methods that are generators or have param lists are not loaded here, but by the :class:`nose2.plugins.loader.generators.Generators` and :class:`nose2.plugins.loader.parameters.Parameters` plugins. This plugin also implements :func:`loadTestsFromName` to enable loading tests from dotted class and method names passed on the command line. This plugin makes two additional plugin hooks available for other test loaders to use: .. function :: loadTestsFromTestClass(self, event) :param event: A :class:`LoadFromTestClassEvent` instance Plugins can use this hook to load tests from a class that is not a :class:`unittest.TestCase` subclass. To prevent other plugins from loading tests from the test class, set ``event.handled`` to ``True`` and return a test suite. Plugins can also append tests to ``event.extraTests``. Ususally, that's what you want, since it allows other plugins to load their tests from the test case as well. .. function :: getTestMethodNames(self, event) :param event: A :class:`GetTestMethodNamesEvent` instance Plugins can use this hook to limit or extend the list of test case names that will be loaded from a class that is not a :class:`unittest.TestCase` subclass by the standard nose2 test loader plugins (and other plugins that respect the results of the hook). To force a specific list of names, set ``event.handled`` to ``True`` and return a list: this exact list will be the only test case names loaded from the test case. Plugins can also extend the list of names by appending test names to ``event.extraNames``, and exclude names by appending test names to ``event.excludedNames``. About Test Classes ------------------ Test classes are classes that look test-like but are not subclasses of :class:`unittest.TestCase`. Test classes support all of the same test types and fixtures as test cases. To "look test-like" a class must have a name that, lowercased, matches the configured test method prefix -- "test" by default. Test classes must also be able to be instantiated without arguments. What are they useful for? Mostly the case where a test class can't for some reason subclass :class:`unittest.TestCase`. Otherwise, test class tests and test cases are functionally equivalent in nose2, and test cases have broader support and all of those helpful *assert\** methods -- so when in doubt, you should use a :class:`unittest.TestCase`. Here's an example of a test class:: class TestSomething(object): def test(self): assert self.something(), "Something failed!" """ import unittest import sys from nose2 import events, util from nose2.compat import unittest as ut2 __unittest = True class TestClassLoader(events.Plugin): """Loader plugin that loads test functions""" alwaysOn = True configSection = 'test-classes' def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def register(self): """Install extra hooks Adds the new plugin hooks: - loadTestsFromTestClass - getTestMethodNames """ super(TestClassLoader, self).register() self.addMethods('loadTestsFromTestClass', 'getTestMethodNames') def loadTestsFromModule(self, event): """Load test classes from event.module""" module = event.module for name in dir(module): obj = getattr(module, name) if (isinstance(obj, type) and not issubclass(obj, unittest.TestCase) and not issubclass(obj, unittest.TestSuite) and name.lower().startswith(self.session.testMethodPrefix)): event.extraTests.append( self._loadTestsFromTestClass(event, obj)) def loadTestsFromName(self, event): """Load tests from event.name if it names a test class/method""" name = event.name module = event.module try: result = util.test_from_name(name, module) except (AttributeError, ImportError) as e: event.handled = True return event.loader.failedLoadTests(name, e) if result is None: return parent, obj, name, index = result if isinstance(obj, type) and not issubclass(obj, unittest.TestCase): # name is a test case class event.extraTests.append(self._loadTestsFromTestClass(event, obj)) elif (isinstance(parent, type) and not issubclass(parent, unittest.TestCase) and not util.isgenerator(obj) and not hasattr(obj, 'paramList')): # name is a single test method event.extraTests.append( util.transplant_class( MethodTestCase(parent), parent.__module__)(obj.__name__)) def _loadTestsFromTestClass(self, event, cls): # ... fire event for others to load from evt = LoadFromTestClassEvent(event.loader, cls) result = self.session.hooks.loadTestsFromTestClass(evt) if evt.handled: loaded_suite = result or event.loader.suiteClass() else: names = self._getTestMethodNames(event, cls) try: loaded_suite = event.loader.suiteClass( [util.transplant_class( MethodTestCase(cls), cls.__module__)(name) for name in names]) except: _, ev, _ = sys.exc_info() return event.loader.suiteClass( event.loader.failedLoadTests(cls.__name__, ev)) if evt.extraTests: loaded_suite.addTests(evt.extraTests) # ... add extra tests return loaded_suite def _getTestMethodNames(self, event, cls): # ... give others a chance to modify list excluded = set() def isTestMethod(attrname, cls=cls, excluded=excluded): # FIXME allow plugs to change prefix prefix = self.session.testMethodPrefix return ( attrname.startswith(prefix) and hasattr(getattr(cls, attrname), '__call__') and attrname not in excluded ) evt = GetTestMethodNamesEvent(event.loader, cls, isTestMethod) result = self.session.hooks.getTestMethodNames(evt) if evt.handled: test_names = result or [] else: excluded.update(evt.excludedNames) test_names = [entry for entry in dir(cls) if isTestMethod(entry)] if event.loader.sortTestMethodsUsing: test_names.sort(key=event.loader.sortTestMethodsUsing) return test_names # to prevent unit2 discover from running this as a test, need to # hide it inside of a factory func. ugly! def MethodTestCase(cls): class _MethodTestCase(ut2.TestCase): def __init__(self, method): self.method = method self._name = "%s.%s.%s" % (cls.__module__, cls.__name__, method) self.obj = cls() ut2.TestCase.__init__(self, 'runTest') @classmethod def setUpClass(klass): if hasattr(cls, 'setUpClass'): cls.setUpClass() @classmethod def tearDownClass(klass): if hasattr(cls, 'tearDownClass'): cls.tearDownClass() def setUp(self): if hasattr(self.obj, 'setUp'): self.obj.setUp() def tearDown(self): if hasattr(self.obj, 'tearDown'): self.obj.tearDown() def __repr__(self): return self._name id = __str__ = __repr__ def runTest(self): getattr(self.obj, self.method)() return _MethodTestCase # # Event classes # class LoadFromTestClassEvent(events.LoadFromTestCaseEvent): """Bare subclass of :class:`nose2.events.LoadFromTestCaseEvent`""" class GetTestMethodNamesEvent(events.GetTestCaseNamesEvent): """Bare subclass of :class:`nose2.events.GetTestCaseNamesEvent`""" nose2-0.6.4/nose2/plugins/__init__.py0000664000175000017500000000000012672050004016755 0ustar travistravisnose2-0.6.4/nose2/plugins/attrib.py0000664000175000017500000001243412672050004016521 0ustar travistravisimport logging from unittest import TestSuite from nose2.events import Plugin log = logging.getLogger(__name__) undefined = object() class AttributeSelector(Plugin): """Filter tests by attribute""" def __init__(self): self.attribs = [] self.eval_attribs = [] self.addArgument( self.attribs, "A", "attribute", "Select tests with matching attribute") self.addArgument( self.eval_attribs, "E", "eval-attribute", "Select tests for whose attributes the " "given Python expression evaluates to ``True``") def handleArgs(self, args): """Register if any attribs defined""" if self.attribs or self.eval_attribs: self.register() def moduleLoadedSuite(self, event): """Filter event.suite by specified attributes""" log.debug('Attribute selector attribs %s/%s', self.attribs, self.eval_attribs) attribs = [] for attr in self.eval_attribs: def eval_in_context(expr, obj): try: return eval(expr, None, ContextHelper(obj)) except Exception as e: log.warning( "%s raised exception %s with test %s", expr, e, obj) return False attribs.append([(attr, eval_in_context)]) for attr in self.attribs: # all attributes within an attribute group must match attr_group = [] for attrib in attr.strip().split(","): # don't die on trailing comma if not attrib: continue items = attrib.split("=", 1) if len(items) > 1: # "name=value" # -> 'str(obj.name) == value' must be True key, value = items else: key = items[0] if key[0] == "!": # "!name" # 'bool(obj.name)' must be False key = key[1:] value = False else: # "name" # -> 'bool(obj.name)' must be True value = True attr_group.append((key, value)) attribs.append(attr_group) if not attribs: return event.suite = self.filterSuite(event.suite, attribs) def filterSuite(self, suite, attribs): # FIXME probably need to copy or something to allow suites w/custom attrs to work or iter and remove instead of # recreating new_suite = suite.__class__() for test in suite: if isinstance(test, TestSuite): new_suite.addTest(self.filterSuite(test, attribs)) elif self.validateAttrib(test, attribs): new_suite.addTest(test) return new_suite def validateAttrib(self, test, attribs): any_ = False for group in attribs: match = True for key, value in group: neg = False if key.startswith('!'): neg, key = True, key[1:] obj_value = _get_attr(test, key) if callable(value): if not value(key, test): match = False break elif value is True: # value must exist and be True if not bool(obj_value): match = False break elif value is False: # value must not exist or be False if bool(obj_value): match = False break elif type(obj_value) in (list, tuple): # value must be found in the list attribute found = str(value).lower() in [str(x).lower() for x in obj_value] if found and neg: match = False break elif not found and not neg: match = False break else: # value must match, convert to string and compare if (value != obj_value and str(value).lower() != str(obj_value).lower()): match = False break any_ = any_ or match return any_ # helpers def _get_attr(test, key): # FIXME for vals that are lists (or just mutable?), combine all levels val = getattr(test, key, undefined) if val is not undefined: return val if hasattr(test, '_testFunc'): val = getattr(test._testFunc, key, undefined) if val is not undefined: return val elif hasattr(test, '_testMethodName'): meth = getattr(test, test._testMethodName, undefined) if meth is not undefined: val = getattr(meth, key, undefined) if val is not undefined: return val class ContextHelper: def __init__(self, obj): self.obj = obj def __getitem__(self, name): return _get_attr(self.obj, name) nose2-0.6.4/nose2/plugins/buffer.py0000664000175000017500000001021112672050004016474 0ustar travistravis""" Buffer stdout and/or stderr during test execution, appending any output to the error reports of failed tests. This allows you to use print for debugging in tests without making your test runs noisy. This plugin implements :func:`startTest`, :func:`stopTest`, :func:`setTestOutcome`, :func:`outcomeDetail`, :func:`beforeInteraction` and :func:`afterInteraction` to manage capturing sys.stdout and/or sys.stderr into buffers, attaching the buffered output to test error report detail, and getting out of the way when other plugins want to talk to the user. """ import sys from six import StringIO from nose2 import events from nose2.util import ln __unittest = True class _Buffer(object): def __init__(self, stream): self._stream = stream self._buffer = StringIO() def fileno(self): return self._stream.fileno() def __getattr__(self, attr): # this happens on unpickling if attr == '_buffer': raise AttributeError("No _buffer yet") return getattr(self._buffer, attr) def __le__(self, obj): return self._buffer.getvalue() == obj def __eq__(self, obj): return self._buffer.getvalue() == obj def __str__(self): return self._buffer.getvalue() def __repr__(self): return repr(self._buffer.getvalue()) class OutputBufferPlugin(events.Plugin): """Buffer output during test execution""" commandLineSwitch = ('B', 'output-buffer', 'Enable output buffer') configSection = 'output-buffer' def __init__(self): self.captureStdout = self.config.as_bool('stdout', default=True) self.captureStderr = self.config.as_bool('stderr', default=False) self.bufStdout = self.bufStderr = None self.realStdout = sys.__stdout__ self.realStderr = sys.__stderr__ self._disable = False def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) # turn off in this process: the subproc will run the tests self._disable = True def startSubprocess(self, event): self.realStdout = sys.__stdout__ self.realStderr = sys.__stderr__ def startTest(self, event): """Start buffering selected stream(s)""" self._buffer() def stopTest(self, event): """Stop buffering""" self._restore() def setTestOutcome(self, event): """Attach buffer(s) to event.metadata""" if self._disable: return if self.captureStdout and 'stdout' not in event.metadata: event.metadata['stdout'] = self.bufStdout if self.captureStderr and 'stderr' not in event.metadata: event.metadata['stderr'] = self.bufStderr def outcomeDetail(self, event): """Add buffered output to event.extraDetail""" for stream in ('stdout', 'stderr'): if stream in event.outcomeEvent.metadata: buf = event.outcomeEvent.metadata[stream].getvalue() if not buf: continue event.extraDetail.append( ln('>> begin captured %s <<' % stream)) event.extraDetail.append(buf) event.extraDetail.append(ln('>> end captured %s <<' % stream)) def beforeInteraction(self, event): """Stop buffering so users can see stdout""" self._restore() def afterInteraction(self, event): """Start buffering again (does not clear buffers)""" self._buffer(fresh=False) def stopSubprocess(self, event): self._restore() def _restore(self): if self._disable: return if self.captureStdout: sys.stdout = self.realStdout if self.captureStderr: sys.stderr = self.realStderr def _buffer(self, fresh=True): if self._disable: return if self.captureStdout: if fresh or self.bufStdout is None: self.bufStdout = _Buffer(sys.stdout) sys.stdout = self.bufStdout if self.captureStderr: if fresh or self.bufStderr is None: self.bufStderr = _Buffer(sys.stderr) sys.stderr = self.bufStderr nose2-0.6.4/nose2/plugins/collect.py0000664000175000017500000000250012672050004016652 0ustar travistravis""" This plugin implements :func:`startTestRun`, setting a test executor (``event.executeTests``) that just collects tests without executing them. To do so it calls result.startTest, result.addSuccess and result.stopTest for ech test, without calling the test itself. """ from nose2.events import Plugin from nose2.compat import unittest __unittest = True class CollectOnly(Plugin): """Collect but don't run tests""" configSection = 'collect-only' commandLineSwitch = (None, 'collect-only', 'Collect and output test names; do not run any tests') _mpmode = False def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) self._mpmode = True def startTestRun(self, event): """Replace ``event.executeTests``""" if self._mpmode: return event.executeTests = self.collectTests def startSubprocess(self, event): event.executeTests = self.collectTests def collectTests(self, suite, result): """Collect tests, but don't run them""" for test in suite: if isinstance(test, unittest.BaseTestSuite): self.collectTests(test, result) continue result.startTest(test) result.addSuccess(test) result.stopTest(test) nose2-0.6.4/nose2/plugins/coverage.py0000664000175000017500000000640412672050004017027 0ustar travistravis""" Use this plugin to activate coverage report. To install this plugin, you need to activate ``coverage-plugin`` with extra requirements : :: $ pip install nose2[coverage-plugin] Next, you can enable coverage reporting with : :: $ nose2 --with-coverage Or with this lines in ``unittest.cfg`` : :: [coverage] always-on = True """ from nose2.events import Plugin class Coverage(Plugin): configSection = 'coverage' commandLineSwitch = ('C', 'with-coverage', 'Turn on coverage reporting') def __init__(self): """Get our config and add our command line arguments.""" self.conSource = self.config.as_list('coverage', []) self.conReport = self.config.as_list('coverage-report', []) self.conConfig = self.config.as_str('coverage-config', '').strip() group = self.session.pluginargs group.add_argument( '--coverage', action='append', default=[], metavar='PATH', dest='coverage_source', help='Measure coverage for filesystem path (multi-allowed)' ) group.add_argument( '--coverage-report', action='append', default=[], metavar='TYPE', choices=['term', 'term-missing', 'annotate', 'html', 'xml'], dest='coverage_report', help='Generate selected reports, available types:' ' term, term-missing, annotate, html, xml (multi-allowed)' ) group.add_argument( '--coverage-config', action='store', default='', metavar='FILE', dest='coverage_config', help='Config file for coverage, default: .coveragerc' ) self.covController = None def handleArgs(self, event): """Get our options in order command line, config file, hard coded.""" self.covSource = (event.args.coverage_source or self.conSource or ['.']) self.covReport = (event.args.coverage_report or self.conReport or ['term']) self.covConfig = (event.args.coverage_config or self.conConfig or '.coveragerc') def createTests(self, event): """Start coverage early to catch imported modules. Only called if active so, safe to just start without checking flags""" try: import cov_core except: print('Warning: you need to install [coverage-plugin] ' 'extra requirements to use this plugin') return self.covController = cov_core.Central(self.covSource, self.covReport, self.covConfig) self.covController.start() def createdTestSuite(self, event): """Pause coverage collection until we begin running tests.""" if self.covController: self.covController.cov.stop() def startTestRun(self, event): """Resume coverage collection before running tests.""" if self.covController: self.covController.cov.start() def afterSummaryReport(self, event): """Only called if active so stop coverage and produce reports.""" if self.covController: self.covController.finish() self.covController.summary(event.stream) nose2-0.6.4/nose2/plugins/debugger.py0000664000175000017500000000342412672050004017017 0ustar travistravis""" Start a :func:`pdb.post_mortem` on errors and failures. This plugin implements :func:`testOutcome` and will drop into pdb whenever it sees a test outcome that includes exc_info. It fires :func:`beforeInteraction` before launching pdb and :func:`afterInteraction` after. Other plugins may implement :func:`beforeInteraction` to return ``False`` and set ``event.handled`` to prevent this plugin from launching pdb. """ import logging import pdb from nose2 import events __unittest = True log = logging.getLogger(__name__) class Debugger(events.Plugin): """Enter pdb on test error or failure .. attribute :: pdb For ease of mocking and using different pdb implementations, pdb is aliased as a class attribute. """ configSection = 'debugger' commandLineSwitch = ('D', 'debugger', 'Enter pdb on test fail or error') # allow easy mocking and replacment of pdb pdb = pdb def __init__(self): self.errorsOnly = self.config.as_bool('errors-only', default=False) def testOutcome(self, event): """Drop into pdb on unexpected errors or failures""" if not event.exc_info or event.expected: # skipped tests, unexpected successes, expected failures return value, tb = event.exc_info[1:] test = event.test if self.errorsOnly and isinstance(value, test.failureException): return evt = events.UserInteractionEvent() result = self.session.hooks.beforeInteraction(evt) try: if not result and evt.handled: log.warning( "Skipping pdb for %s, user interaction not allowed", event) return self.pdb.post_mortem(tb) finally: self.session.hooks.afterInteraction(evt) nose2-0.6.4/nose2/plugins/doctests.py0000664000175000017500000000316112672050004017061 0ustar travistravis""" Load tests from doctests. This plugin implements :func:`handleFile` to load doctests from text files and python modules. To disable loading doctests from text files, configure an empty extensions list: .. code-block :: ini [doctest] extensions = """ import doctest import os from nose2.events import Plugin from nose2 import util __unittest = True class DocTestLoader(Plugin): configSection = 'doctest' commandLineSwitch = (None, 'with-doctest', 'Load doctests from text files and modules') def __init__(self): self.extensions = self.config.as_list('extensions', ['.txt', '.rst']) def handleFile(self, event): """Load doctests from text files and modules""" path = event.path _root, ext = os.path.splitext(path) if ext in self.extensions: suite = doctest.DocFileTest(path, module_relative=False) event.extraTests.append(suite) return elif not util.valid_module_name(os.path.basename(path)): return name, package_path = util.name_from_path(path) util.ensure_importable(package_path) try: module = util.module_from_name(name) except Exception: # XXX log warning here? return if hasattr(module, '__test__') and not module.__test__: return try: suite = doctest.DocTestSuite(module) except ValueError: # with python <= 3.5, doctest, very annoyingly, raises ValueError # when a module has no tests. return event.extraTests.append(suite) nose2-0.6.4/nose2/plugins/dundertest.py0000664000175000017500000000157612672050004017422 0ustar travistravis""" This plugin implements :func:`startTestRun`, which excludes all test objects that define a ``__test__`` attribute that evaluates to ``False``. """ from unittest import TestSuite from nose2 import events __unittest = True class DunderTestFilter(events.Plugin): """ Exclude all tests defining a ``__test__`` attribute that evaluates to ``False``. """ alwaysOn = True def startTestRun(self, event): """ Recurse :attr:`event.suite` and remove all test suites and test cases that define a ``__test__`` attribute that evaluates to ``False``. """ self.removeNonTests(event.suite) def removeNonTests(self, suite): for test in list(suite): if not getattr(test, '__test__', True): suite._tests.remove(test) elif isinstance(test, TestSuite): self.removeNonTests(test) nose2-0.6.4/nose2/plugins/failfast.py0000664000175000017500000000114712672050004017024 0ustar travistravis""" Stop the test run after the first error or failure. This plugin implements :func:`testOutcome` and sets ``event.result.shouldStop`` if it sees an outcome with exc_info that is not expected. """ from nose2 import events __unittest = True class FailFast(events.Plugin): """Stop the test run after error or failure""" commandLineSwitch = ( 'F', 'fail-fast', 'Stop the test run after the first error or failure') def testOutcome(self, event): """Stop on unexpected error or failure""" if event.exc_info and not event.expected: event.result.shouldStop = True nose2-0.6.4/nose2/plugins/junitxml.py0000664000175000017500000002074012672050004017105 0ustar travistravis""" Output test reports in junit-xml format. This plugin implements :func:`startTest`, :func:`testOutcome` and :func:`stopTestRun` to compile and then output a test report in junit-xml format. By default, the report is written to a file called ``nose2-junit.xml`` in the current working directory. You can configure the output filename by setting ``path`` in a ``[junit-xml]`` section in a config file. Unicode characters which are invalid in XML 1.0 are replaced with the ``U+FFFD`` replacement character. In the case that your software throws an error with an invalid byte string. By default, the ranges of discouraged characters are replaced as well. This can be changed by setting the ``keep_restricted`` configuration variable to ``True``. """ # Based on unittest2/plugins/junitxml.py, # which is itself based on the junitxml plugin from py.test import os.path import time import re import sys import json from xml.etree import ElementTree as ET import six from nose2 import events, result, util __unittest = True class JUnitXmlReporter(events.Plugin): """Output junit-xml test report to file""" configSection = 'junit-xml' commandLineSwitch = ('X', 'junit-xml', 'Generate junit-xml output report') def __init__(self): self.path = os.path.realpath( self.config.as_str('path', default='nose2-junit.xml')) self.keep_restricted = self.config.as_bool('keep_restricted', default=False) self.test_properties = self.config.as_str('test_properties', default=None) if self.test_properties is not None: self.test_properties_path = os.path.realpath(self.test_properties) self.errors = 0 self.failed = 0 self.skipped = 0 self.numtests = 0 self.tree = ET.Element('testsuite') self._start = None def startTest(self, event): """Count test, record start time""" self.numtests += 1 self._start = event.startTime def testOutcome(self, event): """Add test outcome to xml tree""" test = event.test testid = test.id().split('\n')[0] # split into module, class, method parts... somehow parts = testid.split('.') classname = '.'.join(parts[:-1]) method = parts[-1] testcase = ET.SubElement(self.tree, 'testcase') testcase.set('time', "%.6f" % self._time()) testcase.set('classname', classname) testcase.set('name', method) msg = '' if event.exc_info: msg = util.exc_info_to_string(event.exc_info, test) elif event.reason: msg = event.reason msg = string_cleanup(msg, self.keep_restricted) if event.outcome == result.ERROR: self.errors += 1 error = ET.SubElement(testcase, 'error') error.set('message', 'test failure') error.text = msg elif event.outcome == result.FAIL and not event.expected: self.failed += 1 failure = ET.SubElement(testcase, 'failure') failure.set('message', 'test failure') failure.text = msg elif event.outcome == result.PASS and not event.expected: self.skipped += 1 skipped = ET.SubElement(testcase, 'skipped') skipped.set('message', 'test passes unexpectedly') elif event.outcome == result.SKIP: self.skipped += 1 skipped = ET.SubElement(testcase, 'skipped') elif event.outcome == result.FAIL and event.expected: self.skipped += 1 skipped = ET.SubElement(testcase, 'skipped') skipped.set('message', 'expected test failure') skipped.text = msg system_err = ET.SubElement(testcase, 'system-err') system_err.text = string_cleanup( '\n'.join(event.metadata.get('logs', '')), self.keep_restricted ) def _check(self): if not os.path.exists(os.path.dirname(self.path)): raise IOError(2, 'JUnitXML: Parent folder does not exist for file', self.path) if self.test_properties is not None: if not os.path.exists(self.test_properties_path): raise IOError(2, 'JUnitXML: Properties file does not exist', self.test_properties_path) def stopTestRun(self, event): """Output xml tree to file""" self.tree.set('name', 'nose2-junit') self.tree.set('errors', str(self.errors)) self.tree.set('failures', str(self.failed)) self.tree.set('skipped', str(self.skipped)) self.tree.set('tests', str(self.numtests)) self.tree.set('time', "%.3f" % event.timeTaken) self._check() self._include_test_properties() self._indent_tree(self.tree) output = ET.ElementTree(self.tree) output.write(self.path, encoding="utf-8") def _include_test_properties(self): """Include test properties in xml tree""" if self.test_properties is None: return props = {} with open(self.test_properties_path) as data: try: props = json.loads(data.read()) except ValueError: raise ValueError('JUnitXML: could not decode file: \'%s\'' % self.test_properties_path) properties = ET.SubElement(self.tree, 'properties') for key, val in props.items(): prop = ET.SubElement(properties, 'property') prop.set('name', key) prop.set('value', val) def _indent_tree(self, elem, level=0): """In-place pretty formatting of the ElementTree structure.""" i = "\n" + level * " " if len(elem): if not elem.text or not elem.text.strip(): elem.text = i + " " if not elem.tail or not elem.tail.strip(): elem.tail = i for elem in elem: self._indent_tree(elem, level + 1) if not elem.tail or not elem.tail.strip(): elem.tail = i else: if level and (not elem.tail or not elem.tail.strip()): elem.tail = i def _time(self): try: return time.time() - self._start except Exception: pass finally: self._start = None return 0 # # xml utility functions # # six doesn't include a unichr function def _unichr(string): if six.PY3: return chr(string) else: return unichr(string) # etree outputs XML 1.0 so the 1.1 Restricted characters are invalid. # and there are no characters that can be given as entities aside # form & < > ' " which ever have to be escaped (etree handles these fine) ILLEGAL_RANGES = [(0x00, 0x08), (0x0B, 0x0C), (0x0E, 0x1F), (0xD800, 0xDFFF), (0xFFFE, 0xFFFF)] # 0xD800 thru 0xDFFF are technically invalid in UTF-8 but PY2 will encode # bytes into these but PY3 will do a replacement # Other non-characters which are not strictly forbidden but # discouraged. RESTRICTED_RANGES = [(0x7F, 0x84), (0x86, 0x9F), (0xFDD0, 0xFDDF)] # check for a wide build if sys.maxunicode > 0xFFFF: RESTRICTED_RANGES += [(0x1FFFE, 0x1FFFF), (0x2FFFE, 0x2FFFF), (0x3FFFE, 0x3FFFF), (0x4FFFE, 0x4FFFF), (0x5FFFE, 0x5FFFF), (0x6FFFE, 0x6FFFF), (0x7FFFE, 0x7FFFF), (0x8FFFE, 0x8FFFF), (0x9FFFE, 0x9FFFF), (0xAFFFE, 0xAFFFF), (0xBFFFE, 0xBFFFF), (0xCFFFE, 0xCFFFF), (0xDFFFE, 0xDFFFF), (0xEFFFE, 0xEFFFF), (0xFFFFE, 0xFFFFF), (0x10FFFE, 0x10FFFF)] ILLEGAL_REGEX_STR = \ six.u('[') + \ six.u('').join(["%s-%s" % (_unichr(l), _unichr(h)) for (l, h) in ILLEGAL_RANGES]) + \ six.u(']') RESTRICTED_REGEX_STR = \ six.u('[') + \ six.u('').join(["%s-%s" % (_unichr(l), _unichr(h)) for (l, h) in RESTRICTED_RANGES]) + \ six.u(']') _ILLEGAL_REGEX = re.compile(ILLEGAL_REGEX_STR, re.U) _RESTRICTED_REGEX = re.compile(RESTRICTED_REGEX_STR, re.U) def string_cleanup(string, keep_restricted=False): if not issubclass(type(string), six.text_type): string = six.text_type(string, encoding='utf-8', errors='replace') string = _ILLEGAL_REGEX.sub(six.u('\uFFFD'), string) if not keep_restricted: string = _RESTRICTED_REGEX.sub(six.u('\uFFFD'), string) return string nose2-0.6.4/nose2/plugins/layers.py0000664000175000017500000001341312672050004016531 0ustar travistravisimport logging import re import six from nose2 import events, util from nose2.suite import LayerSuite from nose2.compat import unittest, OrderedDict BRIGHT = r'\033[1m' RESET = r'\033[0m' __unittest = True log = logging.getLogger(__name__) class Layers(events.Plugin): alwaysOn = True def startTestRun(self, event): event.suite = self._makeLayerSuite(event) def _makeLayerSuite(self, event): return self._sortByLayers( event.suite, self.session.testLoader.suiteClass) def _sortByLayers(self, suite, suiteClass): top = suiteClass() # first find all of the layers mentioned layers = OrderedDict() for test in self._flatten(suite): # split tests up into buckets by layer layer = getattr(test, 'layer', None) if layer: layers.setdefault(layer, LayerSuite(layer=layer)).addTest(test) else: top.addTest(test) # then organize layers into a tree remaining = list(layers.keys()) seen = set() tree = {} while remaining: ly = remaining.pop() if ly in seen: continue seen.add(ly) # superclasses of this layer if ly is None: deps = [] else: deps = [cls for cls in util.bases_and_mixins(ly) if cls is not object] deps.reverse() if not deps: # layer is top-level self._addToTree(tree, ly, None) else: outer = ly while deps: inner, outer = outer, deps.pop() self._addToTree(tree, inner, outer) if outer not in layers: remaining.append(outer) layers[outer] = LayerSuite(layer=outer) # finally build the top-level suite self._treeToSuite(tree, None, top, layers) # printtree(top) return top def _addToTree(self, tree, inner, outer): found = False for k, v in tree.items(): if inner in v: found = True if outer is not None: v.remove(inner) break if outer is not None or not found: tree.setdefault(outer, []).append(inner) def _treeToSuite(self, tree, key, suite, layers): mysuite = layers.get(key, None) if mysuite: suite.addTest(mysuite) suite = mysuite sublayers = tree.get(key, []) # ensure that layers with a set order are in order sublayers.sort(key=self._sortKey) log.debug('sorted sublayers of %s (%s): %s', mysuite, getattr(mysuite, 'layer', 'no layer'), sublayers) for layer in sublayers: self._treeToSuite(tree, layer, suite, layers) def _flatten(self, suite): out = [] for test in suite: try: out.extend(self._flatten(test)) except TypeError: out.append(test) return out def _sortKey(self, layer): pos = getattr(layer, 'position', None) # ... lame if pos is not None: key = six.u("%04d") % pos else: key = layer.__name__ return key class LayerReporter(events.Plugin): commandLineSwitch = ( None, 'layer-reporter', 'Add layer information to test reports') configSection = 'layer-reporter' def __init__(self): self.indent = self.config.as_str('indent', ' ') self.colors = self.config.as_bool('colors', False) self.highlight_words = self.config.as_list('highlight-words', ['A', 'having', 'should']) self.highlight_re = re.compile( r'\b(%s)\b' % '|'.join(self.highlight_words)) self.layersReported = set() def reportStartTest(self, event): if self.session.verbosity < 2: return test = event.testEvent.test layer = getattr(test, 'layer', None) if not layer: return for ix, lys in enumerate(util.ancestry(layer)): for layer in lys: if layer not in self.layersReported: desc = self.describeLayer(layer) event.stream.writeln('%s%s' % (self.indent * ix, desc)) self.layersReported.add(layer) event.stream.write(self.indent * (ix + 1)) def describeLayer(self, layer): return self.format(getattr(layer, 'description', layer.__name__)) def format(self, st): if self.colors: return self.highlight_re.sub(r'%s\1%s' % (BRIGHT, RESET), st) return st def describeTest(self, event): if hasattr(event.test, 'methodDescription'): event.description = self.format(event.test.methodDescription()) if event.errorList and hasattr(event.test, 'layer'): # walk back layers to build full description self.describeLayers(event) def describeLayers(self, event): desc = [event.description] base = event.test.layer for layer in (base.__mro__ + getattr(base, 'mixins', ())): if layer is object: continue desc.append(self.describeLayer(layer)) desc.reverse() event.description = ' '.join(desc) # for debugging def printtree(suite, indent=''): six.print_('%s%s ->' % (indent, getattr(suite, 'layer', 'no layer'))) for test in suite: if isinstance(test, unittest.BaseTestSuite): printtree(test, indent + ' ') else: six.print_('%s %s' % (indent, test)) six.print_('%s<- %s' % (indent, getattr(suite, 'layer', 'no layer'))) nose2-0.6.4/nose2/plugins/logcapture.py0000664000175000017500000001360312672050004017400 0ustar travistravis""" Capture log messages during test execution, appending them to the error reports of failed tests. This plugin implements :func:`startTestRun`, :func:`startTest`, :func:`stopTest`, :func:`setTestOutcome`, and :func:`outcomeDetail` to set up a logging configuration that captures log messages during test execution, and appends them to error reports for tests that fail or raise exceptions. """ import logging from logging.handlers import BufferingHandler import threading from nose2.events import Plugin from nose2.util import ln, parse_log_level log = logging.getLogger(__name__) __unittest = True class LogCapture(Plugin): """Capture log messages during test execution""" configSection = 'log-capture' commandLineSwitch = (None, 'log-capture', 'Enable log capture') logformat = '%(name)s: %(levelname)s: %(message)s' logdatefmt = None clear = False filters = ['-nose'] def __init__(self): self.logformat = self.config.as_str('format', self.logformat) self.logdatefmt = self.config.as_str('date-format', self.logdatefmt) self.filters = self.config.as_list('filter', self.filters) self.clear = self.config.as_bool('clear-handlers', self.clear) self.loglevel = parse_log_level( self.config.as_str('log-level', 'NOTSET')) self.handler = MyMemoryHandler(1000, self.logformat, self.logdatefmt, self.filters) def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) def startSubprocess(self, event): self._setupLoghandler() def startTestRun(self, event): """Set up logging handler""" self._setupLoghandler() def startTest(self, event): """Set up handler for new test""" self._setupLoghandler() def setTestOutcome(self, event): """Store captured log messages in ``event.metadata``""" self._addCapturedLogs(event) def stopTest(self, event): """Clear captured messages, ready for next test""" self.handler.truncate() def outcomeDetail(self, event): """Append captured log messages to ``event.extraDetail``""" logs = event.outcomeEvent.metadata.get('logs', None) if logs: event.extraDetail.append(ln('>> begin captured logging <<')) event.extraDetail.extend(logs) event.extraDetail.append(ln('>> end captured logging <<')) def _setupLoghandler(self): # setup our handler with root logger root_logger = logging.getLogger() if self.clear: if hasattr(root_logger, "handlers"): for handler in root_logger.handlers: root_logger.removeHandler(handler) for logger in logging.Logger.manager.loggerDict.values(): if hasattr(logger, "handlers"): for handler in logger.handlers: logger.removeHandler(handler) # make sure there isn't one already # you can't simply use "if self.handler not in root_logger.handlers" # since at least in unit tests this doesn't work -- # LogCapture() is instantiated for each test case while root_logger # is module global # so we always add new MyMemoryHandler instance for handler in root_logger.handlers[:]: if isinstance(handler, MyMemoryHandler): root_logger.handlers.remove(handler) root_logger.addHandler(self.handler) root_logger.setLevel(self.loglevel) def _addCapturedLogs(self, event): format = self.handler.format records = [format(r) for r in self.handler.buffer] if 'logs' in event.metadata: event.metadata['logs'].extend(records) else: event.metadata['logs'] = records class FilterSet(object): def __init__(self, filter_components): self.inclusive, self.exclusive = self._partition(filter_components) @staticmethod def _partition(components): inclusive, exclusive = [], [] for component in components: if component.startswith('-'): exclusive.append(component[1:]) else: inclusive.append(component) return inclusive, exclusive def allow(self, record): """returns whether this record should be printed""" if not self: # nothing to filter return True return self._allow(record) and not self._deny(record) @staticmethod def _any_match(matchers, record): """return the bool of whether `record` starts with any item in `matchers`""" def record_matches_key(key): return record == key or record.startswith(key + '.') return any(map(record_matches_key, matchers)) def _allow(self, record): if not self.inclusive: return True return self._any_match(self.inclusive, record) def _deny(self, record): if not self.exclusive: return False return self._any_match(self.exclusive, record) class MyMemoryHandler(BufferingHandler): def __init__(self, capacity, logformat, logdatefmt, filters): BufferingHandler.__init__(self, capacity) fmt = logging.Formatter(logformat, logdatefmt) self.setFormatter(fmt) self.filterset = FilterSet(filters) def flush(self): pass # do nothing def truncate(self): self.buffer = [] def filter(self, record): return self.filterset.allow(record.name) def emit(self, record): # take a snapshot of the potentially mutable arguments record.msg = record.getMessage() record.args = {} BufferingHandler.emit(self, record) def __getstate__(self): state = self.__dict__.copy() del state['lock'] return state def __setstate__(self, state): self.__dict__.update(state) self.lock = threading.RLock() nose2-0.6.4/nose2/plugins/mp.py0000664000175000017500000003567012672050004015657 0ustar travistravis import logging import multiprocessing import select import unittest import collections import os import sys import six import multiprocessing.connection as connection from nose2 import events, loader, result, runner, session, util log = logging.getLogger(__name__) class MultiProcess(events.Plugin): configSection = 'multiprocess' def __init__(self): self.addArgument(self.setProcs, 'N', 'processes', '# o procs') self.testRunTimeout = self.config.as_float('test-run-timeout', 60.0) self.procs = self.config.as_int( 'processes', multiprocessing.cpu_count()) self.setAddress(self.config.as_str('bind_address', None)) self.cases = {} def setProcs(self, num): self.procs = int(num[0]) # FIXME merge n fix self.register() def setAddress(self, address): if address is None or address.strip() == '': address = [] else: address = [x.strip() for x in address.split(':')[:2]] #Background: On Windows, select.select only works on sockets. So the #ability to select a bindable address and optionally port for the mp #plugin was added. Pipes should support a form of select, but this #would require using pywin32. There are altnernatives but all have #some kind of downside. An alternative might be creating a connection #like object using a shared queue for incomings events. self.bind_host = None self.bind_port = 0 if sys.platform == "win32" or address: self.bind_host = '127.116.157.163' if address and address[0]: self.bind_host = address[0] self.bind_port = 0 if len(address) >= 2: self.bind_port = int(address[1]) def pluginsLoaded(self, event): self.addMethods('registerInSubprocess', 'startSubprocess', 'stopSubprocess') def startTestRun(self, event): event.executeTests = self._runmp def beforeInteraction(self, event): # prevent interactive plugins from running event.handled = True return False def _runmp(self, test, result): flat = list(self._flatten(test)) procs = self._startProcs(len(flat)) # send one initial task to each process for proc, conn in procs: if not flat: break caseid = flat.pop(0) conn.send(caseid) rdrs = [conn for proc, conn in procs if proc.is_alive()] while flat or rdrs: ready, _, _ = select.select(rdrs, [], [], self.testRunTimeout) for conn in ready: # XXX proc could be dead try: remote_events = conn.recv() except EOFError: # probably dead/12 log.warning("Subprocess connection closed unexpectedly") continue # XXX or die? if remote_events is None: # XXX proc is done, how to mark it dead? log.debug("Conn closed %s", conn) rdrs.remove(conn) continue # replay events testid, events = remote_events log.debug("Received results for %s", testid) for (hook, event) in events: log.debug("Received %s(%s)", hook, event) self._localize(event) getattr(self.session.hooks, hook)(event) # send a new test to the worker if there is one left if not flat: # if there isn't send None - it's the 'done' flag conn.send(None) continue caseid = flat.pop(0) conn.send(caseid) for _, conn in procs: conn.close() # ensure we wait until all processes are done before # exiting, to allow plugins running there to finalize for proc, _ in procs: proc.join() def _prepConns(self): """ If the ``bind_host`` is not ``None``, return: (multiprocessing.connection.Listener, (address, port, authkey)) else: (parent_connection, child_connection) For the former case: ``accept`` must be called on the listener. In order to get a ``Connection`` object for the socket. """ if self.bind_host is not None: #prevent "accidental" wire crossing authkey = os.urandom(20) address = (self.bind_host, self.bind_port) listener = connection.Listener(address, authkey=authkey) return (listener, listener.address + (authkey,)) else: return multiprocessing.Pipe() def _acceptConns(self, parent_conn): """ When listener is is a :class:`connection.Listener` instance: accept the next incoming connection. However, a timeout mechanism is needed. Since this functionality was added to support mp over inet sockets, this method assumes a Socket-based listen, and will accept the private _socket member to get a low_level socket to do a select on. """ if isinstance(parent_conn, connection.Listener): #ick private interface rdrs = [parent_conn._listener._socket] readable, _, _ = select.select(rdrs, [], [], self.testRunTimeout) if readable: return parent_conn.accept() else: raise RuntimeError('MP: Socket Connection Failed') else: return parent_conn def _startProcs(self, test_count): # XXX create session export session_export = self._exportSession() procs = [] count = min(test_count, self.procs) log.debug("Creating %i worker processes", count) for i in range(0, count): parent_conn, child_conn = self._prepConns() proc = multiprocessing.Process( target=procserver, args=(session_export, child_conn)) proc.daemon = True proc.start() parent_conn = self._acceptConns(parent_conn) procs.append((proc, parent_conn)) return procs def _flatten(self, suite): # XXX # examine suite tests to find out if they have class # or module fixtures and group them that way into names # of test classes or modules # ALSO record all test cases in self.cases log.debug("Flattening test into list of IDs") mods = {} classes = {} stack = [suite] while stack: suite = stack.pop() for test in suite: if isinstance(test, unittest.TestSuite): stack.append(test) else: testid = util.test_name(test) self.cases[testid] = test if util.has_module_fixtures(test): mods.setdefault(test.__class__.__module__, []).append( testid) elif util.has_class_fixtures(test): classes.setdefault( "%s.%s" % (test.__class__.__module__, test.__class__.__name__), []).append(testid) else: yield testid for cls in sorted(classes.keys()): yield cls for mod in sorted(mods.keys()): yield mod def _localize(self, event): # XXX set loader, case, result etc to local ones, if present in event # (event case will be just the id) # (traceback in exc_info if any won't be real!) if hasattr(event, 'result'): event.result = self.session.testResult if hasattr(event, 'loader'): event.loader = self.session.testLoader if hasattr(event, 'runner'): event.runner = self.session.testRunner if hasattr(event, 'test') and isinstance(event.test, six.string_types): # remote event.case is the test id try: event.test = self.cases[event.test] except KeyError: event.test = self.session.testLoader.failedLoadTests( 'test_not_found', RuntimeError("Unable to locate test case for %s in " "main process" % event.test))._tests[0] def _exportSession(self): # argparse isn't pickleable # no plugin instances # no hooks export = {'config': self.session.config, 'verbosity': self.session.verbosity, 'startDir': self.session.startDir, 'topLevelDir': self.session.topLevelDir, 'logLevel': self.session.logLevel, # XXX classes or modules? 'pluginClasses': []} # XXX fire registerInSubprocess -- add those plugin classes # (classes must be pickleable!) event = RegisterInSubprocessEvent() # FIXME should be own event type self.session.hooks.registerInSubprocess(event) export['pluginClasses'].extend(event.pluginClasses) return export def procserver(session_export, conn): # init logging system rlog = multiprocessing.log_to_stderr() rlog.setLevel(session_export['logLevel']) # make a real session from the "session" we got ssn = session.Session() ssn.config = session_export['config'] ssn.hooks = RecordingPluginInterface() ssn.verbosity = session_export['verbosity'] ssn.startDir = session_export['startDir'] ssn.topLevelDir = session_export['topLevelDir'] ssn.prepareSysPath() loader_ = loader.PluggableTestLoader(ssn) ssn.testLoader = loader_ result_ = result.PluggableTestResult(ssn) ssn.testResult = result_ runner_ = runner.PluggableTestRunner(ssn) # needed?? ssn.testRunner = runner_ # load and register plugins ssn.plugins = [ plugin(session=ssn) for plugin in session_export['pluginClasses']] rlog.debug("Plugins loaded: %s", ssn.plugins) for plugin in ssn.plugins: plugin.register() rlog.debug("Registered %s in subprocess", plugin) if isinstance(conn, collections.Sequence): conn = connection.Client(conn[:2], authkey=conn[2]) event = SubprocessEvent(loader_, result_, runner_, ssn.plugins, conn) res = ssn.hooks.startSubprocess(event) if event.handled and not res: conn.send(None) conn.close() ssn.hooks.stopSubprocess(event) return # receive and run tests executor = event.executeTests for testid in gentests(conn): if testid is None: break # XXX to handle weird cases like layers, need to # deal with the case that testid is something other # than a simple string. test = event.loader.loadTestsFromName(testid) # xxx try/except? rlog.debug("Execute test %s (%s)", testid, test) executor(test, event.result) events = [e for e in ssn.hooks.flush()] conn.send((testid, events)) rlog.debug("Log for %s returned", testid) conn.send(None) conn.close() ssn.hooks.stopSubprocess(event) # test generator def gentests(conn): while True: try: testid = conn.recv() if testid is None: return yield testid except EOFError: return # custom event classes class SubprocessEvent(events.Event): """Event fired at start and end of subprocess execution. .. attribute :: loader Test loader instance .. attribute :: result Test result .. attribute :: plugins List of plugins loaded in the subprocess. .. attribute :: connection The :class:`multiprocessing.Connection` instance that the subprocess uses for communication with the main process. .. attribute :: executeTests Callable that will be used to execute tests. Plugins may set this attribute to wrap or otherwise change test execution. The callable must match the signature:: def execute(suite, result): ... """ def __init__(self, loader, result, runner, plugins, connection, **metadata): self.loader = loader self.result = result self.runner = runner self.plugins = plugins self.connection = connection self.executeTests = lambda test, result: test(result) super(SubprocessEvent, self).__init__(**metadata) class RegisterInSubprocessEvent(events.Event): """Event fired to notify plugins that multiprocess testing will occur .. attribute :: pluginClasses Add a plugin class to this list to cause the plugin to be instantiated in each test-running subprocess. The most common thing to do, for plugins that need to run in subprocesses, is:: def registerInSubprocess(self, event): event.pluginClasses.append(self.__class__) """ def __init__(self, **metadata): self.pluginClasses = [] super(RegisterInSubprocessEvent, self).__init__(**metadata) # custom hook system that records calls and events class RecordingHook(events.Hook): def __init__(self, method, interface): super(RecordingHook, self).__init__(method) self.interface = interface def __call__(self, event): res = super(RecordingHook, self).__call__(event) self.interface.log(self.method, event) return res class RecordingPluginInterface(events.PluginInterface): hookClass = RecordingHook noLogMethods = set( ['getTestCaseNames', 'startSubprocess', 'stopSubprocess', 'registerInSubprocess', 'moduleLoadedSuite']) def __init__(self): super(RecordingPluginInterface, self).__init__() self.events = [] def log(self, method, event): self.events.append((method, event)) def flush(self): events = self.events[:] self.events = [] return events def register(self, method, plugin): """Register a plugin for a method. :param method: A method name :param plugin: A plugin instance """ self._hookForMethod(method).append(plugin) def __getattr__(self, attr): if attr.startswith('__'): raise AttributeError('No %s in %s' % (attr, self)) return self._hookForMethod(attr) def _hookForMethod(self, method): # return recording hook for most hooks, normal hook for those # (like test loading and subprocess events) that we don't want # to send back to the main process. try: return self.hooks[method] except KeyError: if method in self.noLogMethods or method.startswith('loadTest'): hook = events.Hook(method) else: hook = self.hookClass(method, self) self.hooks[method] = hook return hook nose2-0.6.4/nose2/plugins/outcomes.py0000664000175000017500000000376212672050004017076 0ustar travistravis""" Map exceptions to test outcomes. This plugin implements :func:`setTestOutcome` to enable simple mapping of exception classes to existing test outcomes. By setting a list of exception classes in a nose2 config file, you can configure exceptions that would otherwise be treated as test errors, to be treated as failures or skips instead: .. code-block :: ini [outcomes] always-on = True treat-as-fail = NotImplementedError treat-as-skip = TodoError IOError """ from nose2.events import Plugin __unittest = True class Outcomes(Plugin): """Map exceptions to other test outcomes""" configSection = 'outcomes' commandLineSwitch = (None, 'set-outcomes', 'Treat some configured exceptions as failure or skips') def __init__(self): self.treatAsFail = set(self.config.as_list('treat-as-fail', [])) self.treatAsSkip = set(self.config.as_list('treat-as-skip', [])) def setTestOutcome(self, event): """Update outcome, exc_info and reason based on configured mappings""" if event.exc_info: ec, ev, tb = event.exc_info classname = ec.__name__ if classname in self.treatAsFail: short, long_ = self.labels(classname) self._setOutcome(event, 'failed', short, long_) elif classname in self.treatAsSkip: short, long_ = self.labels(classname, upper=False) self._setOutcome( event, 'skipped', short, "%s: '%s'" % (long_, ev), str(ev)) def labels(self, label, upper=True): if upper: label = label.upper() else: label = label.lower() short = label[0] return short, label def _setOutcome(self, event, outcome, shortLabel, longLabel, reason=None): event.outcome = outcome event.shortLabel = shortLabel event.longLabel = longLabel if reason: event.exc_info = None event.reason = reason nose2-0.6.4/nose2/plugins/printhooks.py0000664000175000017500000000342512672050004017434 0ustar travistravis""" This plugin is primarily useful for plugin authors who want to debug their plugins. It prints each hook that is called to stderr, along with details of the event that was passed to the hook. To do that, this plugin overrides :meth:`nose2.events.Plugin.register` and, after registration, replaces all existing :class:`nose2.events.Hook` instances in ``session.hooks`` with instances of a :class:`~nose2.events.Hook` subclass that prints information about each call. """ import sys from nose2 import events INDENT = [] __unittest = True class PrintHooks(events.Plugin): """Print hooks as they are called""" configSection = 'print-hooks' commandLineSwitch = ('P', 'print-hooks', 'Print names of hooks in order of execution') def register(self): """Override to inject noisy hook instances. Replaces :class:`~nose2.events.Hook` instances in ``self.session.hooks.hooks`` with noisier objects. """ super(PrintHooks, self).register() # now we can be sure that all other plugins have loaded # and this plugin is active, patch in our hook class self.session.hooks.hookClass = NoisyHook for attr, hook in self.session.hooks.hooks.items(): newhook = NoisyHook(attr) newhook.plugins = hook.plugins self.session.hooks.hooks[attr] = newhook class NoisyHook(events.Hook): def __call__(self, event): _report(self.method, event) _indent() try: return super(NoisyHook, self).__call__(event) finally: _dedent() def _report(method, event): sys.stderr.write("\n%s%s: %s" % (''.join(INDENT), method, event)) def _indent(): INDENT.append(' ') def _dedent(): if INDENT: INDENT.pop() nose2-0.6.4/nose2/plugins/prof.py0000664000175000017500000000534212672050004016202 0ustar travistravis""" Profile test execution using hotshot. This plugin implements :func:`startTestRun` and replaces ``event.executeTests`` with :meth:`hotshot.Profile.runcall`. It implements :func:`beforeSummaryReport` to output profiling information before the final test summary time. Config file options ``filename``, ``sort`` and ``restrict`` can be used to change where profiling information is saved and how it is presented. """ try: import hotshot from hotshot import stats except ImportError: hotshot, stats = None, None import logging import os import tempfile from nose2 import events, util log = logging.getLogger(__name__) __unittest = True class Profiler(events.Plugin): """Profile the test run""" configSection = 'profiler' commandLineSwitch = ('P', 'profile', 'Run tests under profiler') def __init__(self): self.pfile = self.config.as_str('filename', '') self.sort = self.config.as_str('sort', 'cumulative') self.restrict = self.config.as_list('restrict', []) self.clean = False self.fileno = None def register(self): """Don't register if hotshot is not found""" if hotshot is None: log.error("Unable to profile: hotshot module not available") return super(Profiler, self).register() def startTestRun(self, event): """Set up the profiler""" self.createPfile() self.prof = hotshot.Profile(self.pfile) event.executeTests = self.prof.runcall def beforeSummaryReport(self, event): """Output profiling results""" # write prof output to stream class Stream: def write(self, *msg): for m in msg: event.stream.write(m) event.stream.write(' ') event.stream.flush() stream = Stream() self.prof.close() prof_stats = stats.load(self.pfile) prof_stats.sort_stats(self.sort) event.stream.writeln(util.ln("Profiling results")) tmp = prof_stats.stream prof_stats.stream = stream try: if self.restrict: prof_stats.print_stats(*self.restrict) else: prof_stats.print_stats() finally: prof_stats.stream = tmp self.prof.close() event.stream.writeln('') if self.clean: if self.fileno: try: os.close(self.fileno) except OSError: pass try: os.unlink(self.pfile) except OSError: pass def createPfile(self): if not self.pfile: self.fileno, self.pfile = tempfile.mkstemp() self.clean = True nose2-0.6.4/nose2/plugins/result.py0000664000175000017500000002363312672050004016555 0ustar travistravis""" Collect and report test results. This plugin implements the primary user interface for nose2. It collects test outcomes and reports on them to the console, as well as firing several hooks for other plugins to do their own reporting. To see this report, nose2 MUST be run with the :option:`verbose` flag:: nose2 --verbose This plugin extends standard unittest console reporting slightly by allowing custom report categories. To put events into a custom reporting category, change the event.outcome to whatever you want. Note, however, that customer categories are *not* treated as errors or failures for the purposes of determining whether a test run has succeeded. Don't disable this plugin, unless you (a) have another one doing the same job, or (b) really don't want any test results (and want all test runs to ``exit(1)``). """ # This module contains some code copied from unittest2/runner.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import sys import unittest from nose2 import events, result, util __unittest = True class ResultReporter(events.Plugin): """Result plugin that implements standard unittest console reporting""" alwaysOn = True configSection = 'test-result' separator1 = '=' * 70 separator2 = '-' * 70 def __init__(self): self.testsRun = 0 self.reportCategories = {'failures': [], 'errors': [], 'skipped': [], 'expectedFailures': [], 'unexpectedSuccesses': []} self.dontReport = set(['errors', 'failures', 'skipped', 'passed', 'expectedFailures', 'unexpectedSuccesses']) self.stream = util._WritelnDecorator(sys.stderr) self.descriptions = self.config.as_bool('descriptions', True) def startTest(self, event): """Handle startTest hook - prints test description if verbosity > 1 """ self.testsRun += 1 self._reportStartTest(event) def testOutcome(self, event): """Handle testOutcome hook - records test outcome in reportCategories - prints test outcome label - fires reporting hooks (:func:`reportSuccess`, :func:`reportFailure`, etc) """ if event.outcome == result.ERROR: self.reportCategories['errors'].append(event) self._reportError(event) elif event.outcome == result.FAIL: if not event.expected: self.reportCategories['failures'].append(event) self._reportFailure(event) else: self.reportCategories['expectedFailures'].append(event) self._reportExpectedFailure(event) elif event.outcome == result.SKIP: self.reportCategories['skipped'].append(event) self._reportSkip(event) elif event.outcome == result.PASS: if event.expected: self._reportSuccess(event) else: self.reportCategories['unexpectedSuccesses'].append(event) self._reportUnexpectedSuccess(event) else: # generic outcome handling self.reportCategories.setdefault(event.outcome, []).append(event) self._reportOtherOutcome(event) def afterTestRun(self, event): """Handle afterTestRun hook - prints error lists - prints summary - fires summary reporting hooks (:func:`beforeErrorList`, :func:`beforeSummaryReport`, etc) """ self._reportSummary(event) def wasSuccessful(self, event): event.success = True for name, events in self.reportCategories.items(): for e in events: if (e.outcome == result.ERROR or (e.outcome == result.FAIL and not e.expected)): event.success = False break def _reportStartTest(self, event): evt = events.ReportTestEvent(event, self.stream) self.session.hooks.reportStartTest(evt) if evt.handled: return if self.session.verbosity > 1: # allow other plugins to override/spy on stream evt.stream.write(self._getDescription(event.test, errorList=False)) evt.stream.write(' ... ') evt.stream.flush() def _reportError(self, event): self._report(event, 'reportError', 'E', 'ERROR') def _reportFailure(self, event): self._report(event, 'reportFailure', 'F', 'FAIL') def _reportSkip(self, event): self._report(event, 'reportSkip', 's', 'skipped %s' % event.reason) def _reportExpectedFailure(self, event): self._report(event, 'reportExpectedFailure', 'x', 'expected failure') def _reportUnexpectedSuccess(self, event): self._report( event, 'reportUnexpectedSuccess', 'u', 'unexpected success') def _reportOtherOutcome(self, event): self._report(event, 'reportOtherOutcome', '?', 'unknown outcome') def _reportSuccess(self, event): self._report(event, 'reportSuccess', '.', 'ok') def _reportSummary(self, event): # let others print something evt = events.ReportSummaryEvent( event, self.stream, self.reportCategories) self.session.hooks.beforeErrorList(evt) # allows other plugins to mess with report categories cats = evt.reportCategories errors = cats.get('errors', []) failures = cats.get('failures', []) # use evt.stream so plugins can replace/wrap/spy it evt.stream.writeln('') self._printErrorList('ERROR', errors, evt.stream) self._printErrorList('FAIL', failures, evt.stream) for flavour, events_ in cats.items(): if flavour in self.dontReport: continue self._printErrorList(flavour.upper(), events_, evt.stream) self._printSummary(evt) def _printErrorList(self, flavour, events_, stream): for event in events_: desc = self._getDescription(event.test, errorList=True) err = self._getOutcomeDetail(event) stream.writeln(self.separator1) stream.writeln("%s: %s" % (flavour, desc)) stream.writeln(self.separator2) stream.writeln("%s" % err) def _printSummary(self, reportEvent): self.session.hooks.beforeSummaryReport(reportEvent) stream = reportEvent.stream stream.writeln(self.separator2) run = self.testsRun msg = ( "Ran %d test%s in %.3fs\n" % (run, run != 1 and "s" or "", reportEvent.stopTestEvent.timeTaken)) stream.writeln(msg) infos = [] extraInfos = [] if reportEvent.stopTestEvent.result.wasSuccessful(): stream.write("OK") else: stream.write("FAILED") failed = len(reportEvent.reportCategories.get('failures', [])) errored = len(reportEvent.reportCategories.get('errors', [])) skipped = len(reportEvent.reportCategories.get('skipped', [])) expectedFails = len( reportEvent.reportCategories.get('expectedFailures', [])) unexpectedSuccesses = len( reportEvent.reportCategories.get('unexpectedSuccesses', [])) for flavour, results in reportEvent.reportCategories.items(): if flavour in self.dontReport: continue count = len(results) if count: extraInfos.append("%s=%d" % (flavour, count)) if failed: infos.append("failures=%d" % failed) if errored: infos.append("errors=%d" % errored) if skipped: infos.append("skipped=%d" % skipped) if expectedFails: infos.append("expected failures=%d" % expectedFails) if unexpectedSuccesses: infos.append("unexpected successes=%d" % unexpectedSuccesses) infos.extend(extraInfos) if infos: reportEvent.stream.writeln(" (%s)" % (", ".join(infos),)) else: reportEvent.stream.writeln('') self.session.hooks.afterSummaryReport(reportEvent) def _getDescription(self, test, errorList): if not isinstance(test, unittest.TestCase): return test.__class__.__name__ doc_first_line = test.shortDescription() if self.descriptions and doc_first_line: desc = '\n'.join((str(test), doc_first_line)) else: desc = str(test) event = events.DescribeTestEvent( test, description=desc, errorList=errorList) self.session.hooks.describeTest(event) return event.description def _getOutcomeDetail(self, event): evt = events.OutcomeDetailEvent(event) result = self.session.hooks.outcomeDetail(evt) if evt.handled: return result exc_info = getattr(event, 'exc_info', None) test = getattr(event, 'test', None) if exc_info: detail = [util.exc_info_to_string(exc_info, test)] else: detail = [] if evt.extraDetail: detail.extend(evt.extraDetail) try: return "\n".join(detail) except UnicodeDecodeError: return "\n".join(util.safe_decode(d) for d in detail) def _report(self, event, hook, shortLabel, longLabel): evt = events.ReportTestEvent(event, self.stream) getattr(self.session.hooks, hook)(evt) if evt.handled: return if self.session.verbosity > 1: # event I fired has stream, event I received has labels evt.stream.writeln(getattr(event, 'longLabel', None) or longLabel) elif self.session.verbosity: evt.stream.write(getattr(event, 'shortLabel', None) or shortLabel) evt.stream.flush() nose2-0.6.4/nose2/plugins/testid.py0000664000175000017500000000645712672050004016540 0ustar travistravis""" Allow easy test selection with test ids. Assigns (and, in verbose mode, prints) a sequential test id for each test executed. Ids can be fed back in as test names, and this plugin will translate them back to full test names. Saves typing! This plugin implements :func:`reportStartTest`, :func:`loadTestsFromName`, :func:`loadTestsFromNames` and :func:`stopTest`. """ import os import pickle import re from nose2.events import Plugin from nose2 import util __unittest = True class TestId(Plugin): """Allow easy test select with ids""" configSection = 'testid' commandLineSwitch = ('I', 'with-id', 'Add test ids to output') idpat = re.compile(r'(\d+)') def __init__(self): self.idfile = self.config.as_str('id-file', '.noseids') self.ids = {} self.tests = {} if not os.path.isabs(self.idfile): # FIXME expand-user? self.idfile = os.path.join(os.getcwd(), self.idfile) self.id = 0 self._loaded = False def nextId(self): """Increment ID and return it.""" self.id += 1 return self.id def reportStartTest(self, event): """Record and possibly output test id""" testid = util.test_name(event.testEvent.test) if testid not in self.tests: id_ = self.nextId() self.ids[id_] = testid self.tests[testid] = id_ else: id_ = self.tests[testid] event.metadata['testid'] = id_ if self.session.verbosity > 1: event.stream.write('#%s ' % id_) def loadTestsFromName(self, event): """Load tests from a name that is an id If the name is a number, it might be an ID assigned by us. If we can find a test to which we have assigned that ID, event.name is changed to the test's real ID. In this way, tests can be referred to via sequential numbers. """ testid = self._testNameFromId(event.name) if testid is not None: event.name = testid def loadTestsFromNames(self, event): """Translate test ids into test names""" for i, name in enumerate(event.names[:]): testid = self._testNameFromId(name) if testid is not None: event.names[i] = testid def stopTestRun(self, event): """Write testids file""" with open(self.idfile, 'wb') as fh: pickle.dump({'ids': self.ids, 'tests': self.tests}, fh) def loadIds(self): """Load previously pickled 'ids' and 'tests' attributes.""" if self._loaded: return try: with open(self.idfile, 'rb') as fh: data = pickle.load(fh) except EnvironmentError: self._loaded = True return if 'ids' in data: self.ids = data['ids'] if 'tests' in data: self.tests = data['tests'] self.id = max(self.ids.keys()) self._loaded = True def _testNameFromId(self, name): """Try to translate one of our IDs to real test ID.""" m = self.idpat.match(name) if m is None: return None id_ = int(m.groups()[0]) self.loadIds() # Translate to test's real ID try: return self.ids[id_] except KeyError: return None nose2-0.6.4/nose2/tests/0000775000175000017500000000000012672050226014345 5ustar travistravisnose2-0.6.4/nose2/tests/functional/0000775000175000017500000000000012672050226016507 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/0000775000175000017500000000000012672050226020223 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/cfg/0000775000175000017500000000000012672050226020762 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/cfg/a.cfg0000664000175000017500000000005112672050004021651 0ustar travistravis[a] a = 1 [unittest] plugins = plugin_a nose2-0.6.4/nose2/tests/functional/support/cfg/b.cfg0000664000175000017500000000002012672050004021646 0ustar travistravis[b] b = 4 5 nose2-0.6.4/nose2/tests/functional/support/lib/0000775000175000017500000000000012672050226020771 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/lib/plugin_a.py0000664000175000017500000000022612672050004023133 0ustar travistravisfrom nose2 import events class PluginA(events.Plugin): configSection = 'a' def __init__(self): self.a = self.config.as_int('a', 0) nose2-0.6.4/nose2/tests/functional/support/scenario/0000775000175000017500000000000012672050226022026 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/class_fixtures/0000775000175000017500000000000012672050226025064 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/class_fixtures/test_cf_testcase.py0000664000175000017500000000075512672050004030761 0ustar travistravisimport unittest class Test(unittest.TestCase): @classmethod def setUpClass(cls): cls.x = 1 def test_1(self): assert self.x def test_2(self): assert self.x class Test2(unittest.TestCase): def setUp(self): self.x = 1 def test_1(self): assert self.x def test_2(self): assert self.x class Test3(Test): # this has class setup by virtue of inheritting from Test def test_3(self): assert self.x nose2-0.6.4/nose2/tests/functional/support/scenario/colliding_test_modules/0000775000175000017500000000000012672050226026561 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/colliding_test_modules/tests/0000775000175000017500000000000012672050226027723 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/colliding_test_modules/tests/more_tests/0000775000175000017500000000000012672050226032107 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/colliding_test_modules/tests/more_tests/test.py0000664000175000017500000000000012672050004033420 0ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/colliding_test_modules/tests/test.py0000664000175000017500000000000012672050004031234 0ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/decorators/0000775000175000017500000000000012672050226024173 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/decorators/test_decorators.py0000664000175000017500000000077112672050004027750 0ustar travistravisfrom nose2.tools.decorators import with_setup, with_teardown setup_performed = False teardown_performed = False def setup(): global setup_performed setup_performed = True def teardown(): global teardown_performed teardown_performed = True @with_setup(setup) def test_with_setup(): assert setup_performed, 'Setup not performed.' @with_teardown(teardown) def test_with_teardown(): pass def test_teardown_ran(): assert teardown_performed, 'Teardown not performed.' nose2-0.6.4/nose2/tests/functional/support/scenario/doctests/0000775000175000017500000000000012672050226023656 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/doctests/doctests_pkg1/0000775000175000017500000000000012672050226026430 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/doctests/doctests_pkg1/__init__.py0000664000175000017500000000000012672050004030521 0ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/doctests/doctests_pkg1/docs1.py0000664000175000017500000000003012672050004027776 0ustar travistravis""" >>> 2 == 2 True """ nose2-0.6.4/nose2/tests/functional/support/scenario/doctests/doctests_pkg1/docs1.rst0000664000175000017500000000002012672050004030155 0ustar travistravis>>> 1 == 1 True nose2-0.6.4/nose2/tests/functional/support/scenario/doctests/doctests_pkg1/docs1.txt0000664000175000017500000000004112672050004030167 0ustar travistravis>>> 2 == 2 True >>> 3 == 2 False nose2-0.6.4/nose2/tests/functional/support/scenario/doctests/docs.py0000664000175000017500000000003012672050004025143 0ustar travistravis""" >>> 2 == 2 True """ nose2-0.6.4/nose2/tests/functional/support/scenario/doctests/docs.rst0000664000175000017500000000002012672050004025322 0ustar travistravis>>> 1 == 1 True nose2-0.6.4/nose2/tests/functional/support/scenario/doctests/docs.txt0000664000175000017500000000004112672050004025334 0ustar travistravis>>> 2 == 2 True >>> 3 == 2 False nose2-0.6.4/nose2/tests/functional/support/scenario/dundertest_attribute/0000775000175000017500000000000012672050226026272 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/dundertest_attribute/test.py0000664000175000017500000000016412672050004027616 0ustar travistravisimport unittest class TestDunderTest(unittest.TestCase): __test__ = False def test_a(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/expected_failures/0000775000175000017500000000000012672050226025521 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/expected_failures/expected_failures.py0000664000175000017500000000055312672050004031563 0ustar travistravisfrom nose2.compat import unittest class TestWithExpectedFailures(unittest.TestCase): @unittest.expectedFailure def test_should_fail(self): assert False @unittest.expectedFailure def test_should_pass(self): assert True def test_whatever(self): assert True def test_fails(self): assert False nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/0000775000175000017500000000000012672050226023700 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/chdir/0000775000175000017500000000000012672050226024771 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/chdir/test_junitxml_chdir.py0000664000175000017500000000061012672050004031414 0ustar travistravisimport os.path import shutil import tempfile from nose2.compat import unittest class Test(unittest.TestCase): def setUp(self): super(Test, self).setUp() self.temp_dir = tempfile.mkdtemp() def tearDown(self): super(Test, self).tearDown() shutil.rmtree(self.temp_dir, ignore_errors=True) def test_chdir(self): os.chdir(self.temp_dir) nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/empty_properties/0000775000175000017500000000000012672050226027312 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/empty_properties/properties.json0000664000175000017500000000000012672050004032361 0ustar travistravis././@LongLink0000000000000000000000000000016000000000000011562 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/empty_properties/test_junitxml_empty_properties.pynose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/empty_properties/test_junitxml_empty_pr0000664000175000017500000000012312672050004034053 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/empty_properties/unittest.cfg0000664000175000017500000000013012672050004031636 0ustar travistravis[junit-xml] always-on = False keep_restricted = False test_properties = properties.json nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/fail_to_write/0000775000175000017500000000000012672050226026527 5ustar travistravis././@LongLink0000000000000000000000000000015200000000000011563 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/fail_to_write/test_junitxml_fail_to_write.pynose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/fail_to_write/test_junitxml_fail_to_wri0000664000175000017500000000012312672050004033727 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/fail_to_write/unittest.cfg0000664000175000017500000000012112672050004031053 0ustar travistravis[junit-xml] always-on = False keep_restricted = False path = /does/not/exist.xml nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/happyday/0000775000175000017500000000000012672050226025517 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/happyday/test_junitxml_happyday.py0000664000175000017500000000012312672050004032667 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/missing_properties/0000775000175000017500000000000012672050226027625 5ustar travistravis././@LongLink0000000000000000000000000000016400000000000011566 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/missing_properties/test_junitxml_missing_properties.pynose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/missing_properties/test_junitxml_missin0000664000175000017500000000012312672050004034031 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/missing_properties/unittest.cfg0000664000175000017500000000013012672050004032151 0ustar travistravis[junit-xml] always-on = False keep_restricted = False test_properties = properties.json nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/with_properties/0000775000175000017500000000000012672050226027127 5ustar travistravis././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/with_properties/test_junitxml_with_properties.pynose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/with_properties/test_junitxml_with_prop0000664000175000017500000000012312672050004034044 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/junitxml/with_properties/unittest.cfg0000664000175000017500000000013012672050004031453 0ustar travistravis[junit-xml] always-on = False keep_restricted = False test_properties = properties.json nose2-0.6.4/nose2/tests/functional/support/scenario/layers/0000775000175000017500000000000012672050226023325 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/layers/test_layers.py0000664000175000017500000000731612672050004026236 0ustar travistravisfrom nose2.compat import unittest STATE = {} class Base(object): @classmethod def setUp(cls): STATE['base'] = 'setup' @classmethod def tearDown(cls): del STATE['base'] class LayerA(Base): position = 1 @classmethod def setUp(cls): STATE['layerA'] = 'setup' @classmethod def tearDown(cls): del STATE['layerA'] @classmethod def testSetUp(cls, test): STATE['layerA.test'] = 'setup' # print "->", STATE, test @classmethod def testTearDown(cls, test): # print "<-", STATE, test del STATE['layerA.test'] class LayerA_1(LayerA): position = 0 @classmethod def setUp(cls): STATE['layerA_1'] = 'setup' @classmethod def tearDown(cls): del STATE['layerA_1'] class LayerB(LayerA): position = 2 @classmethod def setUp(cls): STATE['layerB'] = 'setup' @classmethod def tearDown(cls): del STATE['layerB'] class LayerB_1(LayerB): position = 0 @classmethod def setUp(cls): STATE['layerB_1'] = 'setup' @classmethod def tearDown(cls): del STATE['layerB_1'] class LayerC(LayerB, LayerA): position = 1 @classmethod def setUp(cls): STATE['layerC'] = 'setup' @classmethod def tearDown(cls): del STATE['layerC'] class LayerD(Base): position = 0 @classmethod def setUp(cls): STATE['layerD'] = 'setup' @classmethod def tearDown(cls): del STATE['layerD'] class Outer(unittest.TestCase): layer = Base def test(self): self.assertEqual(STATE.get('base'), 'setup') class InnerA(unittest.TestCase): layer = LayerA def setUp(self): STATE['innerA.test'] = 'setup' def tearDown(self): del STATE['innerA.test'] def test(self): expect = {'base': 'setup', 'layerA': 'setup', 'innerA.test': 'setup', 'layerA.test': 'setup'} for k, v in expect.items(): self.assertEqual(STATE.get(k), v) class InnerA_1(unittest.TestCase): layer = LayerA_1 def test(self): expect = {'base': 'setup', 'layerA': 'setup', 'layerA_1': 'setup', 'layerA.test': 'setup'} for k, v in expect.items(): self.assertEqual(STATE.get(k), v) class InnerB(unittest.TestCase): layer = LayerB def setUp(self): STATE['innerB.test'] = 'setup' def tearDown(self): STATE['innerB.test'] = 'tearDown' class InnerB_1(unittest.TestCase): layer = LayerB_1 def test(self): expect = {'base': 'setup', 'layerB': 'setup', 'layerB_1': 'setup'} for k, v in expect.items(): self.assertEqual(STATE.get(k), v) class InnerC(unittest.TestCase): layer = LayerC def test(self): expect = {'base': 'setup', 'layerB': 'setup', 'layerC': 'setup', 'layerA': 'setup', 'layerA.test': 'setup'} for k, v in expect.items(): self.assertEqual(STATE.get(k), v) def test2(self): expect = {'base': 'setup', 'layerB': 'setup', 'layerC': 'setup', 'layerA': 'setup', 'layerA.test': 'setup'} for k, v in expect.items(): self.assertEqual(STATE.get(k), v) class InnerD(unittest.TestCase): layer = LayerD def test(self): self.assertEqual( {'base': 'setup', 'layerD': 'setup'}, STATE) class NoLayer(unittest.TestCase): def test(self): self.assertEqual(STATE, {}) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_and_attributes/0000775000175000017500000000000012672050226026415 5ustar travistravis././@LongLink0000000000000000000000000000015000000000000011561 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/layers_and_attributes/test_layers_and_attributes.pynose2-0.6.4/nose2/tests/functional/support/scenario/layers_and_attributes/test_layers_and_attributes0000664000175000017500000000120212672050004033753 0ustar travistravisfrom nose2.compat import unittest STATE = {} class L1(object): @classmethod def setUp(cls): STATE['L1'] = 'setup' @classmethod def tearDown(cls): del STATE['L1'] class L2(object): @classmethod def setUp(cls): STATE['L2'] = 'setup' @classmethod def tearDown(cls): del STATE['L2'] class LayerAndAttributesA(unittest.TestCase): layer = L1 a = 1 def test(self): self.assertEqual(STATE.get('L1'), 'setup') class LayerAndAttributesB(unittest.TestCase): layer = L2 b = 1 def test(self): self.assertEqual(STATE.get('L2'), 'setup') nose2-0.6.4/nose2/tests/functional/support/scenario/layers_setups/0000775000175000017500000000000012672050226024730 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/layers_setups/higher_layer_setup.py0000664000175000017500000000146212672050004031161 0ustar travistravisimport logging log = logging.getLogger(__name__) from nose2.tools import such with such.A('foo') as it: it.upper_run = 0 it.lower_run = 0 @it.has_setup def upper_test_setup(case): log.error('foo::setUp') it.upper_run += 1 with it.having('some bar'): @it.has_setup def lower_test_setup(case): log.error('foo some bar::setUp') it.lower_run += 1 @it.should("run all setups") def test_run_all_setups(case): case.assertEquals(it.upper_run, 1) case.assertEquals(it.lower_run, 1) @it.should("run all setups just once") def test_run_all_setups_just_once(case): case.assertEquals(it.upper_run, 1) case.assertEquals(it.lower_run, 1) it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_3layers.py0000664000175000017500000000223112672050004033516 0ustar travistravisimport logging log = logging.getLogger(__name__) from nose2.tools import such with such.A('foo') as it: it.upper_run = 0 it.mid_run = 0 it.lower_run = 0 @it.has_test_setup def upper_test_setup(case): log.error('foo::setUp') it.upper_run += 1 with it.having('some bar'): @it.has_test_setup def middle_test_setup(case): log.error('foo some bar::setUp') it.mid_run += 1 with it.having('and more'): @it.has_test_setup def lower_test_setup(case): log.error('foo some bar and more::setUp') it.lower_run += 1 @it.should("run all setups") def test_run_all_setups(case): case.assertEquals(it.upper_run, 1) case.assertEquals(it.mid_run, 1) case.assertEquals(it.lower_run, 1) @it.should("run all setups again") def test_run_all_setups_again(case): case.assertEquals(it.upper_run, 2) case.assertEquals(it.mid_run, 2) case.assertEquals(it.lower_run, 2) it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_no_test.py0000664000175000017500000000146412672050004033616 0ustar travistravisimport logging log = logging.getLogger(__name__) from nose2.tools import such with such.A('foo') as it: it.upper_run = 0 it.lower_run = 0 @it.has_test_setup def upper_test_setup(case): log.error('foo::setUp') it.upper_run += 1 with it.having('some bar'): @it.has_test_setup def lower_test_setup(case): log.error('foo some bar::setUp') it.lower_run += 1 @it.should("run all setups") def test_run_all_setups(case): case.assertEquals(it.upper_run, 1) case.assertEquals(it.lower_run, 1) @it.should("run all setups again") def test_run_all_setups_again(case): case.assertEquals(it.upper_run, 2) case.assertEquals(it.lower_run, 2) it.createTests(globals()) ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_with_test.pynose2-0.6.4/nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_with_test.p0000664000175000017500000000173312672050004033763 0ustar travistravisimport logging log = logging.getLogger(__name__) from nose2.tools import such with such.A('foo') as it: it.upper_run = 0 it.lower_run = 0 @it.has_test_setup def upper_test_setup(case): log.error('foo::setUp') it.upper_run += 1 @it.should("run upper setups") def test_run_upper_setups(case): case.assertEquals(it.upper_run, 1) case.assertEquals(it.lower_run, 0) with it.having('some bar'): @it.has_test_setup def lower_test_setup(case): log.error('foo some bar::setUp') it.lower_run += 1 @it.should("run all setups") def test_run_all_setups(case): case.assertEquals(it.upper_run, 2) case.assertEquals(it.lower_run, 1) @it.should("run all setups again") def test_run_all_setups_again(case): case.assertEquals(it.upper_run, 3) case.assertEquals(it.lower_run, 2) it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/0000775000175000017500000000000012672050226025754 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/test_layer_setup_fail.py0000664000175000017500000000034112672050004032704 0ustar travistravisimport unittest class Layer(object): @classmethod def setUp(cls): raise RuntimeError('Bad Error in Layer setUp!') class Test(unittest.TestCase): layer = Layer def testPass(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/test_layer_teardown_fail.py0000664000175000017500000000044112672050004033370 0ustar travistravisimport unittest class Layer(object): @classmethod def setUp(cls): pass @classmethod def testTearDown(cls): raise RuntimeError('Bad Error in Layer testTearDown!') class Test(unittest.TestCase): layer = Layer def testPass(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/test_layers_with_errors.py0000664000175000017500000000065312672050004033311 0ustar travistravisfrom nose2.compat import unittest class Layer(object): description = 'fixture with a value' @classmethod def setUp(cls): cls.value = 1 class Test(unittest.TestCase): layer = Layer def test_ok(self): self.assertEqual(self.layer.value, 1) def test_fail(self): self.assertEqual(self.layer.value, 2) def test_err(self): self.assertEqual(self.layer.mulch, 'pine') nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/test_such_setup_fail.py0000664000175000017500000000043212672050004032533 0ustar travistravisfrom nose2.tools import such with such.A('test scenario with errors') as it: @it.has_setup def setup_fail(): raise RuntimeError('Bad Error in such setUp!') @it.should('check that value == 1') def test_passes(case): pass it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/test_such_teardown_fail.py0000664000175000017500000000044312672050004033220 0ustar travistravisfrom nose2.tools import such with such.A('test scenario with errors') as it: @it.has_teardown def teardown_fail(): raise RuntimeError('Bad Error in such tearDown!') @it.should('check that value == 1') def test_passes(case): pass it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_errors/test_such_with_errors.py0000664000175000017500000000102712672050004032750 0ustar travistravisfrom nose2.tools import such with such.A('test scenario with errors') as it: @it.has_setup def set_value(): it.value = 1 @it.should('check that value == 1') def test_passes(case): case.assertEqual(it.value, 1) @it.should('check that value == 2 and fail') def test_fails(case): case.assertEqual(it.value, 2) @it.should('check for an attribute that does not exist and raise an error') def test_err(case): case.assertEqual(it.mulch, 'pine') it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_inheritance/0000775000175000017500000000000012672050226026731 5ustar travistravis././@LongLink0000000000000000000000000000015400000000000011565 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_inheritance/test_layers_with_inheritance.pynose2-0.6.4/nose2/tests/functional/support/scenario/layers_with_inheritance/test_layers_with_inherit0000664000175000017500000000135312672050004033763 0ustar travistravisfrom nose2.compat import unittest class L1(object): @classmethod def setUp(cls): print('L1 setUp') @classmethod def testSetUp(cls): print('L1 testSetUp') @classmethod def tearDown(cls): print('L1 tearDown') @classmethod def testTearDown(cls): print('L1 testTearDown') class L2(L1): @classmethod def setUp(cls): print('L2 setUp') @classmethod def testSetUp(cls): print('L2 testSetUp') @classmethod def testTearDown(cls): print('L2 testTearDown') # L1 tearDown should only run once class T1(unittest.TestCase): layer = L2 def test1(self): print('Run test1') def test2(self): print('Run test2') nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests/0000775000175000017500000000000012672050226024167 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/load_tests/test_filter.py0000664000175000017500000000037612672050004027065 0ustar travistravisimport unittest class TestCase(unittest.TestCase): def test_a(self): pass def test_b(self): pass def test_c(self): pass def load_tests(loader, tests, pattern): del tests._tests[0]._tests[1] return tests nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests/test_simple.py0000664000175000017500000000052712672050004027067 0ustar travistravisimport unittest class TestCase(unittest.TestCase): def test_a(self): pass def test_b(self): pass def test_c(self): pass def load_tests(loader, tests, pattern): class InnerTest(unittest.TestCase): def test_d(self): pass tests.addTest(InnerTest('test_d')) return tests nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/0000775000175000017500000000000012672050226025030 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/0000775000175000017500000000000012672050226026151 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/tests/0000775000175000017500000000000012672050226027313 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/tests/__init__.py0000664000175000017500000000045012672050004031415 0ustar travistravisimport os def load_tests(loader, standard_tests, pattern): # top level directory cached on loader instance this_dir = os.path.dirname(__file__) package_tests = loader.discover(start_dir=this_dir, pattern=pattern) standard_tests.addTests(package_tests) return standard_tests nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/tests/test_find_these.py0000664000175000017500000000012312672050004033022 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/__init__.py0000664000175000017500000000003712672050004030254 0ustar travistravisdef gt(a, b): return a > b nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/0000775000175000017500000000000012672050226026233 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/tests/0000775000175000017500000000000012672050226027375 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/tests/__init__.py0000664000175000017500000000041612672050004031501 0ustar travistravisimport unittest def load_tests(loader, standard_tests, pattern): suite = loader.suiteClass() class Test(unittest.TestCase): def test(self): import ltpkg2 assert ltpkg2.lt(1, 2) suite.addTest(Test('test')) return suite nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/tests/test_skip_these.py0000664000175000017500000000017112672050004033135 0ustar travistravisimport unittest class Test(unittest.TestCase): def test(self): raise Exception("this should not execute") nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/__init__.py0000664000175000017500000000003712672050004030336 0ustar travistravisdef lt(a, b): return a < b nose2-0.6.4/nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg0000664000175000017500000000004512672050004027361 0ustar travistravis[unittest] test-file-pattern = test* nose2-0.6.4/nose2/tests/functional/support/scenario/logging/0000775000175000017500000000000012672050226023454 5ustar travistravis././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/logging/logging_keeps_copies_of_mutable_objects.pynose2-0.6.4/nose2/tests/functional/support/scenario/logging/logging_keeps_copies_of_mutable_objects.0000664000175000017500000000047512672050004033542 0ustar travistravis import nose2 import unittest import logging log = logging.getLogger(__name__) class Test(unittest.TestCase): def test_logging_keeps_copies_of_mutable_objects(self): d = {} log.debug("foo: %s", d) d["bar"] = "baz" self.assert_(False) if __name__ == '__main__': nose2.main()nose2-0.6.4/nose2/tests/functional/support/scenario/many_tests/0000775000175000017500000000000012672050226024214 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/many_tests/test_gen_many_func.py0000664000175000017500000000013112672050004030422 0ustar travistravisdef check(_): pass def test(): for i in range(0, 600): yield check, i nose2-0.6.4/nose2/tests/functional/support/scenario/many_tests_socket/0000775000175000017500000000000012672050226025564 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/many_tests_socket/nose2.cfg0000664000175000017500000000005012672050004027260 0ustar travistravis[multiprocess] bind_address = 127.1.2.3 nose2-0.6.4/nose2/tests/functional/support/scenario/many_tests_socket/test_gen_many_socket_func.py0000664000175000017500000000013112672050004033342 0ustar travistravisdef check(_): pass def test(): for i in range(0, 600): yield check, i nose2-0.6.4/nose2/tests/functional/support/scenario/module_fixtures/0000775000175000017500000000000012672050226025244 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/module_fixtures/test_mf_func.py0000664000175000017500000000026112672050004030263 0ustar travistravisTHINGS = [] def setUpModule(): THINGS.append(1) def tearDownModule(): while THINGS: THINGS.pop() def test(): assert THINGS, "setup didn't run I think" nose2-0.6.4/nose2/tests/functional/support/scenario/module_fixtures/test_mf_gen_func.py0000664000175000017500000000032412672050004031114 0ustar travistravisTHINGS = [] def setUpModule(): THINGS.append(1) def tearDownModule(): while THINGS: THINGS.pop() def check(_): assert THINGS, "setup didn't run I think" def test(): yield check, 1 nose2-0.6.4/nose2/tests/functional/support/scenario/module_fixtures/test_mf_param_func.py0000664000175000017500000000031012672050004031436 0ustar travistravisTHINGS = [] def setUpModule(): THINGS.append(1) def tearDownModule(): while THINGS: THINGS.pop() def test(p): assert THINGS, "setup didn't run I think" test.paramList = (1,) nose2-0.6.4/nose2/tests/functional/support/scenario/module_fixtures/test_mf_testcase.py0000664000175000017500000000045112672050004031144 0ustar travistravisimport unittest THINGS = [] def setUpModule(): THINGS.append(1) def tearDownModule(): while THINGS: THINGS.pop() class Test(unittest.TestCase): def test_1(self): assert THINGS, "setup didn't run" def test_2(self): assert THINGS, "setup didn't run" nose2-0.6.4/nose2/tests/functional/support/scenario/module_import_err/0000775000175000017500000000000012672050226025555 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/module_import_err/test_import_err.py0000664000175000017500000000020512672050004031337 0ustar travistravisimport unittest raise ImportError("booms") def test(): pass class Test(unittest.TestCase): def test(self): pass nose2-0.6.4/nose2/tests/functional/support/scenario/no_tests/0000775000175000017500000000000012672050226023664 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/no_tests/a.py0000664000175000017500000000002712672050004024447 0ustar travistravis"""An empty module.""" nose2-0.6.4/nose2/tests/functional/support/scenario/one_test/0000775000175000017500000000000012672050226023646 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/one_test/tests.py0000664000175000017500000000021412672050004025351 0ustar travistravisimport nose2 import unittest class Test(unittest.TestCase): def test(self): pass if __name__ == '__main__': nose2.main()nose2-0.6.4/nose2/tests/functional/support/scenario/package_in_lib/0000775000175000017500000000000012672050226024735 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/package_in_lib/lib/0000775000175000017500000000000012672050226025503 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/package_in_lib/lib/pkg2/0000775000175000017500000000000012672050226026346 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/package_in_lib/lib/pkg2/__init__.py0000664000175000017500000000016112672050004030447 0ustar travistravisimport logging log = logging.getLogger(__name__) def get_one(): log.debug("Returning %s", 1) return 1 nose2-0.6.4/nose2/tests/functional/support/scenario/package_in_lib/tests.py0000664000175000017500000000062012672050004026441 0ustar travistravisimport logging import unittest from pkg2 import get_one log = logging.getLogger(__name__) log.debug("module imported") def test(): log.debug("test run") assert get_one() == 1 def test_fail(): log.debug("test_fail run") assert get_one() == 2 class Tests(unittest.TestCase): def test_fail2(self): log.debug("test_fail2 run") self.assertEqual(get_one(), 4) nose2-0.6.4/nose2/tests/functional/support/scenario/slow/0000775000175000017500000000000012672050226023012 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/slow/test_slow.py0000664000175000017500000000067112672050004025405 0ustar travistravisimport time import unittest import logging log = logging.getLogger(__name__) class TestSlow(unittest.TestCase): def test_ok(self): print("hide this") time.sleep(2) def test_fail(self): print("show this") log.debug("hola") time.sleep(2) self.assertEqual(1, 2) def test_err(self): print("show this too") log.debug("ciao") time.sleep(2) {}['x'] nose2-0.6.4/nose2/tests/functional/support/scenario/such_with_params/0000775000175000017500000000000012672050226025366 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/such_with_params/such_with_params.py0000664000175000017500000000065512672050004031300 0ustar travistravisfrom nose2.tools import such from nose2.tools.params import params with such.A('foo') as it: @it.should('do bar') @params(1,2,3) def test(case, bar): case.assert_(isinstance(bar, int)) @it.should('do bar and extra') @params((1, 2), (3, 4) ,(5, 6)) def testExtraArg(case, bar, foo): case.assert_(isinstance(bar, int)) case.assert_(isinstance(foo, int)) it.createTests(globals()) nose2-0.6.4/nose2/tests/functional/support/scenario/test_class_fail/0000775000175000017500000000000012672050226025165 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/test_class_fail/test_class_fail.py0000664000175000017500000000040312672050004030665 0ustar travistravis class Test(object): def __init__(self): raise RuntimeError('Something bad happened but other tests should still be run!') def test(self): raise RuntimeError('Something bad happened but other tests should still be run! RUNNING') nose2-0.6.4/nose2/tests/functional/support/scenario/test_classes/0000775000175000017500000000000012672050226024522 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/test_classes/test_classes.py0000664000175000017500000000037612672050004027570 0ustar travistravisclass Test(object): def test(self): pass def test_gen(self): def check(a): pass for i in range(0, 5): yield check, i def test_params(self, a): pass test_params.paramList = (1, 2) nose2-0.6.4/nose2/tests/functional/support/scenario/test_classes/test_fixtures.py0000664000175000017500000000116212672050004027776 0ustar travistravisclass Test(object): @classmethod def setUpClass(cls): cls.setup = 1 @classmethod def tearDownClass(cls): del cls.setup def setUp(self): self.test_setup = 1 def tearDown(self): del self.test_setup def test(self): assert self.test_setup assert self.setup def test_gen(self): def check(a): assert self.test_setup assert self.setup for i in range(0, 2): yield check, i def test_params(self, a): assert self.test_setup assert self.setup test_params.paramList = (1, 2) nose2-0.6.4/nose2/tests/functional/support/scenario/test_with_module/0000775000175000017500000000000012672050226025405 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/test_with_module/lib/0000775000175000017500000000000012672050226026153 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/test_with_module/lib/__init__.py0000664000175000017500000000000012672050004030244 0ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/test_with_module/lib/mod1.py0000664000175000017500000000016612672050004027362 0ustar travistravisdef covered_func(): a = 1 a = a + 8 return a def uncovered_func(): b = 1 b = b + 8 return b nose2-0.6.4/nose2/tests/functional/support/scenario/test_with_module/test_coverage.py0000664000175000017500000000022012672050004030575 0ustar travistravisimport unittest from lib import mod1 class TestLib(unittest.TestCase): def test1(self): self.assertEqual(mod1.covered_func(), 9) nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/0000775000175000017500000000000012672050226025331 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/pkg1/0000775000175000017500000000000012672050226026173 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/0000775000175000017500000000000012672050226027152 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/__init__.py0000664000175000017500000000000212672050004031245 0ustar travistravis# nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py0000664000175000017500000000330312672050004032050 0ustar travistravistry: import unittest2 as unittest except ImportError: import unittest class SomeTests(unittest.TestCase): tags = ['case'] def test_ok(self): pass test_ok.tags = ['method', 'pass'] test_ok.a = 0 test_ok.b = 1 def test_typeerr(self): raise TypeError("oops") test_typeerr.tags = ['method'] def test_failed(self): print("Hello stdout") assert False, "I failed" test_failed.tags = ['method'] def test_skippy(self): raise unittest.SkipTest("I wanted to skip") test_skippy.a = 1 test_skippy.b = 1 def test_gen_method(self): def check(x): assert x == 1 check.b = 2 yield check, 1 yield check, 2 test_gen_method.a = 1 test_gen_method.b = 1 def test_params_method(self, a): self.assertEqual(a, 1) test_params_method.paramList = (1, 2) test_params_method.a = 1 def test_func(): assert 1 == 1 test_func.a = 1 test_func.b = 0 test_func.tags = ['func', 'pass'] def test_gen(): def check(a, b): assert a == b check.tags = ['func'] for i in range(0, 5): yield check, (i, i,) test_gen.testGenerator = True test_gen.tags = ['func'] def test_gen_nose_style(): def check(a, b): assert a == b for i in range(0, 5): yield check, i, i did_setup = False def setup(): global did_setup did_setup = True def test_fixt(): assert did_setup test_fixt.setup = setup def test_params_func(a): assert a == 1 test_params_func.paramList = (1, 2) test_params_func.tags = ['func'] def test_params_func_multi_arg(a, b): assert a == b test_params_func_multi_arg.paramList = ((1, 1), (1, 2), (2, 2)) nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/pkg1/__init__.py0000664000175000017500000000000212672050004030266 0ustar travistravis# nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/pkg1/mod1.py0000664000175000017500000000022112672050004027372 0ustar travistravis def some_other_func(): """This is a function with an inline doctest. >>> a = 1 >>> b = 2 >>> a == b False """ pass nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/docs.rst0000664000175000017500000000002012672050004026775 0ustar travistravis>>> 1 == 1 True nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/docs.txt0000664000175000017500000000004112672050004027007 0ustar travistravis>>> 2 == 2 True >>> 3 == 2 False nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/setup.py0000664000175000017500000000021712672050004027035 0ustar travistravisfrom setuptools import setup, find_packages setup(name='pkg1', packages=find_packages(), test_suite='nose2.collector.collector') nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_package/unittest.cfg0000664000175000017500000000014312672050004027661 0ustar travistravis[outcomes] treat-as-skip = IOError TodoError TypeError treat-as-fail = GlormpError nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/0000775000175000017500000000000012672050226026601 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000775000175000017500000000000012672050226032457 5ustar travistravis././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000775000175000017500000000000012672050226032457 5ustar travistravis././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/SOURCES.txtnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000040112672050004032446 0ustar travistravissetup.py pkgunegg/__init__.py pkgunegg/mod1.py pkgunegg.egg-info/PKG-INFO pkgunegg.egg-info/SOURCES.txt pkgunegg.egg-info/dependency_links.txt pkgunegg.egg-info/top_level.txt pkgunegg.egg-info/zip-safe pkgunegg/test/__init__.py pkgunegg/test/test_things.py ././@LongLink0000000000000000000000000000020200000000000011557 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/dependency_links.txtnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000000112672050004032442 0ustar travistravis ././@LongLink0000000000000000000000000000017300000000000011566 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/top_level.txtnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000001112672050004032443 0ustar travistravispkgunegg ././@LongLink0000000000000000000000000000015600000000000011567 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000775000175000017500000000000012672050226032457 5ustar travistravis././@LongLink0000000000000000000000000000016300000000000011565 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/test/nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000775000175000017500000000000012672050226032457 5ustar travistravis././@LongLink0000000000000000000000000000017600000000000011571 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/test/__init__.pynose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000000212672050004032443 0ustar travistravis# ././@LongLink0000000000000000000000000000020100000000000011556 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/test/test_things.pynose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000330312672050004032452 0ustar travistravistry: import unittest2 as unittest except ImportError: import unittest class SomeTests(unittest.TestCase): tags = ['case'] def test_ok(self): pass test_ok.tags = ['method', 'pass'] test_ok.a = 0 test_ok.b = 1 def test_typeerr(self): raise TypeError("oops") test_typeerr.tags = ['method'] def test_failed(self): print("Hello stdout") assert False, "I failed" test_failed.tags = ['method'] def test_skippy(self): raise unittest.SkipTest("I wanted to skip") test_skippy.a = 1 test_skippy.b = 1 def test_gen_method(self): def check(x): assert x == 1 check.b = 2 yield check, 1 yield check, 2 test_gen_method.a = 1 test_gen_method.b = 1 def test_params_method(self, a): self.assertEqual(a, 1) test_params_method.paramList = (1, 2) test_params_method.a = 1 def test_func(): assert 1 == 1 test_func.a = 1 test_func.b = 0 test_func.tags = ['func', 'pass'] def test_gen(): def check(a, b): assert a == b check.tags = ['func'] for i in range(0, 5): yield check, (i, i,) test_gen.testGenerator = True test_gen.tags = ['func'] def test_gen_nose_style(): def check(a, b): assert a == b for i in range(0, 5): yield check, i, i did_setup = False def setup(): global did_setup did_setup = True def test_fixt(): assert did_setup test_fixt.setup = setup def test_params_func(a): assert a == 1 test_params_func.paramList = (1, 2) test_params_func.tags = ['func'] def test_params_func_multi_arg(a, b): assert a == b test_params_func_multi_arg.paramList = ((1, 1), (1, 2), (2, 2)) ././@LongLink0000000000000000000000000000017100000000000011564 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/__init__.pynose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000000212672050004032443 0ustar travistravis# ././@LongLink0000000000000000000000000000016500000000000011567 Lustar rootrootnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/mod1.pynose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/0000664000175000017500000000022112672050004032446 0ustar travistravis def some_other_func(): """This is a function with an inline doctest. >>> a = 1 >>> b = 2 >>> a == b False """ pass nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/docs.rst0000664000175000017500000000002012672050004030245 0ustar travistravis>>> 1 == 1 True nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/docs.txt0000664000175000017500000000004112672050004030257 0ustar travistravis>>> 2 == 2 True >>> 3 == 2 False nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/setup.py0000664000175000017500000000024412672050004030305 0ustar travistravisfrom setuptools import setup, find_packages setup(name='pkg1', packages=find_packages(), zip_safe=True, test_suite='nose2.collector.collector') nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/unittest.cfg0000664000175000017500000000014312672050004031131 0ustar travistravis[outcomes] treat-as-skip = IOError TodoError TypeError treat-as-fail = GlormpError nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_zipped_eggs/0000775000175000017500000000000012672050226026236 5ustar travistravisnose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_zipped_eggs/docs.rst0000664000175000017500000000002012672050004027702 0ustar travistravis>>> 1 == 1 True nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_zipped_eggs/docs.txt0000664000175000017500000000004112672050004027714 0ustar travistravis>>> 2 == 2 True >>> 3 == 2 False nose2-0.6.4/nose2/tests/functional/support/scenario/tests_in_zipped_eggs/pkgegg-0.0.0-py2.7.egg0000664000175000017500000001225212672050004031470 0ustar travistravisPK VV¶D EGG-INFO/UT ãI}SæI}Sux ˜"õPK VV¶Dpkgegg/UT ãI}SðI}Sux ˜"õPK VV¶D pkgegg/test/UT ãI}SðI}Sux ˜"õPK ¯‹¬D“×2EGG-INFO/dependency_links.txtUT ZxpSþI}Sux ˜"õ PKtV¶DŸÈ-{îEGG-INFO/SOURCES.txtUT J}SuJ}Sux ˜"õ+N-)-Ð+¨ä*ÈNOMO×ÏÌË,‰GÊÍO1Dpõ€X73/-_?ÀÛ]×ÓÏÍC"Ø?4ÈÙ5X¯¤¢C.%µ 5/%5/¹2>'3/»«¢’ü‚øœÔ²Ô¬²U™ºÅ‰i©0÷•¤—`s7XDÄ—dd楥PKwV¶DíPKu´EGG-INFO/PKG-INFOUT "J}S)J}Sux ˜"õóM-ILI,IÔ K-*ÎÌϳR0Ô3àòKÌMµR(ÈNOMOç‚Ëè!WpinnbQ¥•B¨Ÿ·Ÿ¸—G~nªnAbz*Bȱ´$#¿¯›š›˜™ƒõÉLNÍ+FÒæ’Zœ\”YP¶ &“X’–_”‹PK ¯‹¬D“×2EGG-INFO/zip-safeUT ZxpSýI}Sux ˜"õ PK zV¶D{•,³EGG-INFO/top_level.txtUT (J}SuJ}Sux ˜"õpkgegg PK¯‹¬DÝ7åÖd„pkgegg/__init__.pycUT ZxpSuJ}Sux ˜"õcþÌËå£\œÌŒ@ìÄÅ,@"…!X$â§’C#ŠuDRifNŠ~RJfq‰^Nf^i…n……Y¼™‰~jzº~Avº¡~||f^fI|¼^Ae P‡Mn~JiNªÈÜb9PK R[¬D€Œ¥pkgegg/__init__.pyUT L#pSþI}Sux ˜"õ# PK¯‹¬DMÑ™5Õypkgegg/mod1.pycUT ZxpSuJ}Sux ˜"õ¥O½ Â0Ž?ƒНpàR-)ZÁI¬“Ki›ØkRLŠºûƾ€—"R]=r÷å¾ûëì›"ÊZò{Hù†å…_“hbü ûů€ »1v“¨ª˜Éè,¼›tNb–’Ì#­0¢¶©‘ D¢ÚGò(ûùg'$'Û¬>»oÒ:bâ[Rø.2ªdlºG]Sòž¸Ó6ŽiL÷EÓþ^À´¯‹ß%¯&¡¡q ,Ó1‘§câ¹§žþȦš·ñ¤ H ]ºæŒü)ƒI§Ùqq™Ì6lБûŸ/Ø Žºìá`:L² ¶¹‰¢Ñ ën ÿÃÏ?¨ö¢=·¬ ‹®kIRx·½žœ•> #6ÊJ*ƒÃôÐåÕ-}*ùPãI}§ÂÝó>"¹< ìѽÃüaô ¬¨;åd!Ì9ø|Øï×Ì…x%ÛMÖ+¢ïÎ7ì7PK¯‹¬D8ϲ pkgegg/test/test_things.pycUT ZxpSuJ}Sux ˜"õÍWÝoÜDŸµïË—»Þ僔´%pB´¨©x@å#-M¤’_ÔHÈrn÷.N|öÕ»')¼Pþ&þ1^xƒ™±}¾Kò€èEÅ“ÝY{v~¿™ÙÙØ4ëÏ=È~Êø|‹þÅY$€xÝ’²à¤É&!²EA‹‘€—Ò%àØ†¾iÃoo^”@–hrPYU¯²Âƒ*Hü­ÁÀâi ¤Ão: ê ðè…à1®Öyµª þ ½wúÕCïáƒM5lŽN_l¤…gŽ‚h ïÎL•,’*ƬBKD,SA9Tæ(–¼ÝÈ×: •€<˜øjå¾¶É '㿊ÔoZÝãÏãx¤Sß)šûg#õ$Iâ„U®•£x[(ŠÁ T’´ <—=¾ ìîÓt[ß#(ÜSÎÛä¼&“;* ãumd<6º†ŠÝõ¾„J2@Cûƒjenàè;­Ub‚8º€ 9Àtÿ•= 3.5, the test name contains the fully qualified class # name, so the regexp has an optional matching part. self.assertTestRunOutputMatches( proc, stderr='test..ltpkg2.tests(.load_tests.)?.Test') def test_project_directory_inside_package(self): proc = self.runIn( 'scenario/load_tests_pkg/ltpkg/tests', '-v', '-c=' 'nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg', '--plugin=nose2.plugins.loader.loadtests') self.assertTestRunOutputMatches(proc, stderr='Ran 1 test') self.assertTestRunOutputMatches( proc, stderr='test..ltpkg.tests.test_find_these.Test') nose2-0.6.4/nose2/tests/functional/test_logcapture_plugin.py0000664000175000017500000000143212672050004023635 0ustar travistravisimport re from nose2.tests._common import FunctionalTestCase class LogCaptureFunctionalTest(FunctionalTestCase): def test_package_in_lib(self): match = re.compile('>> begin captured logging <<') self.assertTestRunOutputMatches( self.runIn('scenario/package_in_lib', '--log-capture'), stderr=match) def test_logging_keeps_copies_of_mutable_objects(self): proc = self.runIn('scenario/logging', '-v', '--log-capture', 'logging_keeps_copies_of_mutable_objects') self.assertTestRunOutputMatches(proc, stderr='Ran 1 test in') self.assertTestRunOutputMatches(proc, stderr='FAILED') self.assertTestRunOutputMatches(proc, stderr='foo: {}') nose2-0.6.4/nose2/tests/functional/test_main.py0000664000175000017500000000170012672050004021034 0ustar travistravisfrom nose2.tests._common import FunctionalTestCase class TestPluggableTestProgram(FunctionalTestCase): def test_run_in_empty_dir_succeeds(self): proc = self.runIn('scenario/no_tests') stdout, stderr = proc.communicate() self.assertEqual(proc.poll(), 0, stderr) def test_extra_hooks(self): class Check(object): ran = False def startTestRun(self, event): self.ran = True check = Check() proc = self.runIn('scenario/no_tests', extraHooks=[('startTestRun', check)]) stdout, stderr = proc.communicate() self.assertEqual(proc.poll(), 0, stderr) assert check.ran, "Extra hook did not execute" def test_run_in_module_from_its_main(self): proc = self.runModuleAsMain('scenario/one_test/tests.py') self.assertTestRunOutputMatches(proc, stderr='Ran 1 test') self.assertEqual(proc.poll(), 0)nose2-0.6.4/nose2/tests/functional/test_mp_plugin.py0000664000175000017500000002211212672050004022102 0ustar travistravisimport sys from nose2 import session from nose2.compat import unittest from nose2.plugins.mp import MultiProcess, procserver from nose2.plugins import buffer from nose2.plugins.loader import discovery, testcases from nose2.tests._common import FunctionalTestCase, support_file, Conn from six.moves import queue import multiprocessing import threading import time from multiprocessing import connection class TestMpPlugin(FunctionalTestCase): def setUp(self): super(TestMpPlugin, self).setUp() self.session = session.Session() self.plugin = MultiProcess(session=self.session) def test_flatten_without_fixtures(self): sys.path.append(support_file('scenario/slow')) import test_slow as mod suite = unittest.TestSuite() suite.addTest(mod.TestSlow('test_ok')) suite.addTest(mod.TestSlow('test_fail')) suite.addTest(mod.TestSlow('test_err')) flat = list(self.plugin._flatten(suite)) self.assertEqual(len(flat), 3) def test_flatten_nested_suites(self): sys.path.append(support_file('scenario/slow')) import test_slow as mod suite = unittest.TestSuite() suite.addTest(mod.TestSlow('test_ok')) suite.addTest(mod.TestSlow('test_fail')) suite.addTest(mod.TestSlow('test_err')) suite2 = unittest.TestSuite() suite2.addTest(suite) flat = list(self.plugin._flatten(suite2)) self.assertEqual(len(flat), 3) def test_flatten_respects_module_fixtures(self): sys.path.append(support_file('scenario/module_fixtures')) import test_mf_testcase as mod suite = unittest.TestSuite() suite.addTest(mod.Test('test_1')) suite.addTest(mod.Test('test_2')) flat = list(self.plugin._flatten(suite)) self.assertEqual(flat, ['test_mf_testcase']) def test_flatten_respects_class_fixtures(self): sys.path.append(support_file('scenario/class_fixtures')) import test_cf_testcase as mod suite = unittest.TestSuite() suite.addTest(mod.Test('test_1')) suite.addTest(mod.Test('test_2')) suite.addTest(mod.Test2('test_1')) suite.addTest(mod.Test2('test_2')) suite.addTest(mod.Test3('test_3')) flat = list(self.plugin._flatten(suite)) self.assertEqual(flat, ['test_cf_testcase.Test2.test_1', 'test_cf_testcase.Test2.test_2', 'test_cf_testcase.Test', 'test_cf_testcase.Test3', ]) def test_conn_prep(self): self.plugin.bind_host = None (parent_conn, child_conn) = self.plugin._prepConns() (parent_pipe, child_pipe) = multiprocessing.Pipe() self.assertIsInstance(parent_conn, type(parent_pipe)) self.assertIsInstance(child_conn, type(child_pipe)) self.plugin.bind_host = "127.0.0.1" self.plugin.bind_port = 0 (parent_conn, child_conn) = self.plugin._prepConns() self.assertIsInstance(parent_conn, connection.Listener) self.assertIsInstance(child_conn, tuple) self.assertEqual(parent_conn.address, child_conn[:2]) def test_conn_accept(self): (parent_conn, child_conn) = multiprocessing.Pipe() self.assertEqual(self.plugin._acceptConns(parent_conn), parent_conn) listener = connection.Listener(('127.0.0.1', 0)) with self.assertRaises(RuntimeError): self.plugin._acceptConns(listener) def fake_client(address): client = connection.Client(address) time.sleep(10) client.close() t = threading.Thread(target=fake_client, args=(listener.address,)) t.start() conn = self.plugin._acceptConns(listener) self.assertTrue(hasattr(conn, "send")) self.assertTrue(hasattr(conn, "recv")) class TestProcserver(FunctionalTestCase): def setUp(self): super(TestProcserver, self).setUp() self.session = session.Session() def test_dispatch_tests_receive_events(self): ssn = { 'config': self.session.config, 'verbosity': 1, 'startDir': support_file('scenario/tests_in_package'), 'topLevelDir': support_file('scenario/tests_in_package'), 'logLevel': 100, 'pluginClasses': [discovery.DiscoveryLoader, testcases.TestCaseLoader, buffer.OutputBufferPlugin] } conn = Conn(['pkg1.test.test_things.SomeTests.test_ok', 'pkg1.test.test_things.SomeTests.test_failed']) procserver(ssn, conn) # check conn calls expect = [('pkg1.test.test_things.SomeTests.test_ok', [('startTest', {}), ('setTestOutcome', {'outcome': 'passed'}), ('testOutcome', {'outcome': 'passed'}), ('stopTest', {})] ), ('pkg1.test.test_things.SomeTests.test_failed', [('startTest', {}), ('setTestOutcome', { 'outcome': 'failed', 'expected': False, 'metadata': {'stdout': 'Hello stdout\n'}}), ('testOutcome', { 'outcome': 'failed', 'expected': False, 'metadata': {'stdout': 'Hello stdout\n'}}), ('stopTest', {})] ), ] for val in conn.sent: if val is None: break test, events = val exp_test, exp_events = expect.pop(0) self.assertEqual(test, exp_test) for method, event in events: exp_meth, exp_attr = exp_events.pop(0) self.assertEqual(method, exp_meth) for attr, val in exp_attr.items(): self.assertEqual(getattr(event, attr), val) class MPPluginTestRuns(FunctionalTestCase): def test_tests_in_package(self): proc = self.runIn( 'scenario/tests_in_package', '-v', '--plugin=nose2.plugins.mp', '-N=2') self.assertTestRunOutputMatches(proc, stderr='Ran 25 tests') self.assertEqual(proc.poll(), 1) def test_package_in_lib(self): proc = self.runIn( 'scenario/package_in_lib', '-v', '--plugin=nose2.plugins.mp', '-N=2') self.assertTestRunOutputMatches(proc, stderr='Ran 3 tests') self.assertEqual(proc.poll(), 1) def test_module_fixtures(self): proc = self.runIn( 'scenario/module_fixtures', '-v', '--plugin=nose2.plugins.mp', '-N=2') self.assertTestRunOutputMatches(proc, stderr='Ran 5 tests') self.assertEqual(proc.poll(), 0) def test_class_fixtures(self): proc = self.runIn( 'scenario/class_fixtures', '-v', '--plugin=nose2.plugins.mp', '-N=2') self.assertTestRunOutputMatches(proc, stderr='Ran 7 tests') self.assertEqual(proc.poll(), 0) def test_large_number_of_tests_stresstest(self): proc = self.runIn( 'scenario/many_tests', '-v', '--plugin=nose2.plugins.mp', '--plugin=nose2.plugins.loader.generators', '-N=1') self.assertTestRunOutputMatches(proc, stderr='Ran 600 tests') self.assertEqual(proc.poll(), 0) def test_socket_stresstest(self): proc = self.runIn( 'scenario/many_tests_socket', '-v', '-c scenario/many_test_socket/nose2.cfg', '--plugin=nose2.plugins.mp', '--plugin=nose2.plugins.loader.generators', '-N=1') self.assertTestRunOutputMatches(proc, stderr='Ran 600 tests') self.assertEqual(proc.poll(), 0) def test_too_many_procs(self): # Just need to run the mp plugin with less tests than # processes. proc = self.runModuleAsMain('scenario/one_test/tests.py', '--log-level=debug', '--plugin=nose2.plugins.mp', '-N=2') ret_vals = queue.Queue() def save_return(): """ Popen.communciate() blocks. Use a thread-safe queue to return any exceptions. Ideally, this completes and returns None. """ try: self.assertTestRunOutputMatches(proc, stderr='Ran 1 test') self.assertEqual(proc.poll(), 0) ret_vals.put(None) except Exception as exc: ret_vals.put(exc) thread = threading.Thread(target=save_return) thread.start() # 1 minute should be more than sufficent for this # little test case. try: exc = ret_vals.get(True, 60) except queue.Empty: exc = "MP Test timed out" proc.kill() self.assertIsNone(exc, str(exc)) nose2-0.6.4/nose2/tests/functional/test_printhooks_plugin.py0000664000175000017500000000244212672050004023672 0ustar travistravisimport re from nose2.tests._common import FunctionalTestCase class TestPrintHooksPlugin(FunctionalTestCase): def test_invocation_by_double_dash_option(self): proc = self.runIn( 'scenario/no_tests', '--plugin=nose2.plugins.printhooks', '--print-hooks') match = re.compile("\n" "handleArgs: " "CommandLineArgsEvent\(handled=False, args=") self.assertTestRunOutputMatches(proc, stderr=match) self.assertEqual(proc.poll(), 0) def test_invocation_by_single_dash_option(self): proc = self.runIn( 'scenario/no_tests', '--plugin=nose2.plugins.printhooks', '-P') match = re.compile("\n" "handleArgs: " "CommandLineArgsEvent\(handled=False, args=") self.assertTestRunOutputMatches(proc, stderr=match) self.assertEqual(proc.poll(), 0) def test_nested_hooks_are_indented(self): proc = self.runIn( 'scenario/no_tests', '--plugin=nose2.plugins.printhooks', '--print-hooks') match = re.compile("\n handleFile: ") self.assertTestRunOutputMatches(proc, stderr=match) self.assertEqual(proc.poll(), 0) nose2-0.6.4/nose2/tests/functional/test_session.py0000664000175000017500000000147212672050004021601 0ustar travistravisimport sys from nose2 import session from nose2.tests._common import support_file, FunctionalTestCase class SessionFunctionalTests(FunctionalTestCase): def setUp(self): self.s = session.Session() self.s.loadConfigFiles(support_file('cfg', 'a.cfg'), support_file('cfg', 'b.cfg')) sys.path.insert(0, support_file('lib')) def test_session_can_load_config_files(self): assert self.s.config.has_section('a') assert self.s.config.has_section('b') def test_session_holds_plugin_config(self): plug_config = self.s.get('a') assert plug_config def test_session_can_load_plugins_from_modules(self): self.s.loadPlugins() assert self.s.plugins plug = self.s.plugins[0] self.assertEqual(plug.a, 1) nose2-0.6.4/nose2/tests/functional/test_such_dsl.py0000664000175000017500000001167412672050004021727 0ustar travistravisfrom nose2.tests._common import FunctionalTestCase from nose2.tools import such class TestSuchDSL(FunctionalTestCase): def test_runs_example(self): proc = self.runIn( 'such', '-v', '--plugin=nose2.plugins.layers', 'test_such') self.assertTestRunOutputMatches(proc, stderr='Ran 9 tests') self.assertEqual(proc.poll(), 0, proc.stderr.getvalue()) def test_load_top_level_by_name(self): proc = self.runIn( 'such', '-v', '--plugin=nose2.plugins.layers', 'test_such.A system with complex setup.should do something') self.assertTestRunOutputMatches(proc, stderr='Ran 1 test') self.assertEqual(proc.poll(), 0, proc.stderr.getvalue()) def test_load_sublayer_test_by_name(self): proc = self.runIn( 'such', '-v', '--plugin=nose2.plugins.layers', 'test_such.having an expensive fixture.' 'should do more things') self.assertTestRunOutputMatches(proc, stderr='Ran 1 test') self.assertEqual(proc.poll(), 0, proc.stderr.getvalue()) def test_regression_tests_with_the_same_having_description_under_different_fixtures_in_the_same_module_should_be_run( self): proc = self.runIn( 'such', '-v', '--plugin=nose2.plugins.layers', 'test_regression_same_havings') self.assertTestRunOutputMatches(proc, stderr='Ran 2 test') self.assertEqual(proc.poll(), 0, proc.stderr.getvalue()) def test_teardown_fail(self): proc = self.runIn('scenario/layers_with_errors', '--plugin=nose2.plugins.layers', '-v', 'test_such_teardown_fail') self.assertTestRunOutputMatches(proc, stderr='Ran 1 test in') self.assertTestRunOutputMatches(proc, stderr='ERROR: LayerSuite') self.assertTestRunOutputMatches(proc, stderr=r'FAILED \(errors=1\)') self.assertTestRunOutputMatches(proc, stderr='Bad Error in such tearDown') def test_setup_fail(self): proc = self.runIn('scenario/layers_with_errors', '--plugin=nose2.plugins.layers', '-v', 'test_such_setup_fail') self.assertTestRunOutputMatches(proc, stderr='Ran 0 tests in') self.assertTestRunOutputMatches(proc, stderr='ERROR: LayerSuite') self.assertTestRunOutputMatches(proc, stderr=r'FAILED \(errors=1\)') self.assertTestRunOutputMatches(proc, stderr='Bad Error in such setUp!') def test_param_plugin_with_such(self): proc = self.runIn('scenario/such_with_params', '--plugin=nose2.plugins.layers', '-v', 'such_with_params') self.assertTestRunOutputMatches(proc, stderr='Ran 6 tests in') self.assertTestRunOutputMatches(proc, stderr='OK') self.assertTestRunOutputMatches(proc, stderr='test 0000: should do bar:3') self.assertTestRunOutputMatches(proc, stderr='test 0001: should do bar and extra:3') def test_such_without_layers_plugin(self): proc = self.runIn('such', '-v', 'test_such_without_layers') self.assertTestRunOutputMatches(proc, stderr=r'FAILED') self.assertTestRunOutputMatches(proc, stderr=such.LAYERS_PLUGIN_NOT_LOADED_MESSAGE) def test_testsetup_on_higher_layer_with_test(self): proc = self.runIn('scenario/layers_setups', '--plugin=nose2.plugins.layers', '-v', 'higher_layer_testsetup_with_test') self.assertTestRunOutputMatches(proc, stderr='Ran 3 tests in') self.assertTestRunOutputMatches(proc, stderr='OK') def test_testsetup_on_higher_layer(self): proc = self.runIn('scenario/layers_setups', '--plugin=nose2.plugins.layers', '-v', 'higher_layer_testsetup_no_test') self.assertTestRunOutputMatches(proc, stderr='Ran 2 tests in') self.assertTestRunOutputMatches(proc, stderr='OK') def test_testsetup_on_higher_layer_3layers(self): proc = self.runIn('scenario/layers_setups', '--plugin=nose2.plugins.layers', '-v', 'higher_layer_testsetup_3layers') self.assertTestRunOutputMatches(proc, stderr='Ran 2 tests in') self.assertTestRunOutputMatches(proc, stderr='OK') def test_setup_on_higher_layer(self): proc = self.runIn('scenario/layers_setups', '--plugin=nose2.plugins.layers', '-v', 'higher_layer_setup') self.assertTestRunOutputMatches(proc, stderr='Ran 2 tests in') self.assertTestRunOutputMatches(proc, stderr='OK') nose2-0.6.4/nose2/tests/functional/test_util.py0000664000175000017500000000067112672050004021073 0ustar travistravisfrom nose2.tests._common import TestCase, support_file from nose2 import util class UtilTests(TestCase): def test_name_from_path(self): test_module = support_file('scenario/tests_in_package/pkg1/test/test_things.py') test_package_path = support_file('scenario/tests_in_package') self.assertEqual( util.name_from_path(test_module), ('pkg1.test.test_things', test_package_path) ) nose2-0.6.4/nose2/tests/unit/0000775000175000017500000000000012672050226015324 5ustar travistravisnose2-0.6.4/nose2/tests/unit/__init__.py0000664000175000017500000000000012672050004017415 0ustar travistravisnose2-0.6.4/nose2/tests/unit/test_attrib_plugin.py0000664000175000017500000000467612672050004021607 0ustar travistravisimport unittest from nose2.plugins import attrib from nose2 import events, session from nose2.tests._common import TestCase class TestAttribPlugin(TestCase): tags = ['unit'] def setUp(self): class TC_1(TestCase): tags = ['a', 'b'] def test_a(self): pass test_a.a = 1 test_a.c = 0 def test_b(self): pass test_b.b = 1 self.TC_1 = TC_1 self.session = session.Session() self.plugin = attrib.AttributeSelector(session=self.session) self.plugin.register() def test_validate_attribs_with_simple_values(self): assert self.plugin.validateAttrib( self.TC_1('test_a'), [[('a', '1')]]) assert self.plugin.validateAttrib( self.TC_1('test_a'), [[('a', True)]]) assert self.plugin.validateAttrib( self.TC_1('test_a'), [[('c', False)]]) assert self.plugin.validateAttrib( self.TC_1('test_b'), [[('b', '1')]]) assert not self.plugin.validateAttrib( self.TC_1('test_a'), [[('a', False)]]) assert not self.plugin.validateAttrib( self.TC_1('test_a'), [[('c', True)]]) assert not self.plugin.validateAttrib( self.TC_1('test_a'), [[('a', '2')]]) assert not self.plugin.validateAttrib( self.TC_1('test_a'), [[('b', '1')]]) def test_validate_attribs_with_callable(self): assert self.plugin.validateAttrib( self.TC_1('test_a'), [[('a', lambda key, test: True)]]) assert not self.plugin.validateAttrib( self.TC_1('test_a'), [[('a', lambda key, test: False)]]) def test_validate_attribs_against_list(self): assert self.plugin.validateAttrib( self.TC_1('test_a'), [[('tags', 'a')]]) assert self.plugin.validateAttrib( self.TC_1('test_a'), [[('tags', 'b')]]) assert not self.plugin.validateAttrib( self.TC_1('test_a'), [[('tags', 'c')]]) def test_module_loaded_suite_filters_suite(self): self.plugin.attribs = ['a'] suite = unittest.TestSuite() suite.addTest(self.TC_1('test_a')) suite.addTest(self.TC_1('test_b')) event = events.ModuleSuiteEvent(None, None, suite) self.session.hooks.moduleLoadedSuite(event) self.assertEqual(len(event.suite._tests), 1) self.assertEqual(event.suite._tests[0]._testMethodName, 'test_a') nose2-0.6.4/nose2/tests/unit/test_buffer_plugin.py0000664000175000017500000000402112672050004021553 0ustar travistravisimport sys import six from nose2.plugins import buffer from nose2 import events, result, session from nose2.tests._common import TestCase class TestBufferPlugin(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.result = result.PluggableTestResult(self.session) self.plugin = buffer.OutputBufferPlugin(session=self.session) self.plugin.register() class Test(TestCase): def test_out(self): six.print_("hello") raise {}["oops"] def test_err(self): six.print_("goodbye", file=sys.stderr) self.case = Test class Watcher(events.Plugin): def __init__(self): self.events = [] def testOutcome(self, event): self.events.append(event) self.watcher = Watcher(session=self.session) self.watcher.register() def test_captures_stdout(self): out = sys.stdout buf = six.StringIO() sys.stdout = buf try: test = self.case('test_out') test(self.result) assert "hello" not in buf.getvalue() assert "hello" in self.watcher.events[ 0].metadata['stdout'].getvalue() finally: sys.stdout = out def test_captures_stderr_when_configured(self): self.plugin.captureStderr = True err = sys.stderr buf = six.StringIO() sys.stderr = buf try: test = self.case('test_err') test(self.result) assert "goodbye" not in buf.getvalue() assert "goodbye" in self.watcher.events[ 0].metadata['stderr'].getvalue() finally: sys.stderr = err def test_decorates_outcome_detail(self): test = self.case('test_out') test(self.result) evt = events.OutcomeDetailEvent(self.watcher.events[0]) self.session.hooks.outcomeDetail(evt) assert "hello" in "".join(evt.extraDetail) nose2-0.6.4/nose2/tests/unit/test_collect_plugin.py0000664000175000017500000000077512672050004021743 0ustar travistravisfrom nose2.tests._common import FakeStartTestRunEvent, TestCase from nose2.plugins import collect from nose2 import session class TestCollectOnly(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.plugin = collect.CollectOnly(session=self.session) def test_startTestRun_sets_executeTests(self): event = FakeStartTestRunEvent() self.plugin.startTestRun(event) self.assertEqual(event.executeTests, self.plugin.collectTests) nose2-0.6.4/nose2/tests/unit/test_collector.py0000664000175000017500000000275512672050004020726 0ustar travistravistry: from unittest import mock except ImportError: # Older python versions dont have mock by default import mock from nose2.tests._common import TestCase, RedirectStdStreams from nose2 import collector from textwrap import dedent import re class TestCollector(TestCase): _RUN_IN_TEMP = True tags = ['unit'] def test_collector_completes_with_no_tests(self): with open("unittest.cfg", "w") as ut_file: ut_file.write(dedent(""" [unittest] quiet = true """)) test = collector.collector() with RedirectStdStreams() as redir: self.assertRaises(SystemExit, test.run, None) self.assertEqual("", redir.stdout.getvalue()) self.assertTrue(re.match(r'\n-+\nRan 0 tests in \d.\d\d\ds\n\nOK\n', redir.stderr.getvalue())) def test_collector_sets_testLoader_in_session(self): """ session.testLoader needs to be set so that plugins that use this field (like Layers) dont break. """ test = collector.collector() mock_session = mock.MagicMock() mock_loader = mock.MagicMock() mock_runner = mock.MagicMock() test._get_objects = mock.Mock(return_value=(mock_session, mock_loader, mock_runner)) test._collector(None) self.assertTrue(mock_session.testLoader is mock_loader) nose2-0.6.4/nose2/tests/unit/test_config.py0000664000175000017500000000171212672050004020175 0ustar travistravisfrom nose2 import config from nose2.compat import unittest class TestConfig(unittest.TestCase): def setUp(self): self.conf = config.Config([ ('a', ' 1 '), ('b', ' x\n y '), ('c', '0'), ('d', '123')]) def test_as_int(self): self.assertEqual(self.conf.as_int('a'), 1) def test_as_str(self): self.assertEqual(self.conf.as_str('a'), '1') self.assertEqual(self.conf.as_str('b'), 'x\n y') self.assertEqual(self.conf.as_str('missing', 'default'), 'default') def test_as_bool(self): self.assertEqual(self.conf.as_bool('a'), True) self.assertEqual(self.conf.as_bool('c'), False) def test_as_float(self): self.assertAlmostEqual(self.conf.as_float('a'), 1.0) def test_as_list(self): self.assertEqual(self.conf.as_list('b'), ['x', 'y']) self.assertEqual(self.conf.as_list('a'), ['1']) self.assertEqual(self.conf.as_list('d'), ['123']) nose2-0.6.4/nose2/tests/unit/test_debugger_plugin.py0000664000175000017500000000463712672050004022103 0ustar travistravisimport logging from nose2.tests._common import TestCase from nose2.plugins import debugger from nose2 import events, result, session class NullHandler(logging.Handler): def emit(self, record): pass class StubPdb(object): def __init__(self): self.called = False self.tb = None def post_mortem(self, tb): self.called = True self.tb = tb class NoInteraction(events.Plugin): def beforeInteraction(self, event): event.handled = True return False class TestDebugger(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.plugin = debugger.Debugger(session=self.session) self.result = result.PluggableTestResult(self.session) class Test(TestCase): def test(self): pass def test_err(self): raise Exception("oops") def test_fail(self): assert False self.case = Test self.pdb = self.plugin.pdb self.plugin.pdb = StubPdb() self.plugin.register() super(TestCase, self).setUp() def tearDown(self): self.plugin.pdb = self.pdb super(TestCase, self).tearDown() def test_does_not_call_pdb_on_success(self): test = self.case('test') test(self.result) assert not self.plugin.pdb.called, "pdb was called on success" def test_does_call_pdb_on_error(self): test = self.case('test_err') test(self.result) assert self.plugin.pdb.called, "pdb was not called on error" def test_does_call_pdb_on_failure(self): test = self.case('test_fail') test(self.result) assert self.plugin.pdb.called, "pdb was not called on failure" def test_does_not_call_pdb_on_failure_if_config_set(self): self.plugin.errorsOnly = True test = self.case('test_fail') test(self.result) assert not self.plugin.pdb.called, \ "pdb was called on failure when errorsOnly set" def test_other_plugins_can_prevent_interaction(self): # prevent 'no logger for x' warnings debugger.log.addHandler(NullHandler()) nono = NoInteraction(session=self.session) nono.register() test = self.case('test_err') test(self.result) assert not self.plugin.pdb.called, \ "pdb was called despite beforeInteraction returning False" nose2-0.6.4/nose2/tests/unit/test_decorators.py0000664000175000017500000000145612672050004021102 0ustar travistravis""" Unit tests for nose2 decorators. """ from nose2.tests._common import TestCase from nose2.tools.decorators import with_setup, with_teardown class WithSetupDecoratorTests(TestCase): def fake_setup(self): pass class fake_test(object): setup = None def test_setup_injection(self): sut = self.fake_test() expected = with_setup(self.fake_setup)(sut).setup self.assertEquals(expected, self.fake_setup) class WithTeardownDecoratorTests(TestCase): def fake_teardown(self): pass class fake_test(object): teardown = None def test_teardown_injection(self): sut = self.fake_test() expected = with_teardown(self.fake_teardown)(sut).tearDownFunc self.assertEquals(expected, self.fake_teardown) nose2-0.6.4/nose2/tests/unit/test_doctest_plugin.py0000664000175000017500000000443312672050004021756 0ustar travistravis"""Test doctests plugin.""" import sys import doctest from nose2 import events, loader, session from nose2.plugins import doctests from nose2.tests._common import TestCase class UnitTestDocTestLoader(TestCase): """Test class DocTestLoader.""" tags = ['unit'] _RUN_IN_TEMP = True def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(self.session) self.plugin = doctests.DocTestLoader(session=self.session) super(UnitTestDocTestLoader, self).setUp() def test___init__(self): """Test the __init__ method.""" self.assertEqual(self.plugin.extensions, ['.txt', '.rst']) def test_handle_file(self): """Test method handleFile.""" # Create doctest files of supported types doc_test = """\ >>> 2 == 2 True """ txt_event = self._handle_file('docs.txt', doc_test) rst_event = self._handle_file('docs.rst', doc_test) # Excercise loading of doctests from Python code py_event = self._handle_file('docs.py', """\ \"\"\" >>> 2 == 2 True \"\"\" """) for event, ext in [(txt_event, 'txt'), (rst_event, 'rst')]: test, = event.extraTests self.assertTrue(isinstance(test, doctest.DocFileCase)) self.assertEqual(repr(test), "docs.%s" % ext) testsuite, = py_event.extraTests test, = list(testsuite) self.assertEqual(repr(test), 'docs ()') def test_handle_file_python_without_doctests(self): """Test calling handleFile for a Python module without doctests.""" event = self._handle_file("mod.py", """\ def func(): pass """) if sys.version_info >= (3, 5): self.assertEqual(event.extraTests, [doctest.DocTestSuite()]) else: self.assertEqual(event.extraTests, []) def _handle_file(self, fpath, content): """Have plugin handle a file with certain content. The file is created, then a plugin is instantiated and its handleFile method is called for the file. """ fh = open(fpath, "w") try: fh.write(content) finally: fh.close() event = events.HandleFileEvent(self.loader, fh.name, fpath, None, None) self.plugin.handleFile(event) return event nose2-0.6.4/nose2/tests/unit/test_dundertest_plugin.py0000664000175000017500000000175412672050004022475 0ustar travistravisimport unittest from nose2 import session from nose2.plugins import dundertest from nose2.tests._common import TestCase class TestDunderTestPlugin(TestCase): tags = ['unit'] def setUp(self): class DummyCase(TestCase): def test_a(self): pass self.suite = unittest.TestSuite() self.caseClass = DummyCase self.session = session.Session() self.plugin = dundertest.DunderTestFilter(session=self.session) self.plugin.register() def test_undefined_dunder_test_attribute_keeps_test(self): self.suite.addTest(self.caseClass('test_a')) self.plugin.removeNonTests(self.suite) self.assertEqual(len(list(self.suite)), 1) def test_false_dunder_test_attribute_removes_test(self): dummyTest = self.caseClass('test_a') dummyTest.__test__ = False self.suite.addTest(dummyTest) self.plugin.removeNonTests(self.suite) self.assertEqual(len(list(self.suite)), 0) nose2-0.6.4/nose2/tests/unit/test_failfast.py0000664000175000017500000000322112672050004020516 0ustar travistravisfrom nose2.tests._common import TestCase from nose2.plugins import failfast from nose2 import result, session from nose2.compat import unittest class TestFailFast(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.result = result.PluggableTestResult(self.session) self.plugin = failfast.FailFast(session=self.session) self.plugin.register() class Test(TestCase): def test(self): pass def test_err(self): raise Exception("oops") def test_fail(self): assert False @unittest.expectedFailure def test_fail_expected(self): assert False @unittest.skipIf(True, "Always skip") def test_skip(self): pass self.case = Test def test_sets_shouldstop_on_unexpected_error(self): test = self.case('test_err') test(self.result) assert self.result.shouldStop def test_sets_shouldstop_on_unexpected_fail(self): test = self.case('test_fail') test(self.result) assert self.result.shouldStop def test_does_not_set_shouldstop_on_expected_fail(self): test = self.case('test_fail_expected') test(self.result) assert not self.result.shouldStop def test_does_not_set_shouldstop_on_success(self): test = self.case('test') test(self.result) assert not self.result.shouldStop def test_does_not_set_shouldstop_on_skip(self): test = self.case('test_skip') test(self.result) assert not self.result.shouldStop nose2-0.6.4/nose2/tests/unit/test_functions_loader.py0000664000175000017500000000271212672050004022267 0ustar travistravisfrom nose2.compat import unittest from nose2 import events, loader, session from nose2.plugins.loader import functions from nose2.tests._common import TestCase class TestFunctionLoader(TestCase): def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(self.session) self.plugin = functions.Functions(session=self.session) def test_can_load_test_functions_from_module(self): class Mod(object): pass def test(): pass m = Mod() m.test = test event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 1) assert isinstance(event.extraTests[0], unittest.FunctionTestCase) def test_ignores_generator_functions(self): class Mod(object): pass def test(): yield m = Mod() m.test = test event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 0) def test_ignores_functions_that_take_args(self): class Mod(object): pass def test(a): pass m = Mod() m.test = test event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 0) nose2-0.6.4/nose2/tests/unit/test_generators_plugin.py0000664000175000017500000000533112672050004022460 0ustar travistravisfrom nose2 import events, loader, session, util from nose2.plugins.loader import generators, testcases from nose2.tests._common import TestCase class TestGeneratorUnpack(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(self.session) self.expect = [(0, ('call', (0, 1))), (1, ('call', (1, 2))), (2, ('call', (2, 3))), ] self.plugin = generators.Generators(session=self.session) # need testcase loader to make the initial response to load from module self.tcl = testcases.TestCaseLoader(session=self.session) def test_unpack_handles_nose_style_generators(self): def gen(): for i in range(0, 3): yield 'call', i, i + 1 out = list(self.plugin.unpack(gen())) self.assertEqual(out, self.expect) def test_unpack_handles_unittest2_style_generators(self): def gen(): for i in range(0, 3): yield 'call', (i, i + 1) out = list(self.plugin.unpack(gen())) self.assertEqual(out, self.expect) def test_ignores_ordinary_functions(self): class Mod(object): pass def test(): pass m = Mod() m.test = test event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 0) def test_can_load_tests_from_generator_functions(self): class Mod(object): __name__ = 'themod' def check(x): assert x == 1 def test(): yield check, 1 yield check, 2 m = Mod() m.test = test test.__module__ = m.__name__ event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 2) # check that test names are sensible self.assertEqual(util.test_name(event.extraTests[0]), 'themod.test:1') self.assertEqual(util.test_name(event.extraTests[1]), 'themod.test:2') def test_can_load_tests_from_generator_methods(self): class Mod(object): pass def check(x): return x == 1 class Test(TestCase): def test(self): yield check, 1 yield check, 2 m = Mod() m.Test = Test event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 1) self.assertEqual(len(event.extraTests[0]._tests), 2) nose2-0.6.4/nose2/tests/unit/test_junitxml.py0000664000175000017500000002357312672050004020613 0ustar travistravisfrom xml.etree import ElementTree as ET from nose2.tests._common import TestCase from nose2.compat import unittest from nose2 import events, loader, result, session, tools from nose2.plugins import junitxml, logcapture from nose2.plugins.loader import generators, parameters, testcases import logging import os import six import sys class TestJunitXmlPlugin(TestCase): _RUN_IN_TEMP = True BAD_FOR_XML_U = six.u('A\x07 B\x0B C\x10 D\uD900 ' 'E\uFFFE F\x80 G\x90 H\uFDDD') # UTF-8 string with double null (invalid) BAD_FOR_XML_B = six.b('A\x07 B\x0b C\x10 D\xed\xa4\x80 ' 'E\xef\xbf\xbe F\xc2\x80 G\xc2\x90 H\xef\xb7\x9d ' '\x00\x00') # "byte" strings in PY2 and unicode in py3 works as expected will # will translate surrogates into UTF-16 characters so BAD_FOR_XML_U # should have 8 letters follows by 0xFFFD, but only 4 when keeping # the discouraged/restricted ranges. Respectively: # "A\uFFFD B\uFFFD C\uFFFD D\uFFFD E\uFFFD F\uFFFD G\uFFFD H\uFFFD" # "A\uFFFD B\uFFFD C\uFFFD D\uFFFD E\uFFFD F\x80 G\x90 H\uFDDD" # # In Python 2 Invalid ascii characters seem to get escaped out as part # of tracebace.format_traceback so full and partial replacements are: # "A\uFFFD B\uFFFD C\uFFFD D\\\\ud900 E\\\\ufffe F\\\\x80 G\\\\x90 H\\\\ufddd" # "A\uFFFD B\uFFFD C\uFFFD D\\\\ud900 E\\\\ufffe F\\\\x80 G\\\\x90 H\\\\ufddd" # # Byte strings in py3 as errors are replaced by their representation string # So these will be safe and not have any replacements # "b'A\\x07 B\\x0b C\\x10 D\\xed\\xa4\\x80 E\\xef\\xbf\\xbe F\\xc2\\x80 # G\\xc2\\x90 H\\xef\\xb7\\x9d \\x00\\x00" if sys.maxunicode <= 0xFFFF: EXPECTED_RE = six.u("^[\x09\x0A\x0D\x20\x21-\uD7FF\uE000-\uFFFD]*$") EXPECTED_RE_SAFE = six.u("^[\x09\x0A\x0D\x20\x21-\x7E\x85" "\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD]*$") else: EXPECTED_RE = six.u("^[\x09\x0A\x0D\x20\x21-\uD7FF\uE000-\uFFFD" "\u10000-\u10FFFF]*$") EXPECTED_RE_SAFE = six.u("^[\x09\x0A\x0D\x20\x21-\x7E\x85" "\xA0-\uD7FF\uE000-\uFDCF\uFDF0-\uFFFD" "\u10000-\u1FFFD\u20000-\u2FFFD" "\u30000-\u3FFFD\u40000-\u4FFFD" "\u50000-\u5FFFD\u60000-\u6FFFD" "\u70000-\u7FFFD\u80000-\u8FFFD" "\u90000-\u8FFFD\uA0000-\uAFFFD" "\uB0000-\uBFFFD\uC0000-\uCFFFD" "\uD0000-\uDFFFD\uE0000-\uEFFFD" "\uF0000-\uFFFFD\u100000-\u10FFFD]*$") def setUp(self): super(TestJunitXmlPlugin, self).setUp() self.session = session.Session() self.loader = loader.PluggableTestLoader(self.session) self.result = result.PluggableTestResult(self.session) self.plugin = junitxml.JUnitXmlReporter(session=self.session) self.plugin.register() # unittest2 needs this if not hasattr(self, 'assertRegex'): self.assertRegex = self.assertRegexpMatches class Test(unittest.TestCase): def test(self): pass def test_chdir(self): TEMP_SUBFOLDER = 'test_chdir' os.mkdir(TEMP_SUBFOLDER) os.chdir(TEMP_SUBFOLDER) def test_fail(self): assert False def test_err(self): 1 / 0 def test_skip(self): self.skipTest('skip') def test_bad_xml(self): raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_U) def test_bad_xml_b(self): raise RuntimeError(TestJunitXmlPlugin.BAD_FOR_XML_B) def test_gen(self): def check(a, b): self.assertEqual(a, b) yield check, 1, 1 yield check, 1, 2 @tools.params(1, 2, 3) def test_params(self, p): self.assertEqual(p, 2) def test_with_log(self): logging.info('log message') self.case = Test def test_success_added_to_xml(self): test = self.case('test') test(self.result) self.assertEqual(self.plugin.numtests, 1) self.assertEqual(len(self.plugin.tree.findall('testcase')), 1) def test_failure_includes_traceback(self): test = self.case('test_fail') test(self.result) case = self.plugin.tree.find('testcase') failure = case.find('failure') assert failure is not None assert 'Traceback' in failure.text def test_error_bad_xml(self): self.plugin.keep_restricted = False test = self.case('test_bad_xml') test(self.result) case = self.plugin.tree.find('testcase') error = case.find('error') self.assertRegex(error.text, self.EXPECTED_RE_SAFE) def test_error_bad_xml_keep(self): self.plugin.keep_restricted = True test = self.case('test_bad_xml') test(self.result) case = self.plugin.tree.find('testcase') error = case.find('error') self.assertRegex(error.text, self.EXPECTED_RE) def test_error_bad_xml_b(self): self.plugin.keep_restricted = False test = self.case('test_bad_xml_b') test(self.result) case = self.plugin.tree.find('testcase') error = case.find('error') ending = six.u(' \uFFFD\uFFFD') assert error is not None self.assertRegex(error.text, self.EXPECTED_RE_SAFE) def test_error_bad_xml_b_keep(self): self.plugin.keep_restricted = True test = self.case('test_bad_xml_b') test(self.result) case = self.plugin.tree.find('testcase') error = case.find('error') assert error is not None self.assertRegex(error.text, self.EXPECTED_RE) def test_error_includes_traceback(self): test = self.case('test_err') test(self.result) case = self.plugin.tree.find('testcase') error = case.find('error') assert error is not None assert 'Traceback' in error.text def test_skip_includes_skipped(self): test = self.case('test_skip') test(self.result) case = self.plugin.tree.find('testcase') skip = case.find('skipped') assert skip is not None def test_generator_test_name_correct(self): gen = generators.Generators(session=self.session) gen.register() event = events.LoadFromTestCaseEvent(self.loader, self.case) self.session.hooks.loadTestsFromTestCase(event) cases = event.extraTests for case in cases: case(self.result) xml = self.plugin.tree.findall('testcase') self.assertEqual(len(xml), 2) self.assertEqual(xml[0].get('name'), 'test_gen:1') self.assertEqual(xml[1].get('name'), 'test_gen:2') def test_params_test_name_correct(self): # param test loading is a bit more complex than generator # loading. XXX -- can these be reconciled so they both # support exclude and also both support loadTestsFromTestCase? plug1 = parameters.Parameters(session=self.session) plug1.register() plug2 = testcases.TestCaseLoader(session=self.session) plug2.register() # need module to fire top-level event class Mod(object): pass m = Mod() m.Test = self.case event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) for case in event.extraTests: case(self.result) xml = self.plugin.tree.findall('testcase') self.assertEqual(len(xml), 12) params = [x for x in xml if x.get('name').startswith('test_params')] self.assertEqual(len(params), 3) self.assertEqual(params[0].get('name'), 'test_params:1') self.assertEqual(params[1].get('name'), 'test_params:2') self.assertEqual(params[2].get('name'), 'test_params:3') def test_writes_xml_file_at_end(self): test = self.case('test') test(self.result) event = events.StopTestRunEvent(None, self.result, 1, 1) self.plugin.stopTestRun(event) with open(self.plugin.path, 'r') as fh: tree = ET.parse(fh).getroot() self.assertEqual(len(tree.findall('testcase')), 1) case = tree.find('testcase') assert 'time' in case.attrib assert 'classname' in case.attrib self.assertEqual(case.get('name'), 'test') self.assertEqual(tree.get('errors'), '0') self.assertEqual(tree.get('failures'), '0') self.assertEqual(tree.get('skipped'), '0') self.assertEqual(tree.get('tests'), '1') assert 'time' in tree.attrib def test_xml_file_path_is_not_affected_by_chdir_in_test(self): inital_dir = os.getcwd() test = self.case('test_chdir') test(self.result) self.assertEqual(inital_dir, os.path.dirname(os.path.realpath(self.plugin.path))) def test_xml_contains_empty_system_err_without_logcapture(self): test = self.case('test_with_log') test(self.result) case = self.plugin.tree.find('testcase') system_err = case.find('system-err') assert system_err is not None assert not system_err.text def test_xml_contains_log_message_in_system_err_with_logcapture(self): self.logcapture_plugin = logcapture.LogCapture(session=self.session) self.logcapture_plugin.register() test = self.case('test_with_log') test(self.result) case = self.plugin.tree.find('testcase') system_err = case.find('system-err') assert system_err is not None assert 'log message' in system_err.text assert 'INFO' in system_err.text nose2-0.6.4/nose2/tests/unit/test_layers_plugin.py0000664000175000017500000002014612672050004021607 0ustar travistravisimport sys from nose2.compat import unittest from nose2.plugins import layers from nose2 import events, loader, session from nose2.tests._common import TestCase class TestLayers(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(session=self.session) self.session.testLoader = self.loader self.plugin = layers.Layers(session=self.session) def test_simple_layer_inheritance(self): class L1(object): pass class L2(L1): pass class T1(unittest.TestCase): layer = L1 def test(self): pass class T2(unittest.TestCase): layer = L2 def test(self): pass suite = unittest.TestSuite([T2('test'), T1('test')]) event = events.StartTestRunEvent(None, suite, None, 0, None) self.plugin.startTestRun(event) expect = [['test (nose2.tests.unit.test_layers_plugin.T1)', ['test (nose2.tests.unit.test_layers_plugin.T2)']]] self.assertEqual(self.names(event.suite), expect) def test_multiple_inheritance(self): class L1(object): pass class L2(L1): pass class L3(L1): pass class T1(unittest.TestCase): layer = L1 def test(self): pass class T2(unittest.TestCase): layer = L2 def test(self): pass class T3(unittest.TestCase): layer = L3 def test(self): pass suite = unittest.TestSuite([T2('test'), T1('test'), T3('test')]) event = events.StartTestRunEvent(None, suite, None, 0, None) self.plugin.startTestRun(event) expect = [['test (nose2.tests.unit.test_layers_plugin.T1)', ['test (nose2.tests.unit.test_layers_plugin.T2)'], ['test (nose2.tests.unit.test_layers_plugin.T3)']]] self.assertEqual(self.names(event.suite), expect) def test_deep_inheritance(self): class L1(object): pass class L2(L1): pass class L3(L1): pass class L4(L2, L1): pass class L5(L4): pass class T1(unittest.TestCase): layer = L1 def test(self): pass class T2(unittest.TestCase): layer = L2 def test(self): pass class T3(unittest.TestCase): layer = L3 def test(self): pass class T4(unittest.TestCase): layer = L4 def test(self): pass class T5(unittest.TestCase): layer = L5 def test(self): pass suite = unittest.TestSuite([T2('test'), T1('test'), T3('test'), T4('test'), T5('test')]) event = events.StartTestRunEvent(None, suite, None, 0, None) self.plugin.startTestRun(event) expect = [['test (nose2.tests.unit.test_layers_plugin.T1)', ['test (nose2.tests.unit.test_layers_plugin.T2)', ['test (nose2.tests.unit.test_layers_plugin.T4)', ['test (nose2.tests.unit.test_layers_plugin.T5)']]], ['test (nose2.tests.unit.test_layers_plugin.T3)']]] self.assertEqual(self.names(event.suite), expect) def test_mixed_layers_no_layers(self): class L1(object): pass class L2(L1): pass class T1(unittest.TestCase): layer = L1 def test(self): pass class T2(unittest.TestCase): layer = L2 def test(self): pass class T3(unittest.TestCase): def test(self): pass suite = unittest.TestSuite([T2('test'), T1('test'), T3('test')]) event = events.StartTestRunEvent(None, suite, None, 0, None) self.plugin.startTestRun(event) expect = ['test (nose2.tests.unit.test_layers_plugin.T3)', ['test (nose2.tests.unit.test_layers_plugin.T1)', ['test (nose2.tests.unit.test_layers_plugin.T2)']]] self.assertEqual(self.names(event.suite), expect) def test_ordered_layers(self): class L1(object): pass class L2(L1): position = 1 class L3(L1): position = 2 class L4(L1): position = 3 class L5(L2): position = 4 class T1(unittest.TestCase): layer = L1 def test(self): pass class T2(unittest.TestCase): layer = L2 def test(self): pass class T3(unittest.TestCase): layer = L3 def test(self): pass class T4(unittest.TestCase): layer = L4 def test(self): pass class T5(unittest.TestCase): layer = L5 def test(self): pass suite = unittest.TestSuite([T2('test'), T1('test'), T3('test'), T4('test'), T5('test')]) event = events.StartTestRunEvent(None, suite, None, 0, None) self.plugin.startTestRun(event) expect = [['test (nose2.tests.unit.test_layers_plugin.T1)', ['test (nose2.tests.unit.test_layers_plugin.T2)', ['test (nose2.tests.unit.test_layers_plugin.T5)', ]], ['test (nose2.tests.unit.test_layers_plugin.T3)', ], ['test (nose2.tests.unit.test_layers_plugin.T4)', ]]] self.assertEqual(self.names(event.suite), expect) def test_mixin_inheritance(self): class L1(object): pass class L2(object): # a mixin, doesn't share a base w/L1 pass class L3(L1): pass class L4(L3): pass class L5(L4): pass class L6(L2): mixins = (L4,) class T1(unittest.TestCase): layer = L1 def test(self): pass class T3(unittest.TestCase): layer = L3 def test(self): pass class T4(unittest.TestCase): layer = L4 def test(self): pass class T5(unittest.TestCase): layer = L5 def test(self): pass class T6(unittest.TestCase): layer = L6 def test(self): pass suite = unittest.TestSuite([T6('test'), T1('test'), T3('test'), T4('test'), T5('test')]) event = events.StartTestRunEvent(None, suite, None, 0, None) self.plugin.startTestRun(event) expect = [['test (nose2.tests.unit.test_layers_plugin.T1)', ['test (nose2.tests.unit.test_layers_plugin.T3)', ['test (nose2.tests.unit.test_layers_plugin.T4)', [['test (nose2.tests.unit.test_layers_plugin.T6)']], ['test (nose2.tests.unit.test_layers_plugin.T5)', ]]]]] self.assertEqual(self.names(event.suite), expect) def names(self, suite): return [n for n in self.iternames(suite)] def iternames(self, suite): for t in suite: if isinstance(t, unittest.TestCase): if sys.version_info >= (3, 5): test_module = t.__class__.__module__ test_class = t.__class__.__name__ test_method = t._testMethodName yield "%s (%s.%s)" % (test_method, test_module, test_class) else: yield str(t) else: yield [n for n in self.iternames(t)] def _listset(self, l): n = set([]) for t in l: if isinstance(t, list): n.add(self._listset(t)) else: n.add(t) return frozenset(n) nose2-0.6.4/nose2/tests/unit/test_loader.py0000664000175000017500000000713312672050004020201 0ustar travistravisfrom nose2 import events, loader, session from nose2.tests._common import TestCase class TestPluggableTestLoader(TestCase): def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(self.session) def test_failed_load_tests_exception(self): suite = self.loader.failedLoadTests('test', RuntimeError('err')) tc = suite._tests[0] with self.assertRaises(RuntimeError) as cm: tc.test() self.assertEqual(cm.exception.args, ('err', )) def test_failed_load_tests_exc_info(self): suite = self.loader.failedLoadTests( 'test', (RuntimeError, RuntimeError('err'), None)) tc = suite._tests[0] with self.assertRaises(RuntimeError) as cm: tc.test() self.assertEqual(cm.exception.args, ('err', )) def test_load_from_module_calls_hook(self): self.session.hooks.register('loadTestsFromModule', FakePlugin()) evt = events.LoadFromModuleEvent(self.loader, 'some_module') self.session.hooks.loadTestsFromModule(evt) self.assertTrue(evt.fakeLoadFromModule, "FakePlugin.loadTestsFromModule() was not called") def test_load_from_name_calls_hook(self): self.session.hooks.register('loadTestsFromName', FakePlugin()) evt = events.LoadFromNameEvent(self.loader, 'some_name', 'some_module') self.session.hooks.loadTestsFromName(evt) self.assertTrue(evt.fakeLoadFromName, "FakePlugin.fakeLoadFromName() was not called") def test_load_from_names_calls_hook(self): self.session.hooks.register('loadTestsFromNames', FakePlugin()) evt = events.LoadFromNamesEvent(self.loader, ['some_name'], 'some_module') self.session.hooks.loadTestsFromNames(evt) self.assertTrue(evt.fakeLoadFromNames, "FakePlugin.fakeLoadFromNames() was not called") def test_loader_from_names_calls_module_hook(self): fake_plugin = FakePlugin() self.session.hooks.register('loadTestsFromModule', fake_plugin) self.loader.loadTestsFromNames([], 'some_module') self.assertTrue(fake_plugin.fakeLoadFromModule, "FakePlugin.loadTestsFromModule() was not called") def test_loader_from_names_calls_name_hook(self): fake_plugin = FakePlugin() self.session.hooks.register('loadTestsFromName', fake_plugin) self.loader.loadTestsFromNames(['some_name']) self.assertTrue(fake_plugin.fakeLoadFromName, "FakePlugin.loadTestsFromName() was not called") def test_loader_from_names_calls_names_hook(self): fake_plugin = FakePlugin() self.session.hooks.register('loadTestsFromNames', fake_plugin) self.loader.loadTestsFromNames(['some_name']) self.assertTrue(fake_plugin.fakeLoadFromNames, "FakePlugin.loadTestsFromNames() was not called") class FakePlugin(object): def __init__(self): self.fakeLoadFromModule = False self.fakeLoadFromName = False self.fakeLoadFromNames = False def loadTestsFromModule(self, event): event.fakeLoadFromModule = True self.fakeLoadFromModule = True def loadTestsFromName(self, event): event.fakeLoadFromName = True self.fakeLoadFromName = True def loadTestsFromNames(self, event): event.fakeLoadFromNames = True self.fakeLoadFromNames = Truenose2-0.6.4/nose2/tests/unit/test_logcapture_plugin.py0000664000175000017500000000420612672050004022454 0ustar travistravisimport logging from nose2.tests._common import TestCase from nose2.plugins import logcapture from nose2 import session log = logging.getLogger(__name__) class StubLogging(object): def __init__(self, name=None): self.name = name self.handlers = [] self.level = None def getLogger(self, _name=None): return self def addHandler(self, handler): self.handlers.append(handler) def setLevel(self, level): self.level = level def debug(self, message, *arg): # import pdb; pdb.set_trace() for handler in self.handlers: handler.emit(StubRecord(message % arg)) class StubRecord(object): def __init__(self, message): self.message = message self.name = 'stub' self.levelname = 'stub' self.exc_info = None self.exc_text = None self.stack_info = None def getMessage(self): return self.message class LogCaptureUnitTest(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.plugin = logcapture.LogCapture(session=self.session) self.logging = logcapture.logging logcapture.logging = StubLogging() def tearDown(self): logcapture.logging = self.logging def event(self, error=True, failed=False): e = Event() e.metadata = {} return e def test_buffer_cleared_after_each_test(self): self.plugin.startTestRun(None) self.plugin.startTest(None) logcapture.logging.getLogger('test').debug("hello") assert self.plugin.handler.buffer self.plugin.setTestOutcome(self.event()) assert self.plugin.handler.buffer self.plugin.stopTest(None) assert not self.plugin.handler.buffer def test_buffered_logs_attached_to_event(self): self.plugin.startTestRun(None) self.plugin.startTest(None) logcapture.logging.getLogger('test').debug("hello") assert self.plugin.handler.buffer e = self.event() self.plugin.setTestOutcome(e) assert 'logs' in e.metadata, "No log in %s" % e.metadata class Event: pass nose2-0.6.4/nose2/tests/unit/test_mp_plugin.py0000664000175000017500000000420712672050004020724 0ustar travistravisfrom nose2 import session from nose2.tests._common import TestCase, Conn from nose2.plugins import mp import sys class TestMPPlugin(TestCase): def setUp(self): self.session = session.Session() self.plugin = mp.MultiProcess(session=self.session) def test_gentests(self): conn = Conn([1, 2, 3]) res = [] for x in mp.gentests(conn): res.append(x) self.assertEqual(res, [1, 2, 3]) def test_recording_plugin_interface(self): rpi = mp.RecordingPluginInterface() # this one should record rpi.setTestOutcome(None) # none of these should record rpi.getTestCaseNames(None) rpi.startSubprocess(None) rpi.stopSubprocess(None) rpi.registerInSubprocess(None) rpi.loadTestsFromModule(None) rpi.loadTestsFromTestCase(None) self.assertEqual(rpi.flush(), [('setTestOutcome', None)]) def test_address(self): platform = sys.platform try: sys.platform = "linux" host = "1.2.3.4" port = 245 self.plugin.setAddress(host) self.assertEqual((self.plugin.bind_host, self.plugin.bind_port), (host, 0)) self.plugin.setAddress("%s:%i" % (host, port)) self.assertEqual((self.plugin.bind_host, self.plugin.bind_port), (host, port)) self.plugin.setAddress(None) self.assertEqual((self.plugin.bind_host, self.plugin.bind_port), (None, 0)) sys.platform = "win32" self.plugin.setAddress(host) self.assertEqual((self.plugin.bind_host, self.plugin.bind_port), (host, 0)) self.plugin.setAddress("%s:%i" % (host, port)) self.assertEqual((self.plugin.bind_host, self.plugin.bind_port), (host, port)) self.plugin.setAddress(None) self.assertEqual((self.plugin.bind_host, self.plugin.bind_port), ("127.116.157.163", 0)) finally: sys.platform = platform nose2-0.6.4/nose2/tests/unit/test_outcomes_plugin.py0000664000175000017500000000441412672050004022146 0ustar travistravisfrom nose2.plugins import outcomes from nose2 import events, result, session from nose2.tests._common import TestCase class TestOutComesPlugin(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.result = result.PluggableTestResult(self.session) self.plugin = outcomes.Outcomes(session=self.session) self.plugin.register() class Test(TestCase): def test_e1(self): raise KeyError("k") def test_e2(self): raise TypeError("x") def test_e3(self): raise IOError("o") self.case = Test class Watcher(events.Plugin): def __init__(self): self.outcomes = {} def testOutcome(self, event): self.outcomes.setdefault(event.outcome, []).append(event) self.watcher = Watcher(session=self.session) self.watcher.register() def test_labels_upper(self): self.assertEqual(self.plugin.labels('xxx'), ('X', 'XXX')) def test_can_do_nothing_when_not_configured(self): test = self.case('test_e1') test(self.result) assert self.watcher.outcomes['error'] assert not 'failed' in self.watcher.outcomes def test_can_treat_as_fail(self): self.plugin.treatAsFail.add('KeyError') test = self.case('test_e1') test(self.result) assert self.watcher.outcomes['failed'] assert not 'error' in self.watcher.outcomes def test_can_treat_as_skip(self): self.plugin.treatAsSkip.add('KeyError') test = self.case('test_e1') test(self.result) assert self.watcher.outcomes['skipped'] assert not 'error' in self.watcher.outcomes def test_can_handle_multiple_events_cleanly(self): self.plugin.treatAsSkip.add('KeyError') self.plugin.treatAsFail.add('TypeError') test = self.case('test_e1') test(self.result) test = self.case('test_e2') test(self.result) test = self.case('test_e3') test(self.result) self.assertEqual(len(self.watcher.outcomes['skipped']), 1) self.assertEqual(len(self.watcher.outcomes['error']), 1) self.assertEqual(len(self.watcher.outcomes['failed']), 1) nose2-0.6.4/nose2/tests/unit/test_params_plugin.py0000664000175000017500000001346512672050004021601 0ustar travistravisfrom nose2 import events, loader, session, util from nose2.plugins.loader import parameters, testcases from nose2.tests._common import TestCase from nose2.tools import cartesian_params, params class TestParams(TestCase): tags = ['unit'] def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(self.session) self.plugin = parameters.Parameters(session=self.session) # need testcase loader to make the initial response to load from module self.tcl = testcases.TestCaseLoader(session=self.session) def test_ignores_ordinary_functions(self): class Mod(object): pass def test(): pass m = Mod() m.test = test event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 0) def test_can_load_tests_from_parameterized_by_params_functions(self): class Mod(object): __name__ = 'themod' def check(x): assert x == 1 @params(1, 2) def test(a): check(a) m = Mod() m.test = test test.__module__ = m.__name__ event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 2) # check that test names are sensible self.assertEqual(util.test_name(event.extraTests[0]), 'themod.test:1') self.assertEqual(util.test_name(event.extraTests[1]), 'themod.test:2') def test_can_load_tests_from_parameterized_by_cartesian_params_functions(self): class Mod(object): __name__ = 'themod' def check(x, y): assert x == y @cartesian_params( (1, 2), (2, 3), ) def test(a, b): check(a, b) m = Mod() m.test = test test.__module__ = m.__name__ event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 4) # check that test names are sensible self.assertEqual(util.test_name(event.extraTests[0]), 'themod.test:1') self.assertEqual(util.test_name(event.extraTests[1]), 'themod.test:2') self.assertEqual(util.test_name(event.extraTests[2]), 'themod.test:3') self.assertEqual(util.test_name(event.extraTests[3]), 'themod.test:4') def test_can_load_tests_from_parameterized_by_params_methods(self): class Mod(object): __name__ = 'themod' class Test(TestCase): @params(1, 2) def test(self, a): assert a == 1 m = Mod() m.Test = Test Test.__module__ = m.__name__ event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 1) self.assertEqual(len(event.extraTests[0]._tests), 2) # check that test names are sensible t1 = util.test_name(event.extraTests[0]._tests[0], qualname=False) self.assertEqual(t1, 'themod.Test.test:1') t2 = util.test_name(event.extraTests[0]._tests[1], qualname=False) self.assertEqual(t2, 'themod.Test.test:2') def test_can_load_tests_from_parameterized_by_cartesian_params_methods(self): class Mod(object): __name__ = 'themod' class Test(TestCase): @cartesian_params( (1, 2), (2, 3), ) def test(self, a, b): assert a == b m = Mod() m.Test = Test Test.__module__ = m.__name__ event = events.LoadFromModuleEvent(self.loader, m) self.session.hooks.loadTestsFromModule(event) self.assertEqual(len(event.extraTests), 1) self.assertEqual(len(event.extraTests[0]._tests), 4) # check that test names are sensible self.assertEqual(util.test_name(event.extraTests[0]._tests[0]), 'themod.Test.test:1') self.assertEqual(util.test_name(event.extraTests[0]._tests[1]), 'themod.Test.test:2') self.assertEqual(util.test_name(event.extraTests[0]._tests[2]), 'themod.Test.test:3') self.assertEqual(util.test_name(event.extraTests[0]._tests[3]), 'themod.Test.test:4') def test_params_creates_params_for_function(self): @params( (1, 2), ('a', 'b'), ) def test(a, b): assert a == b self.assertTupleEqual(tuple(test.paramList), ((1, 2), ('a', 'b'))) def test_cartesian_params_creates_cartesian_product_of_params_for_function(self): @cartesian_params( (1, 2), ('a', 'b'), ) def test(a, b): assert a == b self.assertTupleEqual(tuple(test.paramList), ((1, 'a'), (1, 'b'), (2, 'a'), (2, 'b'))) def test_params_creates_params_for_method(self): class Test(TestCase): @params( (1, 2), ('a', 'b'), ) def test(self, a, b): assert a == b self.assertTupleEqual(tuple(Test.test.paramList), ((1, 2), ('a', 'b'))) def test_cartesian_params_creates_cartesian_product_of_params_for_method(self): class Test(TestCase): @cartesian_params( (1, 2), ('a', 'b'), ) def test(self, a, b): assert a == b self.assertTupleEqual(tuple(Test.test.paramList), ((1, 'a'), (1, 'b'), (2, 'a'), (2, 'b'))) nose2-0.6.4/nose2/tests/unit/test_plugin_api.py0000664000175000017500000000221112672050004021052 0ustar travistravisfrom nose2 import events, session from nose2.tests._common import TestCase class Example(events.Plugin): commandLineSwitch = ('X', 'xxx', 'triple x') def testOutcome(self, event): pass class TestPluginApi(TestCase): def setUp(self): self.session = session.Session() self.plug = Example(session=self.session) super(TestCase, self).setUp() def test_add_option_adds_option(self): helpt = self.session.argparse.format_help() assert '-X, --xxx' in helpt, \ "commandLineSwitch arg not found in help text: %s" % helpt def test_short_opt_registers_plugin(self): args, argv = self.session.argparse.parse_known_args(['-X']) assert self.plug in self.session.plugins assert self.plug in self.session.hooks.testOutcome.plugins, \ "short opt did not register plugin" def test_long_opt_registers_plugin(self): args, argv = self.session.argparse.parse_known_args(['--xxx']) assert self.plug in self.session.plugins assert self.plug in self.session.hooks.testOutcome.plugins, \ "long opt did not register plugin" nose2-0.6.4/nose2/tests/unit/test_printhooks_plugin.py0000664000175000017500000001041312672050004022504 0ustar travistravisimport sys import six from nose2.plugins import printhooks from nose2 import events, session from nose2.tests._common import TestCase class CustomEvent(events.Event): _attrs = events.Event._attrs + ('args',) def __init__(self, args, **kw): self.args = args super(CustomEvent, self).__init__(**kw) class TestPluginA(events.Plugin): def register(self): super(TestPluginA, self).register() self.addMethods('pluginHookA') def register_with_nested_hook(self): super(TestPluginA, self).register() self.addMethods('pluginHookB') class TestPluginB(events.Plugin): def pluginHookA(self, event): event.handled = True return "TestPluginB.pluginHookA" class TestPluginC(events.Plugin): def register(self): super(TestPluginC, self).register() self.addMethods('pluginHookB1') def pluginHookB(self, event): nested_event = CustomEvent('level_two_args') self.session.hooks.pluginHookB1(nested_event) event.handled = True return "TestPluginC.pluginHookB" class IndentAwarePlugin(events.Plugin): def pluginHookA(self, event): event.handled = True return printhooks.INDENT.pop() class TestPrintHooksPlugin(TestCase): tags = ['unit'] def setUp(self): self.err = sys.stderr self.buf = six.StringIO() sys.stderr = self.buf self.addCleanup(self.restore_stderr) self.session = session.Session() self.print_hooks_plugin = printhooks.PrintHooks(session=self.session) self.plugin_a = TestPluginA(session=self.session) self.plugin_b = TestPluginB(session=self.session) def restore_stderr(self): sys.stderr = self.err def test_traces_hooks_created_after_own_registration(self): self.print_hooks_plugin.register() self.plugin_a.register() self.plugin_b.register() event = CustomEvent('args') result = self.session.hooks.pluginHookA(event) self.assertEqual(result, "TestPluginB.pluginHookA") self.assertEqual("\n" "pluginHookA: " "CustomEvent(handled=False, args='args')", self.buf.getvalue()) def test_traces_hooks_created_before_own_registration(self): self.plugin_a.register() self.plugin_b.register() self.print_hooks_plugin.register() event = CustomEvent('args') result = self.session.hooks.pluginHookA(event) self.assertEqual(result, "TestPluginB.pluginHookA") self.assertEqual("\n" "pluginHookA: " "CustomEvent(handled=False, args='args')", self.buf.getvalue()) def test_traces_hooks_that_nobody_implements(self): self.plugin_a.register() self.print_hooks_plugin.register() event = CustomEvent('args') result = self.session.hooks.pluginHookA(event) self.assertEqual(result, None) self.assertEqual("\n" "pluginHookA: " "CustomEvent(handled=False, args='args')", self.buf.getvalue()) def test_indents_nested_hooks_in_trace(self): self.plugin_c = TestPluginC(session=self.session) self.plugin_a.register_with_nested_hook() self.plugin_c.register() self.print_hooks_plugin.register() event = CustomEvent('level_one_args') result = self.session.hooks.pluginHookB(event) self.assertEqual(result, "TestPluginC.pluginHookB") self.assertEqual("\n" "pluginHookB: " "CustomEvent(handled=False, args='level_one_args')" "\n " "pluginHookB1: " "CustomEvent(handled=False, args='level_two_args')", self.buf.getvalue()) def test_hook_implementors_can_modify_trace_indent(self): self.indent_aware_plugin = IndentAwarePlugin(session=self.session) self.plugin_a.register() self.indent_aware_plugin.register() self.print_hooks_plugin.register() event = CustomEvent('args') result = self.session.hooks.pluginHookA(event) self.assertEqual(result, " ") nose2-0.6.4/nose2/tests/unit/test_prof_plugin.py0000664000175000017500000000166212672050004021260 0ustar travistravisfrom nose2 import session from nose2.plugins import prof from nose2.events import StartTestRunEvent from nose2.tests._common import Stub, TestCase class TestProfPlugin(TestCase): tags = ['unit'] def setUp(self): self.plugin = prof.Profiler(session=session.Session()) self.hotshot = prof.hotshot self.stats = prof.stats prof.hotshot = Stub() prof.stats = Stub() def tearDown(self): prof.hotshot = self.hotshot prof.stats = self.stats def test_startTestRun_sets_executeTests(self): _prof = Stub() _prof.runcall = object() prof.hotshot.Profile = lambda filename: _prof event = StartTestRunEvent(runner=None, suite=None, result=None, startTime=None, executeTests=None) self.plugin.startTestRun(event) assert event.executeTests is _prof.runcall, \ "executeTests was not replaced" nose2-0.6.4/nose2/tests/unit/test_result.py0000664000175000017500000000122612672050004020246 0ustar travistravisfrom nose2 import result, session from nose2.tests._common import TestCase class TestPluggableTestResult(TestCase): def setUp(self): self.session = session.Session() self.result = result.PluggableTestResult(self.session) def test_skip_reason_not_discarded(self): class Test(TestCase): def test(self): pass plugin = FakePlugin() self.session.hooks.register('testOutcome', plugin) self.result.addSkip(Test('test'), 'because') self.assertEqual(plugin.reason, 'because') class FakePlugin(object): def testOutcome(self, event): self.reason = event.reason nose2-0.6.4/nose2/tests/unit/test_session.py0000664000175000017500000000101412672050004020406 0ustar travistravisfrom nose2 import events, session from nose2.compat import unittest class SessionUnitTests(unittest.TestCase): def test_can_create_session(self): session.Session() def test_load_plugins_from_module_can_load_plugins(self): class fakemod: pass f = fakemod() class A(events.Plugin): pass f.A = A s = session.Session() s.loadPluginsFromModule(f) assert s.plugins a = s.plugins[0] self.assertEqual(a.session, s) nose2-0.6.4/nose2/tests/unit/test_testcase_loader.py0000664000175000017500000000536212672050004022076 0ustar travistravisfrom nose2.tests._common import TestCase from nose2.plugins.loader.testcases import TestCaseLoader from nose2 import events, loader, session class TestTestCaseLoader(TestCase): def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(session=self.session) self.plugin = TestCaseLoader(session=self.session) class Mod(object): pass self.module = Mod() class A(TestCase): def test(self): pass class B(TestCase): def runTest(self): pass class C(TestCase): def foo(self): pass class Test(object): def test(self): pass self.module.A = A self.module.B = B self.module.C = C self.module.Test = Test def test_can_find_testcases_in_module(self): event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 3) self.assertEqual(len(event.extraTests[0]._tests), 1) # A self.assertEqual(len(event.extraTests[1]._tests), 1) # B self.assertEqual(len(event.extraTests[2]._tests), 0) # C def test_get_testcase_names_can_override_name_selection(self): class FooIsOnlyTest(events.Plugin): def getTestCaseNames(self, event): event.handled = True return ['foo'] if 'foo' in dir(event.testCase) else [] foo = FooIsOnlyTest(session=self.session) foo.register() event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 3) self.assertEqual(len(event.extraTests[0]._tests), 0) # A self.assertEqual(len(event.extraTests[1]._tests), 1) # B (runTest) self.assertEqual(len(event.extraTests[2]._tests), 1) # C def test_plugins_can_exclude_test_names(self): class Excluder(events.Plugin): def getTestCaseNames(self, event): event.excludedNames.append('test') excl = Excluder(session=self.session) excl.register() event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 3) self.assertEqual(len(event.extraTests[0]._tests), 0) # A self.assertEqual(len(event.extraTests[1]._tests), 1) # B (runTest) self.assertEqual(len(event.extraTests[2]._tests), 0) # C nose2-0.6.4/nose2/tests/unit/test_testclass_loader.py0000664000175000017500000000735712672050004022276 0ustar travistravisfrom nose2.tests._common import TestCase from nose2.plugins.loader.testclasses import TestClassLoader from nose2 import events, loader, session class TestTestClassLoader(TestCase): def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(session=self.session) self.plugin = TestClassLoader(session=self.session) class Mod(object): pass self.module = Mod() class TestA(object): def test(self): pass class TestB(object): def runTest(self): pass class TestC(object): def foo(self): pass class Test(TestCase): def test(self): pass self.module.TestA = TestA self.module.TestB = TestB self.module.TestC = TestC self.module.Test = Test def test_can_find_testclasses_in_module(self): event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 3) self.assertEqual(len(event.extraTests[0]._tests), 1) # TestA self.assertEqual(len(event.extraTests[1]._tests), 0) # TestB self.assertEqual(len(event.extraTests[2]._tests), 0) # TestC def test_get_testmethod_names_can_override_name_selection(self): class FooIsOnlyTest(events.Plugin): def getTestMethodNames(self, event): event.handled = True return ['foo'] if 'foo' in dir(event.testCase) else [] foo = FooIsOnlyTest(session=self.session) foo.register() event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 3) self.assertEqual(len(event.extraTests[0]._tests), 0) # TestA self.assertEqual(len(event.extraTests[1]._tests), 0) # TestB self.assertEqual(len(event.extraTests[2]._tests), 1) # TestC def test_plugins_can_exclude_test_names(self): class Excluder(events.Plugin): def getTestMethodNames(self, event): event.excludedNames.append('test') excl = Excluder(session=self.session) excl.register() event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 3) self.assertEqual(len(event.extraTests[0]._tests), 0) # TestA self.assertEqual(len(event.extraTests[1]._tests), 0) # TestB self.assertEqual(len(event.extraTests[2]._tests), 0) # TestC class TestFailingTestClassLoader(TestCase): def setUp(self): self.session = session.Session() self.loader = loader.PluggableTestLoader(session=self.session) self.plugin = TestClassLoader(session=self.session) class Mod(object): pass self.module = Mod() class TestA(object): def __init__(self): raise RuntimeError('Something bad happened!') def test(self): pass self.module.TestA = TestA def test_can_find_testclasses_in_module(self): event = events.LoadFromModuleEvent(self.loader, self.module) result = self.session.hooks.loadTestsFromModule(event) self.assertEqual(result, None) self.assertEqual(len(event.extraTests), 1) self.assertEqual(len(event.extraTests[0]._tests), 1) # TestA self.assertEqual(event.extraTests[0]._tests[0].__class__.__name__, 'LoadTestsFailure') nose2-0.6.4/nose2/tests/unit/test_testid_plugin.py0000664000175000017500000001103312672050004021577 0ustar travistravis"""Test testid plugin.""" import os.path import pickle from six import StringIO from nose2 import session from nose2.events import ReportTestEvent from nose2.plugins import testid from nose2.tests._common import (FakeStartTestEvent, FakeLoadFromNameEvent, FakeLoadFromNamesEvent, TestCase) class UnitTestTestId(TestCase): """Test class TestId. Tests are carried out in a temporary directory, since TestId stores state to file. The temporary directory is removed after testing. """ tags = ['unit'] _RUN_IN_TEMP = True def setUp(self): super(UnitTestTestId, self).setUp() self.stream = StringIO() self.session = session.Session() self.plugin = testid.TestId(session=self.session) def test___init__(self): """Test the __init__ method.""" plug = self.plugin # Test attributes for name, exp_val in [( 'configSection', 'testid'), ('commandLineSwitch', ('I', 'with-id', 'Add test ids to output')), ('idfile', os.path.abspath( '.noseids')), ('ids', {}), ('tests', {}), ('id', 0)]: try: val = getattr(plug, name) except AttributeError: self.fail( 'TestId instance doesn\'t have attribute %s' % (name,)) self.assertEqual(val, exp_val, 'Attribute %s should have value ' '\'%s\', but has value %s' % (name, exp_val, val)) def test_start_test(self): """Test reportStartTest method.""" self.session.verbosity = 2 event = ReportTestEvent(FakeStartTestEvent(self), self.stream) plug = self.plugin plug.reportStartTest(event) self.assertEqual(plug.id, 1) test_id = self.id() self.assertEqual(plug.ids, {1: test_id}) self.assertEqual(plug.tests, {test_id: 1}) self.assertEqual(self.stream.getvalue(), '#1 ') def test_start_test_twice(self): """Test calling reportStartTest twice.""" self.session.verbosity = 2 event = ReportTestEvent(FakeStartTestEvent(self), self.stream) plug = self.plugin plug.reportStartTest(event) plug.reportStartTest(event) self.assertEqual(plug.id, 1) test_id = self.id() self.assertEqual(plug.ids, {1: test_id}) self.assertEqual(plug.tests, {test_id: 1}) self.assertEqual(self.stream.getvalue(), '#1 #1 ') def test_stop_test_run(self): """Test stopTestRun method.""" plug = self.plugin plug.reportStartTest( ReportTestEvent(FakeStartTestEvent(self), self.stream)) plug.stopTestRun(None) fh = open(plug.idfile, 'rb') try: data = pickle.load(fh) finally: fh.close() self.assertEqual(data, {'ids': plug.ids, 'tests': plug.tests}) def test_load_tests_from_name(self): """Test loadTestsFromName method.""" plug = self.plugin # By first starting/stopping a test, an ID is assigned by the plugin plug.reportStartTest( ReportTestEvent(FakeStartTestEvent(self), self.stream)) plug.stopTestRun(None) event = FakeLoadFromNameEvent('1') plug.loadTestsFromName(event) # The numeric ID should be translated to this test's ID self.assertEqual(event.name, self.id()) def test_load_tests_from_name_no_ids(self): """Test calling loadTestsFromName when no IDs have been saved.""" plug = self.plugin event = FakeLoadFromNameEvent('1') plug.loadTestsFromName(event) # The event's name should be unchanged, since no IDs should be mapped self.assertEqual(event.name, '1') def test_load_tests_from_names(self): """Test loadTestsFromNames method.""" plug = self.plugin # By first starting/stopping a test, an ID is assigned by the plugin plug.reportStartTest( ReportTestEvent(FakeStartTestEvent(self), self.stream)) plug.stopTestRun(None) event = FakeLoadFromNamesEvent(['1', '2']) plug.loadTestsFromNames(event) name1, name2 = event.names # The first numeric ID should be translated to this test's ID self.assertEqual(name1, self.id()) # The second one should not have a match self.assertEqual(name2, '2') nose2-0.6.4/nose2/tests/unit/test_util.py0000664000175000017500000000065312672050004017710 0ustar travistravisimport os import sys from nose2.tests._common import TestCase from nose2 import util class UtilTests(TestCase): _RUN_IN_TEMP = True def test_ensure_importable(self): test_dir = os.path.join(self._work_dir, 'test_dir') # Make sure test data is suitable for the test self.assertNotIn(test_dir, sys.path) util.ensure_importable(test_dir) self.assertEqual(test_dir, sys.path[0]) nose2-0.6.4/nose2/tests/__init__.py0000664000175000017500000000004112672050004016443 0ustar travistravis"""Unit and functional tests.""" nose2-0.6.4/nose2/tests/_common.py0000664000175000017500000001736312672050004016352 0ustar travistravis"""Common functionality.""" import os.path import tempfile import shutil import subprocess import sys import six from nose2.compat import unittest from nose2 import discover, util HERE = os.path.abspath(os.path.dirname(__file__)) SUPPORT = os.path.join(HERE, 'functional', 'support') class TestCase(unittest.TestCase): """TestCase extension. If the class variable ``_RUN_IN_TEMP`` is ``True`` (default: ``False``), tests will be performed in a temporary directory, which is deleted afterwards. """ _RUN_IN_TEMP = False def setUp(self): super(TestCase, self).setUp() if self._RUN_IN_TEMP: self._orig_dir = os.getcwd() work_dir = self._work_dir = tempfile.mkdtemp() os.chdir(self._work_dir) # Make sure it's possible to import modules from current directory sys.path.insert(0, work_dir) def tearDown(self): super(TestCase, self).tearDown() if self._RUN_IN_TEMP: os.chdir(self._orig_dir) shutil.rmtree(self._work_dir, ignore_errors=True) def __str__(self): """ In python 3.5, the unittest.TestCase.__str__() output changed. This makes it conform to previous version. """ if sys.version_info >= (3, 5): test_module = self.__class__.__module__ test_class = self.__class__.__name__ test_method = self._testMethodName return "%s (%s.%s)" % (test_method, test_module, test_class) else: return super(TestCase, self).__str__() def id(self): """ In python 3.5, the unittest.TestCase.__id__() output changed. This makes it conform to previous version. """ if sys.version_info >= (3, 5): test_module = self.__class__.__module__ test_class = self.__class__.__name__ test_method = self._testMethodName return "%s.%s.%s" % (test_module, test_class, test_method) else: return super(TestCase, self).id() class FunctionalTestCase(unittest.TestCase): tags = ['functional'] def assertTestRunOutputMatches(self, proc, stdout=None, stderr=None): cmd_stdout, cmd_stderr = None, None try: cmd_stdout, cmd_stderr = self._output[proc.pid] except AttributeError: self._output = {} except KeyError: pass if cmd_stdout is None: cmd_stdout, cmd_stderr = proc.communicate() self._output[proc.pid] = cmd_stdout, cmd_stderr testf = self.assertRegex if hasattr(self, 'assertRegex') \ else self.assertRegexpMatches if stdout: testf(util.safe_decode(cmd_stdout), stdout) if stderr: testf(util.safe_decode(cmd_stderr), stderr) def runIn(self, testdir, *args, **kw): return run_nose2(*args, cwd=testdir, **kw) def runModuleAsMain(self, testmodule, *args): return run_module_as_main(testmodule, *args) class _FakeEventBase(object): """Baseclass for fake :class:`~nose2.events.Event`\s.""" def __init__(self): self.handled = False self.version = '0.1' self.metadata = {} class FakeHandleFileEvent(_FakeEventBase): """Fake HandleFileEvent.""" def __init__(self, name): super(FakeHandleFileEvent, self).__init__() self.loader = Stub() # FIXME self.name = name self.path = os.path.split(name)[1] self.extraTests = [] class FakeStartTestEvent(_FakeEventBase): """Fake :class:`~nose2.events.StartTestEvent`.""" def __init__(self, test): super(FakeStartTestEvent, self).__init__() self.test = test self.result = test.defaultTestResult() import time self.startTime = time.time() class FakeLoadFromNameEvent(_FakeEventBase): """Fake :class:`~nose2.events.LoadFromNameEvent`.""" def __init__(self, name): super(FakeLoadFromNameEvent, self).__init__() self.name = name class FakeLoadFromNamesEvent(_FakeEventBase): """Fake :class:`~nose2.events.LoadFromNamesEvent`.""" def __init__(self, names): super(FakeLoadFromNamesEvent, self).__init__() self.names = names class FakeStartTestRunEvent(_FakeEventBase): """Fake :class:`~nose2.events.StartTestRunEvent`""" def __init__(self, runner=None, suite=None, result=None, startTime=None, executeTests=None): super(FakeStartTestRunEvent, self).__init__() self.suite = suite self.runner = runner self.result = result self.startTime = startTime self.executeTests = executeTests class Stub(object): """Stub object for use in tests""" def __getattr__(self, attr): return Stub() def __call__(self, *arg, **kw): return Stub() def support_file(*path_parts): return os.path.abspath(os.path.join(SUPPORT, *path_parts)) def run_nose2(*nose2_args, **nose2_kwargs): if 'cwd' in nose2_kwargs: cwd = nose2_kwargs.pop('cwd') if not os.path.isabs(cwd): nose2_kwargs['cwd'] = support_file(cwd) return NotReallyAProc(nose2_args, **nose2_kwargs) def run_module_as_main(test_module, *args): if not os.path.isabs(test_module): test_module = support_file(test_module) return subprocess.Popen([sys.executable, test_module] + list(args), stdout=subprocess.PIPE, stderr=subprocess.PIPE) class NotReallyAProc(object): def __init__(self, args, cwd=None, **kwargs): self.args = args self.chdir = cwd self.kwargs = kwargs self.result = None def __enter__(self): self._stdout = sys.__stdout__ self._stderr = sys.__stderr__ self.cwd = os.getcwd() if self.chdir: os.chdir(self.chdir) self.stdout = sys.stdout = sys.__stdout__ = six.StringIO() self.stderr = sys.stderr = sys.__stderr__ = six.StringIO() return self def __exit__(self, exc_type, exc_val, exc_tb): sys.stdout = sys.__stdout__ = self._stdout sys.stderr = sys.__stderr__ = self._stderr if self.chdir: os.chdir(self.cwd) return False def communicate(self): with self: try: self.result = discover( argv=('nose2',) + self.args, exit=False, **self.kwargs) except SystemExit as e: pass return self.stdout.getvalue(), self.stderr.getvalue() @property def pid(self): return id(self) def poll(self): if self.result is None: return 1 return not self.result.result.wasSuccessful() class RedirectStdStreams(object): """ Context manager that replaces the stdin/stdout streams with :class:`StringIO` buffers. """ def __init__(self): self.stdout = six.StringIO() self.stderr = six.StringIO() def __enter__(self): self.old_stdout, self.old_stderr = sys.stdout, sys.stderr self.old_stdout.flush() self.old_stderr.flush() sys.stdout, sys.stderr = self.stdout, self.stderr return self def __exit__(self, exc_type, exc_value, traceback): self.stdout.flush() self.stderr.flush() sys.stdout = self.old_stdout sys.stderr = self.old_stderr # mock multprocessing Connection class Conn(object): def __init__(self, items): self.items = items self.sent = [] self.closed = False def recv(self): if self.closed: raise EOFError("closed") try: return self.items.pop(0) except: raise EOFError("EOF") def send(self, item): self.sent.append(item) def close(self): self.closed = True nose2-0.6.4/nose2/tools/0000775000175000017500000000000012672050226014343 5ustar travistravisnose2-0.6.4/nose2/tools/__init__.py0000664000175000017500000000023112672050004016442 0ustar travistravisfrom .params import params, cartesian_params from . import such from . import decorators __all__ = ['cartesian_params', 'params', 'such', 'decorators'] nose2-0.6.4/nose2/tools/decorators.py0000664000175000017500000000152512672050004017057 0ustar travistravis""" This module provides decorators that assist the test author to write tests. """ def with_setup(setup): """ A decorator that sets the :func:`setup` method to be executed before the test. It currently works only for function test cases. :param setup: The method to be executed before the test. :type setup: function """ def decorator(testcase): testcase.setup = setup return testcase return decorator def with_teardown(teardown): """ A decorator that sets the :func:`teardown` method to be after before the test. It currently works only for function test cases. :param teardown: The method to be executed after the test. :type teardown: function """ def decorator(testcase): testcase.tearDownFunc = teardown return testcase return decorator nose2-0.6.4/nose2/tools/params.py0000664000175000017500000000325412672050004016176 0ustar travistravis""" This module contains some code copied from :mod:`unittest2` and other code developed in reference to :mod:`unittest2`. unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All Rights Reserved. See: http://docs.python.org/license.html """ import itertools __unittest = True def cartesian_params(*paramList): """Make a test function or method parameterized by cartesian product of parameters .. code-block :: python import unittest from nose2.tools import cartesian_params @cartesian_params((1, 2, 3), ('a', 'b')) def test_nums(num, char): assert num < ord(char) class Test(unittest.TestCase): @cartesian_params((1, 2, 3), ('a', 'b')) def test_less_than(self, num, char): self.assertLess(num, ord(char)) Parameters in the list must be defined as iterable objects (such as ``tuple`` or ``list``). """ def decorator(func): func.paramList = itertools.product(*paramList) return func return decorator def params(*paramList): """Make a test function or method parameterized by parameters. .. code-block :: python import unittest from nose2.tools import params @params(1, 2, 3) def test_nums(num): assert num < 4 class Test(unittest.TestCase): @params((1, 2), (2, 3), (4, 5)) def test_less_than(self, a, b): assert a < b Parameters in the list may be defined as simple values, or as tuples. To pass a tuple as a simple value, wrap it in another tuple. """ def decorator(func): func.paramList = paramList return func return decorator nose2-0.6.4/nose2/tools/such.py0000664000175000017500000003066612672050004015664 0ustar travistravisfrom contextlib import contextmanager import inspect import logging import sys import six from nose2.compat import unittest from nose2 import util from nose2.main import PluggableTestProgram log = logging.getLogger(__name__) __unittest = True LAYERS_PLUGIN_NOT_LOADED_MESSAGE = 'Warning: Such will not function properly if the "nose2.plugins.layers" plugin not loaded!\n' @contextmanager def A(description): """Test scenario context manager. Returns a :class:`nose2.tools.such.Scenario` instance, which by convention is bound to ``it``: .. code-block :: python with such.A('test scenario') as it: # tests and fixtures """ yield Scenario(description) class Helper(unittest.TestCase): def runTest(self): pass helper = Helper() class Scenario(object): """A test scenario. A test scenario defines a set of fixtures and tests that depend on those fixtures. """ _helper = helper def __init__(self, description): self._group = Group('A %s' % description, 0) @contextmanager def having(self, description): """Define a new group under the current group. Fixtures and tests defined within the block will belong to the new group. .. code-block :: python with it.having('a description of this group'): # ... """ last = self._group self._group = self._group.child( "having %s" % description) log.debug("starting new group from %s", description) yield self log.debug("leaving group %s", description) self._group = last def uses(self, layer): log.debug("Adding %s as mixin to %s", layer, self._group) self._group.mixins.append(layer) def has_setup(self, func): """Add a :func:`setup` method to this group. The :func:`setup` method will run once, before any of the tests in the containing group. A group may define any number of :func:`setup` functions. They will execute in the order in which they are defined. .. code-block :: python @it.has_setup def setup(): # ... """ self._group.addSetup(func) return func def has_teardown(self, func): """Add a :func:`teardown` method to this group. The :func:`teardown` method will run once, after all of the tests in the containing group. A group may define any number of :func:`teardown` functions. They will execute in the order in which they are defined. .. code-block :: python @it.has_teardown def teardown(): # ... """ self._group.addTeardown(func) return func def has_test_setup(self, func): """Add a test case :func:`setup` method to this group. The :func:`setup` method will run before each of the tests in the containing group. A group may define any number of test case :func:`setup` functions. They will execute in the order in which they are defined. Test :func:`setup` functions may optionally take one argument. If they do, they will be passed the :class:`unittest.TestCase` instance generated for the test. .. code-block :: python @it.has_test_setup def setup(case): # ... """ self._group.addTestSetUp(func) def has_test_teardown(self, func): """Add a test case :func:`teardown` method to this group. The :func:`teardown` method will run before each of the tests in the containing group. A group may define any number of test case :func:`teardown` functions. They will execute in the order in which they are defined. Test :func:`teardown` functions may optionally take one argument. If they do, they will be passed the :class:`unittest.TestCase` instance generated for the test. .. code-block :: python @it.has_test_teardown def teardown(case): # ... """ self._group.addTestTearDown(func) def should(self, desc): """Define a test case. Each function marked with this decorator becomes a test case in the current group. The decorator takes one optional argument, the description of the test case: what it **should** do. If this argument is not provided, the docstring of the decorated function will be used as the test case description. Test functions may optionally take one argument. If they do, they will be passed the :class:`unittest.TestCase` instance generated for the test. They can use this TestCase instance to execute assert methods, among other things. .. code-block :: python @it.should('do this') def dothis(case): # .... @it.should def dothat(): "do that also" # .... """ def decorator(f): _desc = desc if isinstance(desc, six.string_types) else f.__doc__ case = Case(self._group, f, "should %s" % _desc) self._group.addCase(case) return case if isinstance(desc, type(decorator)): return decorator(desc) return decorator def __getattr__(self, attr): return getattr(self._helper, attr) def createTests(self, mod): """Generate test cases for this scenario. .. warning :: You must call this, passing in :func:`globals`, to generate tests from the scenario. If you don't, **no tests will be created**. .. code-block :: python it.createTests(globals()) """ self._checkForLayersPlugin() self._makeGroupTest(mod, self._group) def _checkForLayersPlugin(self): currentSession = PluggableTestProgram.getCurrentSession() if not currentSession: return if not currentSession.isPluginLoaded('nose2.plugins.layers'): sys.stderr.write(LAYERS_PLUGIN_NOT_LOADED_MESSAGE) def _makeGroupTest(self, mod, group, parent_layer=None, position=0): layer = self._makeLayer(group, parent_layer, position) case = self._makeTestCase(group, layer, parent_layer) log.debug( "Made test case %s with layer %s from %s", case, layer, group) mod[layer.__name__] = layer layer.__module__ = mod['__name__'] name = case.__name__ long_name = ' '.join( [n[0].description for n in util.ancestry(layer)] + [name]) mod[long_name] = case if name not in mod: mod[name] = case case.__module__ = mod['__name__'] for index, child in enumerate(group._children): self._makeGroupTest(mod, child, layer, index) def _makeTestCase(self, group, layer, parent_layer): attr = { 'layer': layer, 'group': group, 'description': group.description, } def _make_test_func(case): ''' Needs to be outside of the for-loop scope, so that ``case`` is properly registered as a closure. ''' def _test(s, *args): case(s, *args) return _test for index, case in enumerate(group._cases): name = 'test %04d: %s' % (index, case.description) _test = _make_test_func(case) _test.__name__ = name _test.description = case.description _test.case = case _test.index = index if hasattr(case.func, 'paramList'): _test.paramList = case.func.paramList attr[name] = _test # for collection and sorting attr[case.description] = _test # for random access by name setups = getattr(parent_layer, 'testSetups', []) + group._test_setups if setups: def setUp(self): for func in setups: args, _, _, _ = inspect.getargspec(func) if args: func(self) else: func() attr['setUp'] = setUp teardowns = getattr(parent_layer, 'testTeardowns', []) + group._test_teardowns[:] if teardowns: def tearDown(self): for func in teardowns: args, _, _, _ = inspect.getargspec(func) if args: func(self) else: func() attr['tearDown'] = tearDown def methodDescription(self): return getattr(self, self._testMethodName).description attr['methodDescription'] = methodDescription return type(group.description, (unittest.TestCase,), attr) def _makeLayer(self, group, parent_layer=None, position=0): if parent_layer is None: parent_layer = object def setUp(cls): for func in cls.setups: args, _, _, _ = inspect.getargspec(func) if args: func(self) else: func() def tearDown(cls): for func in cls.teardowns: args, _, _, _ = inspect.getargspec(func) if args: func(self) else: func() attr = { 'description': group.description, 'setUp': classmethod(setUp), 'tearDown': classmethod(tearDown), 'setups': group._setups[:], 'testSetups': getattr(parent_layer, 'testSetups', []) + group._test_setups, 'teardowns': group._teardowns[:], 'testTeardowns': getattr(parent_layer, 'testTeardowns', []) + group._test_teardowns[:], 'position': position, 'mixins': () } if group.base_layer: # inject this layer into the group class list # by making it a subclass of parent_layer layer = group.base_layer if parent_layer not in layer.__bases__: layer.mixins = (parent_layer,) else: layer = type("%s:layer" % group.description, (parent_layer,), attr) if group.mixins: layer.mixins = getattr(layer, 'mixins', ()) + tuple(group.mixins) log.debug("made layer %s with bases %s and mixins %s", layer, layer.__bases__, layer.mixins) return layer class Group(object): """A group of tests, with common fixtures and description""" def __init__(self, description, indent=0, parent=None, base_layer=None): self.description = description self.indent = indent self.parent = parent self.base_layer = base_layer self.mixins = [] self._cases = [] self._setups = [] self._teardowns = [] self._test_setups = [] self._test_teardowns = [] self._children = [] def addCase(self, case): if not self._cases: case.first = True case.indent = self.indent self._cases.append(case) def addSetup(self, func): self._setups.append(func) def addTeardown(self, func): self._teardowns.append(func) def addTestSetUp(self, func): self._test_setups.append(func) def addTestTearDown(self, func): self._test_teardowns.append(func) def fullDescription(self): d = [] p = self.parent while p: d.insert(0, p.description) p = p.parent d.append(self.description) return ' '.join(d) def child(self, description, base_layer=None): child = Group(description, self.indent + 1, self, base_layer) self._children.append(child) return child class Case(object): """Information about a test case""" _helper = helper def __init__(self, group, func, description): self.group = group self.func = func self.description = description self._setups = [] self._teardowns = [] self.first = False self.full = False def __call__(self, testcase, *args): # ... only if it takes an arg self._helper = testcase funcargs, _, _, _ = inspect.getargspec(self.func) if funcargs: self.func(testcase, *args) else: self.func() def __getattr__(self, attr): return getattr(self._helper, attr) nose2-0.6.4/nose2/__init__.py0000664000175000017500000000004612672050004015306 0ustar travistravisfrom nose2.main import discover, main nose2-0.6.4/nose2/__main__.py0000664000175000017500000000030312672050004015263 0ustar travistravis"""Main entry point""" import sys if sys.argv[0].endswith("__main__.py"): sys.argv[0] = "nose2" __unittest = True if __name__ == '__main__': from nose2 import discover discover() nose2-0.6.4/nose2/collector.py0000664000175000017500000000171512672050004015541 0ustar travistravisimport sys import unittest from nose2 import loader, runner, session from nose2.main import PluggableTestProgram __unittest = True def collector(): class Test(unittest.TestCase): def run(self, result_): ok = self._collector(result_) sys.exit(not ok) def _get_objects(self): ssn = session.Session() ldr = loader.PluggableTestLoader(ssn) rnr = runner.PluggableTestRunner(ssn) return ssn, ldr, rnr def _collector(self, result_): ssn, ldr, rnr = self._get_objects() ssn.testLoader = ldr ssn.loadConfigFiles('unittest.cfg', 'nose2.cfg', 'setup.cfg') ssn.setStartDir() ssn.prepareSysPath() ssn.loadPlugins(PluggableTestProgram.defaultPlugins) test = ldr.loadTestsFromNames([], None) rslt = rnr.run(test) return rslt.wasSuccessful() return Test('_collector') nose2-0.6.4/nose2/compat.py0000664000175000017500000000121612672050004015032 0ustar travistravis"""unittest/unittest2 compatibility wrapper. Anything internal to nose2 *must* import unittest from here to be certain that it is using unittest2 when run on older Python versions. Yes:: from nose2.compat import unittest **NO**:: import unittest **NO**:: import unittest2 """ try: import unittest2 as unittest except ImportError: import unittest try: unittest.installHandler except AttributeError: raise ImportError( "Built-in unittest version too old; unittest2 is required") __unittest = True try: from collections import OrderedDict except ImportError: from .backports.ordereddict import OrderedDict nose2-0.6.4/nose2/config.py0000664000175000017500000000431312672050004015015 0ustar travistravisTRUE_VALS = set(['1', 't', 'true', 'on', 'yes', 'y']) __unittest = True class Config(object): """Configuration for a plugin or other entities. Encapsulates configuration for a single plugin or other element. Corresponds to a :class:`ConfigParser.Section` but provides an extended interface for extracting items as a certain type. """ def __init__(self, items): self._items = items self._mvd = {} for k, v in items: self._mvd.setdefault(k, []).append(v) def __getitem__(self, key): return self._mvd[key] def as_bool(self, key, default=None): """Get key value as boolean 1, t, true, on, yes and y (case insensitive) are accepted as ``True`` values. All other values are ``False``. """ try: val = self._mvd[key][0].strip() except KeyError: return default except IndexError: # setting = -> False return False return val.lower() in TRUE_VALS def as_int(self, key, default=None): """Get key value as integer""" return self._cast(key, int, default) def as_float(self, key, default=None): """Get key value as float""" return self._cast(key, float, default) def as_str(self, key, default=None): """Get key value as str""" return self._cast(key, str, default) def as_list(self, key, default=None): """Get key value as list. The value is split into lines and returned as a list. Lines are stripped of whitespace, and lines beginning with # are skipped. """ lines = [] try: vlist = self[key] except KeyError: return default for val in vlist: lines.extend( line.strip() for line in val.splitlines() if line.strip() and not line.strip().startswith('#')) return lines def get(self, key, default=None): """Get key value""" return self.as_str(key, default) def _cast(self, key, type_, default): try: return type_(self._mvd[key][0].strip()) except (KeyError, IndexError): return default nose2-0.6.4/nose2/events.py0000664000175000017500000010024412672050004015054 0ustar travistravis# Adapted from unittest2/events.py from the unittest2 plugins branch. # This module contains some code copied from unittest2/events.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import logging import argparse import six from nose2 import config, util log = logging.getLogger(__name__) __unittest = True # FIXME decide on a real rule for camelCase vs under_score and stick with it. # XXX I'd rather move this stuff to Plugin.__init__ and # have __init__ call self.configure() or something after the # initial setup, but that would further break compatibilty # with the unittest2 plugins branch Plugin class. class PluginMeta(type): def __call__(cls, *args, **kwargs): session = kwargs.pop('session', None) instance = object.__new__(cls, *args, **kwargs) instance.session = session instance.config = config.Config([]) config_section = getattr(instance, 'configSection', None) switch = getattr(instance, 'commandLineSwitch', None) if session is not None and config_section is not None: instance.config = session.get(config_section) always_on = instance.config.as_bool( 'always-on', default=instance.alwaysOn) instance.__init__(*args, **kwargs) if always_on: instance.register() else: if switch is not None: short_opt, long_opt, help = switch instance.addOption( instance._register_cb, short_opt, long_opt, help) return instance class Plugin(six.with_metaclass(PluginMeta)): """Base class for nose2 plugins All nose2 plugins must subclass this class. .. attribute :: session The :class:`nose2.session.Session` under which the plugin has been loaded. .. attribute :: config The :class:`nose2.config.Config` representing the plugin's config section as loaded from the session's config files. .. attribute :: commandLineSwitch A tuple of (short opt, long opt, help text) that defines a command line flag that activates this plugin. The short opt may be ``None``. If defined, it must be a single upper-case character. Both short and long opt must *not* start with dashes. Example:: commandLineSwitch = ('B', 'buffer-output', 'Buffer output during tests') .. attribute :: configSection The name config file section to load into this plugin's config. .. attribute :: alwaysOn If this plugin should automatically register itself, set alwaysOn to ``True``. Default is ``False``. .. note :: Plugins that use config values from config files and want to use the nose2 sphinx extension to automatically generate documentation *must* extract all config values from ``self.config`` in ``__init__``. Otherwise the extension will not be able to detect the config keys that the plugin uses. """ alwaysOn = False registered = False def register(self): """Register with appropriate hooks. This activates the plugin and enables it to receive events. """ if self.session is None: log.warning("Unable to register %s, no session", self) return self.session.registerPlugin(self) self.registered = True def addMethods(self, *methods): """Add new plugin methods to hooks registry Any plugins that are already registered and implement a method added here will be registered for that method as well. """ for method in methods: self.session.hooks.addMethod(method) for plugin in self.session.plugins: for method in methods: if plugin.registered and hasattr(plugin, method): self.session.hooks.register(method, plugin) def _register_cb(self, *_): self.register() def addFlag(self, callback, short_opt, long_opt, help_text=None): """Add command-line flag that takes no arguments :param callback: Callback function to run when flag is seen. The callback will receive one empty argument. :param short_opt: Short option. Must be uppercase, no dashes. :param long_opt: Long option. Must not start with dashes :param help_text: Help text for users so they know what this flag does. """ self.addOption(callback, short_opt, long_opt, help_text, nargs=0) def addArgument(self, callback, short_opt, long_opt, help_text=None): """Add command-line option that takes one argument. :param callback: Callback function to run when flag is seen. The callback will receive one argument. :param short_opt: Short option. Must be uppercase, no dashes. :param long_opt: Long option. Must not start with dashes :param help_text: Help text for users so they know what this flag does. """ self.addOption(callback, short_opt, long_opt, help_text, nargs=1) def addOption(self, callback, short_opt, long_opt, help_text=None, nargs=0): """Add command-line option. :param callback: Callback function to run when flag is seen. The callback will receive one argument. The "callback" may also be a list, in which case values submitted on the command line will be appended to the list. :param short_opt: Short option. Must be uppercase, no dashes. :param long_opt: Long option. Must not start with dashes :param help_text: Help text for users so they know what this flag does. :param nargs: Number of arguments to consume from command line. """ if self.session is None: log.warning("Unable to add option %s/%s for %s, no session", short_opt, long_opt, self) return class CB(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): if six.callable(callback): callback(values) elif isinstance(callback, list): callback.extend(values) else: raise ValueError( "Invalid callback %s for plugin option %s", callback, option_string) opts = [] if short_opt: if short_opt.lower() == short_opt: raise ValueError( 'Lowercase short options are reserved: %s' % short_opt) opts.append('-' + short_opt) if long_opt: opts.append('--' + long_opt) self.session.pluginargs.add_argument( *opts, action=CB, help=help_text, const=True, nargs=nargs) class Hook(object): """A plugin hook Each plugin method in the :class:`nose2.events.PluginInterface` is represented at runtime by a Hook instance that lists the plugins that should be called by that hook. .. attribute :: method The name of the method that this Hook represents. .. attribute :: plugins The list of plugin instances bound to this hook. """ def __init__(self, method): self.method = method self.plugins = [] def __call__(self, event): for plugin in self.plugins[:]: result = getattr(plugin, self.method)(event) if event.handled: return result def append(self, plugin): if plugin not in self.plugins: self.plugins.append(plugin) class PluginInterface(object): """Definition of plugin interface. Instances of this class contain the methods that may be called, and a dictionary of :class:`nose2.events.Hook` instances bound to each method. In a plugin, PluginInterface instance is typically available as self.session.hooks, and plugin hooks may be called on it directly:: event = events.LoadFromModuleEvent(module=the_module) self.session.hooks.loadTestsFromModule(event) .. attribute :: preRegistrationMethods Tuple of methods that are called before registration. .. attribute :: methods Tuple of available plugin hook methods. .. attribute :: hookClass Class to instantiate for each hook. Default: :class:`nose2.events.Hook`. """ preRegistrationMethods = ('pluginsLoaded', 'handleArgs') methods = ( 'loadTestsFromModule', 'loadTestsFromNames', 'handleFile', 'startTestRun', 'startTest', 'stopTest', 'loadTestsFromName', 'loadTestsFromTestCase', 'stopTestRun', 'matchPath', 'matchDirPath', 'getTestCaseNames', 'runnerCreated', 'resultCreated', 'testOutcome', 'wasSuccessful', 'resultStop', 'setTestOutcome', 'describeTest', 'reportStartTest', 'reportError', 'reportFailure', 'reportSkip', 'reportSuccess', 'reportExpectedFailure', 'reportUnexpectedSuccess', 'reportOtherOutcome', 'outcomeDetail', 'beforeErrorList', 'beforeSummaryReport', 'afterSummaryReport', 'beforeInteraction', 'afterInteraction', 'createTests', 'createdTestSuite', 'afterTestRun', 'moduleLoadedSuite', 'handleDir', # ... etc? ) hookClass = Hook def __init__(self): self.hooks = {} def addMethod(self, method): """Add a method to the available method. This allows plugins to register for this method. :param method: A method name """ self.methods = self.methods + (method,) def register(self, method, plugin): """Register a plugin for a method. :param method: A method name :param plugin: A plugin instance """ self.hooks.setdefault(method, self.hookClass(method)).append(plugin) def __getattr__(self, attr): return self.hooks.setdefault(attr, self.hookClass(attr)) class Event(object): """Base class for all events. .. attribute :: metadata Storage for arbitrary information attached to an event. .. attribute :: handled Set to ``True`` to indicate that a plugin has handled the event, and no other plugins or core systems should process it further. .. attribute :: version Version of the event API. This will be incremented with each release of nose2 that changes the API. """ _attrs = ('handled',) version = '0.4' def __init__(self, **metadata): self.handled = False self.metadata = {} self.metadata.update(metadata) def __str__(self): return '%s(%s)' % (self.__class__.__name__, self._format()) def __repr__(self): return str(self) def _format(self): return ', '.join(['%s=%r' % (k, getattr(self, k, None)) for k in self._attrs]) def __getstate__(self): state = self.__dict__ # FIXME fails for loadTestsFailure if 'test' in state: state['test'] = util.test_name(state['test']) if 'executeTests' in state: state['executeTests'] = None if 'exc_info' in state and state['exc_info'] is not None: ec, ev, tb = state['exc_info'] state['exc_info'] = ( ec, ev, util.format_traceback(None, (ec, ev, tb))) clear = ('loader', 'result', 'runner') for attr in clear: if attr in state: state[attr] = None return state class PluginsLoadedEvent(Event): """Event fired after all plugin classes are loaded. .. attribute :: pluginsLoaded List of all loaded plugin classes """ _attrs = Event._attrs + ('pluginsLoaded',) def __init__(self, pluginsLoaded, **kw): self.pluginsLoaded = pluginsLoaded super(PluginsLoadedEvent, self).__init__(**kw) class RunnerCreatedEvent(Event): """Event fired when test runner is created. .. attribute :: runner Test runner instance. Plugins may replace the test runner by setting this attribute to a new test runner instance. """ _attrs = Event._attrs + ('runner',) def __init__(self, runner, **kw): self.runner = runner super(RunnerCreatedEvent, self).__init__(**kw) class ResultCreatedEvent(Event): """Event fired when test result handler is created. .. attribute :: result Test result handler instance. Plugins may replace the test result by setting this attribute to a new test result instance. """ _attrs = Event._attrs + ('result',) def __init__(self, result, **kw): self.result = result super(ResultCreatedEvent, self).__init__(**kw) class StartTestRunEvent(Event): """Event fired when test run is about to start. Test collection is complete before this event fires, but no tests have yet been executed. .. attribute :: runner Test runner .. attribute :: suite Top-level test suite to execute. Plugins can filter this suite, or set event.suite to change which tests execute (or how they execute). .. attribute :: result Test result .. attribute :: startTime Timestamp of test run start .. attribute :: executeTests Callable that will be used to execute tests. Plugins may set this attribute to wrap or otherwise change test execution. The callable must match the signature:: def execute(suite, result): ... To prevent normal test execution, plugins may set ``handled`` on this event to ``True``. When ``handled`` is true, the test executor does not run at all. """ _attrs = Event._attrs + ('runner', 'suite', 'result', 'startTime', 'executeTests') def __init__(self, runner, suite, result, startTime, executeTests, **kw): self.suite = suite self.runner = runner self.result = result self.startTime = startTime self.executeTests = executeTests super(StartTestRunEvent, self).__init__(**kw) class StopTestRunEvent(Event): """Event fired when test run has stopped. .. attribute :: runner Test runner .. attribute :: result Test result .. attribute :: stopTime Timestamp of test run stop .. attribute :: timeTaken Number of seconds test run took to execute """ _attrs = Event._attrs + ('runner', 'result', 'stopTime', 'timeTaken') def __init__(self, runner, result, stopTime, timeTaken, **kw): self.runner = runner self.result = result self.stopTime = stopTime self.timeTaken = timeTaken super(StopTestRunEvent, self).__init__(**kw) class StartTestEvent(Event): """Event fired before a test is executed. .. attribute :: test The test case .. attribute :: result Test result .. attribute :: startTime Timestamp of test start """ _attrs = Event._attrs + ('test', 'result', 'startTime') def __init__(self, test, result, startTime, **kw): self.test = test self.result = result self.startTime = startTime super(StartTestEvent, self).__init__(**kw) class StopTestEvent(Event): """Event fired after a test is executed. .. attribute :: test The test case .. attribute :: result Test result .. attribute :: stopTime Timestamp of test stop """ _attrs = Event._attrs + ('test', 'result', 'stopTime') def __init__(self, test, result, stopTime, **kw): self.test = test self.result = result self.stopTime = stopTime super(StopTestEvent, self).__init__(**kw) class TestOutcomeEvent(Event): """Event fired when a test completes. .. attribute :: test The test case .. attribute :: result Test result .. attribute :: outcome Description of test outcome. Typically will be one of 'error', 'failed', 'skipped', or 'passed'. .. attribute :: exc_info If the test resulted in an exception, the tuple of (exception class, exception value, traceback) as returned by ``sys.exc_info()``. If the test did not result in an exception, ``None``. .. attribute :: reason For test outcomes that include a reason (``Skips``, for example), the reason. .. attribute :: expected Boolean indicating whether the test outcome was expected. In general, all tests are expected to pass, and any other outcome will have expected as ``False``. The exceptions to that rule are unexpected successes and expected failures. .. attribute :: shortLabel A short label describing the test outcome. (For example, 'E' for errors). .. attribute :: longLabel A long label describing the test outcome (for example, 'ERROR' for errors). Plugins may influence how the rest of the system sees the test outcome by setting ``outcome`` or ``exc_info`` or ``expected``. They may influence how the test outcome is reported to the user by setting ``shortLabel`` or ``longLabel``. """ _attrs = Event._attrs + ('test', 'result', 'outcome', 'exc_info', 'reason', 'expected', 'shortLabel', 'longLabel') def __init__(self, test, result, outcome, exc_info=None, reason=None, expected=False, shortLabel=None, longLabel=None, **kw): self.test = test self.result = result self.outcome = outcome self.exc_info = exc_info self.reason = reason self.expected = expected self.shortLabel = shortLabel self.longLabel = longLabel super(TestOutcomeEvent, self).__init__(**kw) class LoadFromModuleEvent(Event): """Event fired when a test module is loaded. .. attribute :: loader Test loader instance .. attribute :: module The module whose tests are to be loaded .. attribute :: extraTests A list of extra tests loaded from the module. To load tests from a module without interfering with other plugins' loading activities, append tests to extraTests. Plugins may set ``handled`` on this event and return a test suite to prevent other plugins from loading tests from the module. If any plugin sets ``handled`` to ``True``, ``extraTests`` will be ignored. """ _attrs = Event._attrs + ('loader', 'module', 'extraTests') def __init__(self, loader, module, **kw): self.loader = loader self.module = module self.extraTests = [] super(LoadFromModuleEvent, self).__init__(**kw) class ModuleSuiteEvent(Event): _attrs = Event._attrs + ('loader', 'module', 'suite') def __init__(self, loader, module, suite, **kw): self.loader = loader self.module = module self.suite = suite super(ModuleSuiteEvent, self).__init__(**kw) class LoadFromTestCaseEvent(Event): """Event fired when tests are loaded from a test case. .. attribute :: loader Test loader instance .. attribute :: testCase The :class:`unittest.TestCase` instance being loaded. .. attribute :: extraTests A list of extra tests loaded from the module. To load tests from a test case without interfering with other plugins' loading activities, append tests to extraTests. Plugins may set ``handled`` on this event and return a test suite to prevent other plugins from loading tests from the test case. If any plugin sets ``handled`` to ``True``, ``extraTests`` will be ignored. """ _attrs = Event._attrs + ('loader', 'testCase', 'extraTests') def __init__(self, loader, testCase, **kw): self.loader = loader self.testCase = testCase self.extraTests = [] super(LoadFromTestCaseEvent, self).__init__(**kw) class LoadFromNamesEvent(Event): """Event fired to load tests from test names. .. attribute :: loader Test loader instance .. attribute :: names List of test names. May be empty or ``None``. .. attribute :: module Module to load from. May be ``None``. If not ``None``, names should be considered relative to this module. .. attribute :: extraTests A list of extra tests loaded from the tests named. To load tests from test names without interfering with other plugins' loading activities, append tests to extraTests. Plugins may set ``handled`` on this event and return a test suite to prevent other plugins from loading tests from the test names. If any plugin sets ``handled`` to ``True``, ``extraTests`` will be ignored. """ _attrs = Event._attrs + ('loader', 'names', 'module', 'extraTests') def __init__(self, loader, names, module, **kw): self.loader = loader self.names = names self.module = module self.extraTests = [] super(LoadFromNamesEvent, self).__init__(**kw) def __str__(self): return "LoadFromNames(names=%r, module=%r)" % (self.names, self.module) class LoadFromNameEvent(Event): """Event fired to load tests from test names. .. attribute :: loader Test loader instance .. attribute :: name Test name to load .. attribute :: module Module to load from. May be ``None``. If not ``None``, names should be considered relative to this module. .. attribute :: extraTests A list of extra tests loaded from the name. To load tests from a test name without interfering with other plugins' loading activities, append tests to extraTests. Plugins may set ``handled`` on this event and return a test suite to prevent other plugins from loading tests from the test name. If any plugin sets ``handled`` to ``True``, ``extraTests`` will be ignored. """ _attrs = Event._attrs + ('loader', 'name', 'module', 'extraTests') def __init__(self, loader, name, module, **kw): self.loader = loader self.name = name self.module = module self.extraTests = [] super(LoadFromNameEvent, self).__init__(**kw) class HandleFileEvent(Event): """Event fired when a non-test file is examined. .. note :: This event is fired for all processed python files and modules including but not limited to the ones that match the test file pattern. .. attribute :: loader Test loader instance .. attribute :: name File basename .. attribute :: path Full path to file .. attribute :: pattern Current test file match pattern .. attribute :: topLevelDirectory Top-level directory of the test run .. attribute :: extraTests A list of extra tests loaded from the file. To load tests from a file without interfering with other plugins' loading activities, append tests to extraTests. Plugins may set ``handled`` on this event and return a test suite to prevent other plugins from loading tests from the file. If any plugin sets ``handled`` to ``True``, ``extraTests`` will be ignored. """ _attrs = Event._attrs + ('loader', 'name', 'path', 'pattern', 'topLevelDirectory') def __init__(self, loader, name, path, pattern, topLevelDirectory, **kw): self.extraTests = [] self.path = path self.loader = loader self.name = name # note: pattern may be None if not called during test discovery self.pattern = pattern self.topLevelDirectory = topLevelDirectory super(HandleFileEvent, self).__init__(**kw) class MatchPathEvent(Event): """Event fired during file matching. Plugins may return ``False`` and set ``handled`` on this event to prevent a file from being matched as a test file, regardless of other system settings. .. attribute :: path Full path to the file .. attribute :: name File basename .. attribute :: pattern Current test file match pattern """ _attrs = Event._attrs + ('name', 'path', 'pattern') def __init__(self, name, path, pattern, **kw): self.path = path self.name = name self.pattern = pattern super(MatchPathEvent, self).__init__(**kw) class GetTestCaseNamesEvent(Event): """Event fired to find test case names in a test case. Plugins may return a list of names and set ``handled`` on this event to force test case name selection. .. attribute :: loader Test loader instance .. attribute :: testCase The :class:`unittest.TestCase` instance being loaded. .. attribute :: testMethodPrefix Set this to change the test method prefix. Unless set by a plugin, it is ``None``. .. attribute :: extraNames A list of extra test names to load from the test case. To cause extra tests to be loaded from the test case, append the names to this list. Note that the names here must be attributes of the test case. .. attribute :: excludedNames A list of names to exclude from test loading. Add names to this list to prevent other plugins from loading the named tests. .. attribute :: isTestMethod Callable that plugins can use to examine test case attributes to determine whether nose2 thinks they are test methods. """ _attrs = Event._attrs + ('loader', 'testCase', 'testMethodPrefix', 'extraNames', 'excludedNames', 'isTestMethod') def __init__(self, loader, testCase, isTestMethod, **kw): self.loader = loader self.testCase = testCase self.testMethodPrefix = None self.extraNames = [] self.excludedNames = [] self.isTestMethod = isTestMethod super(GetTestCaseNamesEvent, self).__init__(**kw) class ResultSuccessEvent(Event): """Event fired at end of test run to determine success. This event fires at the end of the test run and allows plugins to determine whether the test run was successful. .. attribute :: result Test result .. attribute :: success Set this to ``True`` to indicate that the test run was successful. If no plugin sets the ``success`` to ``True``, the test run fails. """ _attrs = Event._attrs + ('result', 'success') def __init__(self, result, success, **kw): self.result = result self.success = success super(ResultSuccessEvent, self).__init__(**kw) class ResultStopEvent(Event): """Event fired when a test run is told to stop. Plugins can use this event to prevent other plugins from stopping a test run. .. attribute :: result Test result .. attribute :: shouldStop Set to ``True`` to indicate that the test run should stop. """ _attrs = Event._attrs + ('result', 'shouldStop') def __init__(self, result, shouldStop, **kw): self.result = result self.shouldStop = shouldStop super(ResultStopEvent, self).__init__(**kw) class DescribeTestEvent(Event): """Event fired to get test description. .. attribute :: test The test case .. attribute :: description Description of the test case. Plugins can set this to change how tests are described in output to users. .. attribute :: errorList Is the event fired as part of error list output? """ _attrs = Event._attrs + ('test', 'description') def __init__(self, test, description=None, errorList=False, **kw): self.test = test self.description = description self.errorList = errorList super(DescribeTestEvent, self).__init__(**kw) class OutcomeDetailEvent(Event): """Event fired to acquire additional details about test outcome. .. attribute :: outcomeEvent A :class:`nose2.events.TestOutcomeEvent` instance holding the test outcome to be described. .. attribute :: extraDetail Extra detail lines to be appended to test outcome output. Plugins can append lines (of strings) to this list to include their extra information in the error list report. """ _attrs = Event._attrs + ('outcomeEvent', 'extraDetail') def __init__(self, outcomeEvent, **kw): self.outcomeEvent = outcomeEvent self.extraDetail = [] super(OutcomeDetailEvent, self).__init__(**kw) class ReportSummaryEvent(Event): """Event fired before and after summary report. .. attribute :: stopTestEvent A :class:`nose2.events.StopTestEvent` instance. .. attribute :: stream The output stream. Plugins can set this to change or capture output. .. attribute :: reportCategories Dictionary of report category and test events captured in that category. Default categories include 'errors', 'failures', 'skipped', 'expectedFails', and 'unexpectedSuccesses'. Plugins may add their own categories. """ _attrs = Event._attrs + ('stopTestEvent', 'stream', 'reportCategories') def __init__(self, stopTestEvent, stream, reportCategories, **kw): self.stopTestEvent = stopTestEvent self.stream = stream self.reportCategories = reportCategories super(ReportSummaryEvent, self).__init__(**kw) class ReportTestEvent(Event): """Event fired to report a test event. Plugins can respond to this event by producing output for the user. .. attribute :: testEvent A test event. In most cases, a :class:`nose2.events.TestOutcomeEvent` instance. For startTest, a :class:`nose2.events.StartTestEvent` instance. .. attribute :: stream The output stream. Plugins can set this to change or capture output. """ _attrs = Event._attrs + ('testEvent', 'stream') def __init__(self, testEvent, stream, **kw): self.testEvent = testEvent self.stream = stream super(ReportTestEvent, self).__init__(**kw) class UserInteractionEvent(Event): """Event fired before and after user interaction. Plugins that capture stdout or otherwise prevent user interaction should respond to this event. To prevent the user interaction from occurring, return ``False`` and set ``handled``. Otherwise, turn off whatever you are doing that prevents users from typing/clicking/touching/psionics/whatever. """ def __init__(self, **kw): super(UserInteractionEvent, self).__init__(**kw) class CommandLineArgsEvent(Event): """Event fired after parsing of command line arguments. Plugins can respond to this event by configuring themselves or other plugins or modifying the parsed arguments. .. note :: Many plugins register options with callbacks. By the time this event fires, those callbacks have already fired. So you can't use this event to reliably influence all plugins. .. attribute :: args Args object returned by argparse. """ _attrs = Event._attrs + ('args',) def __init__(self, args, **kw): self.args = args super(CommandLineArgsEvent, self).__init__(**kw) class CreateTestsEvent(Event): """Event fired before test loading. Plugins can take over test loading by returning a test suite and setting ``handled`` on this event. .. attribute :: loader Test loader instance .. attribute :: names List of test names. May be empty or ``None``. .. attribute :: module Module to load from. May be ``None``. If not ``None``, names should be considered relative to this module. """ _attrs = Event._attrs + ('loader', 'testNames', 'module') def __init__(self, loader, testNames, module, **kw): self.loader = loader self.testNames = testNames self.module = module super(CreateTestsEvent, self).__init__(**kw) class CreatedTestSuiteEvent(Event): """Event fired after test loading. Plugins can replace the loaded test suite by returning a test suite and setting ``handled`` on this event. .. attribute :: suite Test Suite instance """ _attrs = Event._attrs + ('suite', ) def __init__(self, suite, **kw): self.suite = suite super(CreatedTestSuiteEvent, self).__init__(**kw) nose2-0.6.4/nose2/exceptions.py0000664000175000017500000000053512672050004015733 0ustar travistravis# This module contains some code copied from unittest2/ and other code # developed in reference to unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html __unittest = True class TestNotFoundError(Exception): """Raised when a named test cannot be found""" nose2-0.6.4/nose2/loader.py0000664000175000017500000001041412672050004015015 0ustar travistravis# Adapted from unittest2/loader.py from the unittest2 plugins branch. # This module contains some code copied from unittest2/loader.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import logging import traceback import six from nose2 import events from nose2.compat import unittest log = logging.getLogger(__name__) __unittest = True class PluggableTestLoader(object): """Test loader that defers all loading to plugins :param session: Test run session. .. attribute :: suiteClass Suite class to use. Default: :class:`unittest.TestSuite`. """ suiteClass = unittest.TestSuite def __init__(self, session): self.session = session def loadTestsFromModule(self, module): """Load tests from module. Fires :func:`loadTestsFromModule` hook. """ evt = events.LoadFromModuleEvent(self, module) result = self.session.hooks.loadTestsFromModule(evt) if evt.handled: suite = result or self.suiteClass() else: suite = self.suiteClass(evt.extraTests) filterevt = events.ModuleSuiteEvent(self, module, suite) result = self.session.hooks.moduleLoadedSuite(filterevt) if result: return result or self.suiteClass() return filterevt.suite def loadTestsFromNames(self, testNames, module=None): """Load tests from test names. Fires :func:`loadTestsFromNames` hook. """ event = events.LoadFromNamesEvent( self, testNames, module) result = self.session.hooks.loadTestsFromNames(event) log.debug('loadTestsFromNames event %s result %s', event, result) if event.handled: suites = result or [] else: if event.names: suites = [self.loadTestsFromName(name, module) for name in event.names] elif module: suites = self.loadTestsFromModule(module) if event.extraTests: suites.extend(event.extraTests) return self.suiteClass(suites) def loadTestsFromName(self, name, module=None): """Load tests from test name. Fires :func:`loadTestsFromName` hook. """ log.debug('loadTestsFromName %s/%s', name, module) event = events.LoadFromNameEvent(self, name, module) result = self.session.hooks.loadTestsFromName(event) if event.handled: suite = result or self.suiteClass() return suite return self.suiteClass(event.extraTests) def failedImport(self, name): """Make test case representing a failed import.""" message = 'Failed to import test module: %s' % name if hasattr(traceback, 'format_exc'): # Python 2.3 compatibility # format_exc returns two frames of discover.py as well XXX ? message += '\n%s' % traceback.format_exc() return self._makeFailedTest( 'ModuleImportFailure', name, ImportError(message)) def failedLoadTests(self, name, exception): """Make test case representing a failed test load.""" return self._makeFailedTest('LoadTestsFailure', name, exception) def sortTestMethodsUsing(self, name): """Sort key for test case test methods.""" return name.lower() def discover(self, start_dir=None, pattern=None): """Compatibility shim for ``load_tests`` protocol.""" try: oldsd = self.session.startDir self.session.startDir = start_dir return self.loadTestsFromNames([]) finally: self.session.startDir = oldsd def _makeFailedTest(self, classname, methodname, exception): def testFailure(self): if isinstance(exception, Exception): raise exception else: # exception tuple (type, value, traceback) six.reraise(*exception) attrs = {methodname: testFailure} TestClass = type(classname, (unittest.TestCase,), attrs) return self.suiteClass((TestClass(methodname),)) def __repr__(self): return '<%s>' % self.__class__.__name__ nose2-0.6.4/nose2/main.py0000664000175000017500000002667512672050004014513 0ustar travistravisimport logging import os import sys from nose2.compat import unittest from nose2 import events, loader, runner, session, util log = logging.getLogger(__name__) __unittest = True class PluggableTestProgram(unittest.TestProgram): """TestProgram that enables plugins. Accepts the same parameters as :class:`unittest.TestProgram`, but most of them are ignored as their functions are handled by plugins. :param module: Module in which to run tests. Default: :func:`__main__` :param defaultTest: Default test name. Default: ``None`` :param argv: Command line args. Default: ``sys.argv`` :param testRunner: *IGNORED* :param testLoader: *IGNORED* :param exit: Exit after running tests? :param verbosity: Base verbosity :param failfast: *IGNORED* :param catchbreak: *IGNORED* :param buffer: *IGNORED* :param plugins: List of additional plugin modules to load :param excludePlugins: List of plugin modules to exclude :param extraHooks: List of hook names and plugin *instances* to register with the session's hooks system. Each item in the list must be a 2-tuple of (hook name, plugin instance) .. attribute :: sessionClass The class to instantiate to create a test run configuration session. Default: :class:`nose2.session.Session` .. attribute :: loaderClass The class to instantiate to create a test loader. Default: :class:`nose2.loader.PluggableTestLoader`. .. warning :: Overriding this attribute is the only way to customize the test loader class. Passing a test loader to :func:`__init__` does not work. .. attribute :: runnerClass The class to instantiate to create a test runner. Default: :class:`nose2.runner.PluggableTestRunner`. .. warning :: Overriding this attribute is the only way to customize the test runner class. Passing a test runner to :func:`__init__` does not work. .. attribute :: defaultPlugins List of default plugin modules to load. """ sessionClass = session.Session _currentSession = None loaderClass = loader.PluggableTestLoader runnerClass = runner.PluggableTestRunner defaultPlugins = ('nose2.plugins.loader.discovery', 'nose2.plugins.loader.testcases', 'nose2.plugins.loader.functions', 'nose2.plugins.loader.testclasses', 'nose2.plugins.loader.generators', 'nose2.plugins.loader.parameters', 'nose2.plugins.loader.loadtests', 'nose2.plugins.dundertest', 'nose2.plugins.coverage', 'nose2.plugins.result', 'nose2.plugins.logcapture', 'nose2.plugins.buffer', 'nose2.plugins.failfast', 'nose2.plugins.debugger', ) excludePlugins = () # XXX override __init__ to warn that testLoader and testRunner are ignored? def __init__(self, **kw): plugins = kw.pop('plugins', []) exclude = kw.pop('excludePlugins', []) hooks = kw.pop('extraHooks', []) self.defaultPlugins = list(self.defaultPlugins) self.excludePlugins = list(self.excludePlugins) self.extraHooks = hooks self.defaultPlugins.extend(plugins) self.excludePlugins.extend(exclude) super(PluggableTestProgram, self).__init__(**kw) def parseArgs(self, argv): """Parse command line args Parses arguments and creates a configuration session, then calls :func:`createTests`. """ self.session = self.sessionClass() self.__class__._currentSession = self.session self.argparse = self.session.argparse # for convenience # XXX force these? or can it be avoided? self.testLoader = self.loaderClass(self.session) self.session.testLoader = self.testLoader # Parse initial arguments like config file paths, verbosity self.setInitialArguments() # FIXME -h here makes processing stop. cfg_args, argv = self.argparse.parse_known_args(argv[1:]) self.handleCfgArgs(cfg_args) # Parse arguments for plugins (if any) and test names self.argparse.add_argument('testNames', nargs='*') # add help arg now so -h will also print plugin opts self.argparse.add_argument('-h', '--help', action='help', help=('Show this help message and exit')) args, argv = self.argparse.parse_known_args(argv) if argv: self.argparse.error("Unrecognized arguments: %s" % ' '.join(argv)) self.handleArgs(args) self.createTests() def setInitialArguments(self): """Set pre-plugin command-line arguments. This set of arguments is parsed out of the command line before plugins are loaded. """ self.argparse.add_argument( '-s', '--start-dir', default=None, help="Directory to start discovery ('.' default)") self.argparse.add_argument( '-t', '--top-level-directory', '--project-directory', help='Top level directory of project (defaults to start dir)') self.argparse.add_argument( '--config', '-c', nargs='?', action='append', default=['unittest.cfg', 'nose2.cfg'], help="Config files to load, if they exist. ('unittest.cfg' " "and 'nose2.cfg' in start directory default)") self.argparse.add_argument( '--no-user-config', action='store_const', dest='user_config', const=False, default=True, help="Do not load user config files") self.argparse.add_argument( '--no-plugins', action='store_const', dest='load_plugins', const=False, default=True, help="Do not load any plugins. Warning: nose2 does not " "do anything if no plugins are loaded") self.argparse.add_argument( '--plugin', action='append', dest='plugins', default=[], help="Load this plugin module.") self.argparse.add_argument( '--exclude-plugin', action='append', dest='exclude_plugins', default=[], help="Do not load this plugin module") self.argparse.add_argument( '--verbose', '-v', action='count', default=0, help="print test case names and statuses") self.argparse.add_argument('--quiet', action='store_const', dest='verbose', const=0) self.argparse.add_argument( '--log-level', default=logging.WARN, help='Set logging level for message logged to console.') def handleCfgArgs(self, cfg_args): """Handle initial arguments. Handle the initial, pre-plugin arguments parsed out of the command line. """ self.session.logLevel = util.parse_log_level(cfg_args.log_level) logging.basicConfig(level=self.session.logLevel) log.debug('logging initialized %s', cfg_args.log_level) if cfg_args.verbose: self.session.verbosity += cfg_args.verbose self.session.startDir = cfg_args.start_dir if cfg_args.top_level_directory: self.session.topLevelDir = cfg_args.top_level_directory self.session.loadConfigFiles(*self.findConfigFiles(cfg_args)) self.session.setStartDir() self.session.prepareSysPath() if cfg_args.load_plugins: self.defaultPlugins.extend(cfg_args.plugins) self.excludePlugins.extend(cfg_args.exclude_plugins) self.loadPlugins() elif cfg_args.plugins or cfg_args.exclude_plugins: log.warn("Both '--no-plugins' and '--plugin' or '--exclude-plugin' " "specified. No plugins were loaded.") def findConfigFiles(self, cfg_args): """Find available config files""" filenames = cfg_args.config[:] proj_opts = ('unittest.cfg', 'nose2.cfg') for fn in proj_opts: if cfg_args.top_level_directory: fn = os.path.abspath( os.path.join(cfg_args.top_level_directory, fn)) filenames.append(fn) if cfg_args.user_config: user_opts = ('~/.unittest.cfg', '~/.nose2.cfg') for fn in user_opts: filenames.append(os.path.expanduser(fn)) return filenames def handleArgs(self, args): """Handle further arguments. Handle arguments parsed out of command line after plugins have been loaded (and injected their argument configuration). """ self.testNames = args.testNames self.session.hooks.handleArgs(events.CommandLineArgsEvent(args=args)) def loadPlugins(self): """Load available plugins :func:`self.defaultPlugins`` and :func:`self.excludePlugins` are passed to the session to alter the list of plugins that will be loaded. This method also registers any (hook, plugin) pairs set in ``self.hooks``. This is a good way to inject plugins that fall outside of the normal loading procedure, for example, plugins that need some runtime information that can't easily be passed to them through the configuration system. """ self.session.loadPlugins(self.defaultPlugins, self.excludePlugins) for method_name, plugin in self.extraHooks: self.session.hooks.register(method_name, plugin) def createTests(self): """Create top-level test suite""" event = events.CreateTestsEvent( self.testLoader, self.testNames, self.module) result = self.session.hooks.createTests(event) if event.handled: test = result else: log.debug("Create tests from %s/%s", self.testNames, self.module) test = self.testLoader.loadTestsFromNames( self.testNames, self.module) event = events.CreatedTestSuiteEvent(test) result = self.session.hooks.createdTestSuite(event) if event.handled: test = result self.test = test def runTests(self): """Run tests""" # fire plugin hook runner = self._makeRunner() try: self.result = runner.run(self.test) except Exception as e: log.exception('Internal Error') sys.stderr.write('Internal Error: runTests aborted: %s\n'%(e)) if self.exit: sys.exit(1) if self.exit: sys.exit(not self.result.wasSuccessful()) def _makeRunner(self): runner = self.runnerClass(self.session) event = events.RunnerCreatedEvent(runner) self.session.hooks.runnerCreated(event) self.session.testRunner = event.runner return event.runner @classmethod def getCurrentSession(cls): """Returns the current session, or ``None`` if no :class:`nose2.session.Session` is running. """ return cls._currentSession main = PluggableTestProgram def discover(*args, **kwargs): """Main entry point for test discovery. Running discover calls :class:`nose2.main.PluggableTestProgram`, passing through all arguments and keyword arguments **except module**: ``module`` is discarded, to force test discovery. """ kwargs['module'] = None return main(*args, **kwargs) nose2-0.6.4/nose2/result.py0000664000175000017500000000750612672050004015075 0ustar travistravisimport time from nose2 import events ERROR = 'error' FAIL = 'failed' SKIP = 'skipped' PASS = 'passed' __unittest = True class PluggableTestResult(object): """Test result that defers to plugins. All test outcome recording and reporting is deferred to plugins, which are expected to implement :func:`startTest`, :func:`stopTest`, :func:`testOutcome`, and :func:`wasSuccessful`. :param session: Test run session. .. attribute :: shouldStop When ``True``, test run should stop before running another test. """ def __init__(self, session): self.session = session self.shouldStop = False def startTest(self, test): """Start a test case. Fires :func:`startTest` hook. """ event = events.StartTestEvent(test, self, time.time()) self.session.hooks.startTest(event) def stopTest(self, test): """Stop a test case. Fires :func:`stopTest` hook. """ event = events.StopTestEvent(test, self, time.time()) self.session.hooks.stopTest(event) def addError(self, test, err): """Test case resulted in error. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, ERROR, err) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event) def addFailure(self, test, err): """Test case resulted in failure. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, FAIL, err) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event) def addSuccess(self, test): """Test case resulted in success. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, PASS, expected=True) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event) def addSkip(self, test, reason): """Test case was skipped. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, SKIP, reason=reason) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event) def addExpectedFailure(self, test, err): """Test case resulted in expected failure. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, FAIL, err, expected=True) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event) def addUnexpectedSuccess(self, test): """Test case resulted in unexpected success. Fires :func:`setTestOutcome` and :func:`testOutcome` hooks. """ event = events.TestOutcomeEvent(test, self, PASS) self.session.hooks.setTestOutcome(event) self.session.hooks.testOutcome(event) def wasSuccessful(self): """Was test run successful? Fires :func:`wasSuccessful` hook, and returns ``event.success``. """ # assume failure; plugins must explicitly declare success try: return self._success except AttributeError: event = events.ResultSuccessEvent(self, False) self.session.hooks.wasSuccessful(event) self._success = event.success return self._success def stop(self): """Stop test run. Fires :func:`resultStop` hook, and sets ``self.shouldStop`` to ``event.shouldStop``. """ event = events.ResultStopEvent(self, True) self.session.hooks.resultStop(event) self.shouldStop = event.shouldStop def __repr__(self): return '<%s>' % self.__class__.__name__ nose2-0.6.4/nose2/runner.py0000664000175000017500000000405712672050004015066 0ustar travistravis# This module contains some code copied from unittest2/runner.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import time from nose2 import events, result __unittest = True class PluggableTestRunner(object): """Test runner that defers most work to plugins. :param session: Test run session .. attribute :: resultClass Class to instantiate to create test result. Default: :class:`nose2.result.PluggableTestResult`. """ resultClass = result.PluggableTestResult def __init__(self, session): self.session = session def run(self, test): """Run tests. :param test: A unittest :class:`TestSuite`` or :class:`TestClass`. :returns: Test result Fires :func:`startTestRun` and :func:`stopTestRun` hooks. """ result = self._makeResult() executor = lambda suite, result: suite(result) startTime = time.time() event = events.StartTestRunEvent( self, test, result, startTime, executor) self.session.hooks.startTestRun(event) # allows startTestRun to modify test suite test = event.suite # ... and test execution executor = event.executeTests try: if not event.handled: executor(test, result) finally: stopTime = time.time() timeTaken = stopTime - startTime event = events.StopTestRunEvent(self, result, stopTime, timeTaken) self.session.hooks.stopTestRun(event) self.session.hooks.afterTestRun(event) return result def _makeResult(self): result = self.resultClass(self.session) event = events.ResultCreatedEvent(result) self.session.hooks.resultCreated(event) self.session.testResult = event.result return event.result def __repr__(self): return '<%s>' % self.__class__.__name__ nose2-0.6.4/nose2/session.py0000664000175000017500000001476712672050004015251 0ustar travistravisimport logging import os import argparse from six.moves import configparser from nose2 import config, events, util log = logging.getLogger(__name__) __unittest = True class Session(object): """Configuration session. Encapsulates all configuration for a given test run. .. attribute :: argparse An instance of :class:`argparse.ArgumentParser`. Plugins can use this directly to add arguments and argument groups, but *must* do so in their ``__init__`` methods. .. attribute :: pluginargs The argparse argument group in which plugins (by default) place their command-line arguments. Plugins can use this directly to add arguments, but *must* do so in their ``__init__`` methods. .. attribute :: hooks The :class:`nose2.events.PluginInterface` instance contains all available plugin methods and hooks. .. attribute :: plugins The list of loaded -- but not necessarily *active* -- plugins. .. attribute :: verbosity Current verbosity level. Default: 1. .. attribute :: startDir Start directory of test run. Test discovery starts here. Default: current working directory. .. attribute :: topLevelDir Top-level directory of test run. This directory is added to sys.path. Default: starting directory. .. attribute :: libDirs Names of code directories, relative to starting directory. Default: ['lib', 'src']. These directories are added to sys.path and discovery if the exist. .. attribute :: testFilePattern Pattern used to discover test module files. Default: test*.py .. attribute :: testMethodPrefix Prefix used to discover test methods and functions: Default: 'test'. .. attribute :: unittest The config section for nose2 itself. """ configClass = config.Config def __init__(self): self.argparse = argparse.ArgumentParser(prog='nose2', add_help=False) self.pluginargs = self.argparse.add_argument_group( 'plugin arguments', 'Command-line arguments added by plugins:') self.config = configparser.ConfigParser() self.hooks = events.PluginInterface() self.plugins = [] self.verbosity = 1 self.startDir = None self.topLevelDir = None self.testResult = None self.testLoader = None self.logLevel = logging.WARN def get(self, section): """Get a config section. :param section: The section name to retreive. :returns: instance of self.configClass. """ # FIXME cache these items = [] if self.config.has_section(section): items = self.config.items(section) return self.configClass(items) def loadConfigFiles(self, *filenames): """Load config files. :param filenames: Names of config files to load. Loads all names files that exist into ``self.config``. """ self.config.read(filenames) def loadPlugins(self, modules=None, exclude=None): """Load plugins. :param modules: List of module names from which to load plugins. """ # plugins set directly if modules is None: modules = [] if exclude is None: exclude = [] # plugins mentioned in config file(s) cfg = self.unittest more_plugins = cfg.as_list('plugins', []) cfg_exclude = cfg.as_list('exclude-plugins', []) exclude.extend(cfg_exclude) exclude = set(exclude) all_ = (set(modules) | set(more_plugins)) - exclude log.debug("Loading plugin modules: %s", all_) for module in all_: self.loadPluginsFromModule(util.module_from_name(module)) self.hooks.pluginsLoaded(events.PluginsLoadedEvent(self.plugins)) def loadPluginsFromModule(self, module): """Load plugins from a module. :param module: A python module containing zero or more plugin classes. """ avail = [] for entry in dir(module): try: item = getattr(module, entry) except AttributeError: pass try: if issubclass(item, events.Plugin): avail.append(item) except TypeError: pass for cls in avail: log.debug("Plugin is available: %s", cls) plugin = cls(session=self) self.plugins.append(plugin) for method in self.hooks.preRegistrationMethods: if hasattr(plugin, method): self.hooks.register(method, plugin) def registerPlugin(self, plugin): """Register a plugin. :param plugin: A `nose2.events.Plugin` instance. Register the plugin with all methods it implements. """ log.debug("Register active plugin %s", plugin) if plugin not in self.plugins: self.plugins.append(plugin) for method in self.hooks.methods: if hasattr(plugin, method): log.debug("Register method %s for plugin %s", method, plugin) self.hooks.register(method, plugin) def setStartDir(self): if self.startDir is None: self.startDir = self.unittest.as_str('start-dir', '.') def prepareSysPath(self): """Add code directories to sys.path""" tld = self.topLevelDir sd = self.startDir if tld is None: tld = sd tld = os.path.abspath(tld) util.ensure_importable(tld) for libdir in self.libDirs: libdir = os.path.abspath(os.path.join(tld, libdir)) if os.path.exists(libdir): util.ensure_importable(libdir) # convenience properties @property def libDirs(self): return self.unittest.as_list('code-directories', ['lib', 'src']) @property def testFilePattern(self): return self.unittest.as_str('test-file-pattern', 'test*.py') @property def testMethodPrefix(self): return self.unittest.as_str('test-method-prefix', 'test') @property def unittest(self): return self.get('unittest') def isPluginLoaded(self, pluginName): """Returns ``True`` if a given plugin is loaded. :param pluginName: the name of the plugin module: e.g. "nose2.plugins.layers". """ for plugin in self.plugins: if pluginName == plugin.__class__.__module__: return True return False nose2-0.6.4/nose2/sphinxext.py0000664000175000017500000001726212672050004015611 0ustar travistravisimport types from docutils import nodes from docutils.statemachine import ViewList from docutils.parsers.rst import Directive, directives from nose2 import events, session, util AD = u'' __unittest = True class AutoPlugin(Directive): required_arguments = 1 optional_arguments = 1 final_argument_whitespace = False has_content = False option_spec = {'module': directives.unchanged} def run(self): plugin_name = self.arguments[0] parent, plugin = util.object_from_name(plugin_name) if isinstance(plugin, types.ModuleType): # document all plugins in module module = plugin mod_name = module.__name__ plugins = self.plugins(module) else: if 'module' in self.options: mod_name = self.options['module'] else: mod_name = plugin_name[ 0:plugin_name.index(plugin.__name__) - 1] plugins = [plugin] rst = ViewList() if mod_name: rst.append(u'.. automodule :: %s\n' % mod_name, AD) rst.append(u'', AD) for plug in plugins: self.document(rst, plug) # parse rst and generate new nodelist state = self.state node = nodes.section() node.document = state.document surrounding_title_styles = state.memo.title_styles surrounding_section_level = state.memo.section_level state.memo.title_styles = [] state.memo.section_level = 0 state.nested_parse(rst, 0, node, match_titles=1) state.memo.title_styles = surrounding_title_styles state.memo.section_level = surrounding_section_level return node.children def document(self, rst, plugin): ssn = session.Session() ssn.configClass = ssn.config = config = ConfigBucket() ssn.pluginargs = opts = OptBucket() plugin_name = plugin.__name__ config = ssn.config obj = plugin(session=ssn) try: obj.pluginsLoaded(events.PluginsLoadedEvent([obj])) except AttributeError: pass # config options if config.vars: self.add_config(rst, config) # command-line options if opts.opts: self.headline(rst, u'Command-line options') for opt in opts: for line in opt.options(): rst.append(line, AD) rst.append('', AD) # class __doc__ self.headline(rst, u'Plugin class reference: %s' % plugin_name) rst.append(u'.. autoclass :: %s' % plugin_name, AD) rst.append(u' :members:', AD) rst.append(u'', AD) def add_config(self, rst, config): headline = u'Configuration [%s]' % config.section self.headline(rst, headline) for var in sorted(config.vars.keys()): info = config.vars[var] rst.append(u'.. rst:configvar :: %s' % var, AD) rst.append(u' ', AD) rst.append(u' :Default: %(default)s' % info, AD) rst.append(u' :Type: %(type)s' % info, AD) rst.append(u'', AD) self.headline(rst, u"Sample configuration", '-') rst.append(u'The default configuration is equivalent to including ' u'the following in a :file:`unittest.cfg` file.', AD) rst.append(u'', AD) rst.append(u'.. code-block:: ini', AD) rst.append(u' ', AD) rst.append(u' [%s]' % config.section, AD) for var in sorted(config.vars.keys()): info = config.vars[var] entry = ' %s = ' % (var) if info['type'] != 'list': entry = u'%s%s' % (entry, info['default']) rst.append(entry, AD) elif info['default']: pad = ' ' * len(entry) entry = u'%s%s' % (entry, info['default'][0]) rst.append(entry, AD) for val in info['default'][1:]: rst.append(u'%s%s' % (pad, val), AD) else: rst.append(entry, AD) rst.append(u'', AD) def headline(self, rst, headline, level=u'='): rst.append(headline, AD) rst.append(level * len(headline), AD) rst.append(u'', AD) def plugins(self, module): for entry in dir(module): try: item = getattr(module, entry) except AttributeError: pass try: if issubclass(item, events.Plugin): yield item except TypeError: pass def setup(app): app.add_directive('autoplugin', AutoPlugin) app.add_object_type('configvar', 'config', u'pair: %s; configvar') DEFAULT = object() class ConfigBucket(object): def __init__(self): self.section = None self.vars = {} def __call__(self, items): self.vars = dict(items) return self def has_section(self, section): self.section = section return False def items(self): return self.vars.items() def as_bool(self, item, default=DEFAULT): self.vars[item] = {'type': 'boolean', 'default': default} return default as_tri = as_bool def as_int(self, item, default=DEFAULT): self.vars[item] = {'type': 'integer', 'default': default} return default def as_float(self, item, default=DEFAULT): self.vars[item] = {'type': 'float', 'default': default} return default def as_str(self, item, default=DEFAULT): self.vars[item] = {'type': 'str', 'default': default} return default def as_list(self, item, default=DEFAULT): self.vars[item] = {'type': 'list', 'default': default} return default def __getitem__(self, item): self.vars[item] = {'type': None, 'default': DEFAULT} def get(self, item, default=DEFAULT): self.vars[item] = {'type': None, 'default': default} return default class OptBucket(object): def __init__(self, doc=None, prog='nosetests'): self.seen = set() self.opts = [] self.doc = doc self.prog = prog def __iter__(self): return iter(self.opts) def format_help(self): return self.doc.replace('%prog', self.prog).replace(':\n', '::\n') def add_argument(self, *arg, **kw): if not arg in self.seen: self.opts.append(Opt(*arg, **kw)) self.seen.add(arg) def __call__(self, callback, opt=None, longOpt=None, help=None): opts = [] if opt is not None: opts.append('-' + opt) if longOpt is not None: opts.append('--' + longOpt) self.add_option(*opts, help=help) class Opt(object): def __init__(self, *arg, **kw): self.opts = arg self.action = kw.pop('action', None) self.default = kw.pop('default', None) self.metavar = kw.pop('metavar', None) self.help = kw.pop('help', None) def options(self): buf = [] for optstring in self.opts: desc = optstring if self.action not in ('store_true', 'store_false', None): desc += ' %s' % self.meta(optstring) buf.append(desc) res = ['.. cmdoption :: ' + ', '.join(buf)] if self.help: res.append('') res.append(' %s' % self.help) res.append('') return res def meta(self, optstring): # FIXME optparser default metavar? return self.metavar or 'DEFAULT' nose2-0.6.4/nose2/suite.py0000664000175000017500000000721112672050004014701 0ustar travistravisimport sys import inspect import logging from nose2 import util from nose2.compat import unittest log = logging.getLogger(__name__) __unittest = True # # Layer suite class # class LayerSuite(unittest.BaseTestSuite): def __init__(self, tests=(), layer=None): super(LayerSuite, self).__init__(tests) self.layer = layer self.wasSetup = False def run(self, result): if not self._safeMethodCall(self.setUp, result): return try: for test in self: if result.shouldStop: break self._safeMethodCall(self.setUpTest, result, test) try: test(result) finally: self._safeMethodCall(self.tearDownTest, result, test) finally: if self.wasSetup: self._safeMethodCall(self.tearDown, result) def setUp(self): if self.layer is None: return setup = self._getBoundClassmethod(self.layer, 'setUp') if setup: setup() self.wasSetup = True def setUpTest(self, test): # FIXME hook call if self.layer is None: return # skip suites, to ensure test setup only runs once around each test # even for sub-layer suites inside this suite. try: iter(test) except TypeError: # ok, not a suite pass else: # suite-like enough for skipping return if getattr(test, '_layer_wasSetUp', False): return self._allLayers(test, 'testSetUp') test._layer_wasSetUp = True def tearDownTest(self, test): # FIXME hook call if self.layer is None: return if not getattr(test, '_layer_wasSetUp', None): return self._allLayers(test, 'testTearDown', reverse=True) delattr(test, '_layer_wasSetUp') def tearDown(self): # FIXME hook call if self.layer is None: return teardown = self._getBoundClassmethod(self.layer, 'tearDown') if teardown: teardown() def _safeMethodCall(self, method, result, *args): try: method(*args) return True except KeyboardInterrupt: raise except: result.addError(self, sys.exc_info()) return False def _allLayers(self, test, method, reverse=False): done = set() all_lys = util.ancestry(self.layer) if reverse: all_lys = [reversed(lys) for lys in reversed(all_lys)] for lys in all_lys: for layer in lys: if layer in done: continue self._inLayer(layer, test, method) done.add(layer) def _inLayer(self, layer, test, method): meth = self._getBoundClassmethod(layer, method) if meth: args, _, _, _ = inspect.getargspec(meth) if len(args) > 1: meth(test) else: meth() def _getBoundClassmethod(self, cls, method): """ Use instead of :func:`getattr` to get only classmethods explicitly defined on ``cls`` (not methods inherited from ancestors) """ descriptor = cls.__dict__.get(method, None) if descriptor: if not isinstance(descriptor, classmethod): raise TypeError( 'The %s method on a layer must be a classmethod.' % method) bound_method = descriptor.__get__(None, cls) return bound_method else: return None nose2-0.6.4/nose2/util.py0000664000175000017500000002264412672050004014534 0ustar travistravis# This module contains some code copied from unittest2/loader.py and other # code developed in reference to that module and others within unittest2. # unittest2 is Copyright (c) 2001-2010 Python Software Foundation; All # Rights Reserved. See: http://docs.python.org/license.html import logging import os import re import sys import traceback import platform try: from inspect import isgeneratorfunction # new in 2.6 except ImportError: import inspect try: from compiler.consts import CO_GENERATOR except ImportError: # IronPython doesn't have a complier module CO_GENERATOR = 0x20 # backported from Python 2.6 def isgeneratorfunction(func): return bool((inspect.isfunction(func) or inspect.ismethod(func)) and func.func_code.co_flags & CO_GENERATOR) import six __unittest = True IDENT_RE = re.compile(r'^[_a-zA-Z]\w*$', re.UNICODE) VALID_MODULE_RE = re.compile(r'[_a-zA-Z]\w*\.py$', re.UNICODE) def ln(label, char='-', width=70): """Draw a divider, with ``label`` in the middle. >>> ln('hello there') '---------------------------- hello there -----------------------------' ``width`` and divider ``char`` may be specified. Defaults are ``70`` and ``'-'``, respectively. """ label_len = len(label) + 2 chunk = (width - label_len) // 2 out = '%s %s %s' % (char * chunk, label, char * chunk) pad = width - len(out) if pad > 0: out = out + (char * pad) return out def valid_module_name(path): """Is ``path`` a valid module name?""" return VALID_MODULE_RE.search(path) def name_from_path(path): """Translate ``path`` into module name Returns a two-element tuple: 1. a dotted module name that can be used in an import statement (e.g., ``pkg1.test.test_things``) 2. a full path to filesystem directory, which must be on ``sys.path`` for the import to succeed. """ # back up to find module root parts = [] path = os.path.normpath(path) base = os.path.splitext(path)[0] candidate, top = os.path.split(base) parts.append(top) while candidate: if ispackage(candidate): candidate, top = os.path.split(candidate) parts.append(top) else: break return '.'.join(reversed(parts)), candidate def module_from_name(name): """Import module from ``name``""" __import__(name) return sys.modules[name] def test_from_name(name, module): """Import test from ``name``""" pos = name.find(':') index = None if pos != -1: real_name, digits = name[:pos], name[pos + 1:] try: index = int(digits) except ValueError: pass else: name = real_name parent, obj = object_from_name(name, module) return parent, obj, name, index def object_from_name(name, module=None): """Import object from ``name``""" parts = name.split('.') if module is None: parts_copy = parts[:] while parts_copy: try: module = __import__('.'.join(parts_copy)) break except ImportError: del parts_copy[-1] if not parts_copy: raise parts = parts[1:] parent = None obj = module for part in parts: parent, obj = obj, getattr(obj, part) return parent, obj def name_from_args(name, index, args): """Create test name from test args""" summary = ', '.join(repr(arg) for arg in args) return '%s:%s\n%s' % (name, index + 1, summary[:79]) def test_name(test, qualname=True): # XXX does not work for test funcs; test.id() lacks module if hasattr(test, '_funcName'): tid = test._funcName elif hasattr(test, '_testFunc'): tid = "%s.%s" % (test._testFunc.__module__, test._testFunc.__name__) else: if sys.version_info >= (3, 5) and not qualname: test_module = test.__class__.__module__ test_class = test.__class__.__name__ test_method = test._testMethodName tid = "%s.%s.%s" % (test_module, test_class, test_method) else: tid = test.id() if '\n' in tid: tid = tid.split('\n')[0] return tid def ispackage(path): """Is this path a package directory?""" if os.path.isdir(path): # at least the end of the path must be a legal python identifier # and __init__.py[co] must exist end = os.path.basename(path) if IDENT_RE.match(end): for init in ('__init__.py', '__init__.pyc', '__init__.pyo'): if os.path.isfile(os.path.join(path, init)): return True if sys.platform.startswith('java') and \ os.path.isfile(os.path.join(path, '__init__$py.class')): return True return False def ensure_importable(dirname): """Ensure a directory is on ``sys.path``.""" if dirname not in sys.path: sys.path.insert(0, dirname) def isgenerator(obj): """Is this object a generator?""" return (isgeneratorfunction(obj) or getattr(obj, 'testGenerator', None) is not None) def has_module_fixtures(test): """Does this test live in a module with module fixtures?""" modname = test.__class__.__module__ try: mod = sys.modules[modname] except KeyError: return return hasattr(mod, 'setUpModule') or hasattr(mod, 'tearDownModule') def has_class_fixtures(test): # hasattr would be the obvious thing to use here. Unfortunately, all tests # inherit from unittest2.case.TestCase, and that *always* has setUpClass and # tearDownClass methods. Thus, the following (ugly) solution: ver = platform.python_version_tuple() if float('{0}.{1}'.format(*ver[:2])) >= 2.7: name = 'unittest.case' else: name = 'unittest2.case' has_class_setups = any( 'setUpClass' in c.__dict__ for c in test.__class__.__mro__ if c.__module__.find(name) == -1) has_class_teardowns = any( 'tearDownClass' in c.__dict__ for c in test.__class__.__mro__ if c.__module__.find(name) == -1) return has_class_setups or has_class_teardowns def safe_decode(string): """Safely decode a byte string into unicode""" if string is None: return string try: return string.decode() except AttributeError: return string except UnicodeDecodeError: pass try: return string.decode('utf-8') except UnicodeDecodeError: return six.u('') def exc_info_to_string(err, test): """Format exception info for output""" formatTraceback = getattr(test, 'formatTraceback', None) if formatTraceback is not None: return test.formatTraceback(err) else: return format_traceback(test, err) def format_traceback(test, err): """Converts a :func:`sys.exc_info` -style tuple of values into a string.""" exctype, value, tb = err if not hasattr(tb, 'tb_next'): msgLines = tb else: # Skip test runner traceback levels while tb and _is_relevant_tb_level(tb): tb = tb.tb_next failure = getattr(test, 'failureException', AssertionError) if exctype is failure: # Skip assert*() traceback levels length = _count_relevant_tb_levels(tb) msgLines = traceback.format_exception(exctype, value, tb, length) else: msgLines = traceback.format_exception(exctype, value, tb) return ''.join(msgLines) def transplant_class(cls, module): """Make ``cls`` appear to reside in ``module``. :param cls: A class :param module: A module name :returns: A subclass of ``cls`` that appears to have been defined in ``module``. The returned class's ``__name__`` will be equal to ``cls.__name__``, and its ``__module__`` equal to ``module``. """ class C(cls): pass C.__module__ = module C.__name__ = cls.__name__ return C def parse_log_level(lvl): """Return numeric log level given a string""" try: return int(lvl) except ValueError: pass return getattr(logging, lvl.upper(), logging.WARN) def _is_relevant_tb_level(tb): return '__unittest' in tb.tb_frame.f_globals def _count_relevant_tb_levels(tb): length = 0 while tb and not _is_relevant_tb_level(tb): length += 1 tb = tb.tb_next return length class _WritelnDecorator(object): """Used to decorate file-like objects with a handy :func:`writeln` method""" def __init__(self, stream): self.stream = stream def __getattr__(self, attr): if attr in ('stream', '__getstate__'): raise AttributeError(attr) return getattr(self.stream, attr) def write(self, arg): self.stream.write(arg) def writeln(self, arg=None): if arg: self.stream.write(arg) self.stream.write('\n') # text-mode streams translate to \r\n if needed def ancestry(layer): layers = [[layer]] bases = [base for base in bases_and_mixins(layer) if base is not object] while bases: layers.append(bases) newbases = [] for b in bases: for bb in bases_and_mixins(b): if bb is not object: newbases.append(bb) bases = newbases layers.reverse() return layers def bases_and_mixins(layer): return (layer.__bases__ + getattr(layer, 'mixins', ())) nose2-0.6.4/nose2.egg-info/0000775000175000017500000000000012672050226014675 5ustar travistravisnose2-0.6.4/nose2.egg-info/PKG-INFO0000664000175000017500000000666212672050226016004 0ustar travistravisMetadata-Version: 1.0 Name: nose2 Version: 0.6.4 Summary: nose2 is the next generation of nicer testing for Python Home-page: https://github.com/nose-devs/nose2 Author: Jason Pellerin Author-email: jpellerin+nose@gmail.com License: UNKNOWN Description: .. image:: https://travis-ci.org/nose-devs/nose2.png?branch=master :target: https://travis-ci.org/nose-devs/nose2 :alt: Build Status .. image:: https://coveralls.io/repos/nose-devs/nose2/badge.png?branch=master :target: https://coveralls.io/r/nose-devs/nose2?branch=master :alt: Coverage Status .. image:: https://landscape.io/github/nose-devs/nose2/master/landscape.png :target: https://landscape.io/github/nose-devs/nose2/master :alt: Code Health .. image:: https://pypip.in/v/nose2/badge.png :target: https://crate.io/packages/nose2/ :alt: Latest PyPI version .. image:: https://pypip.in/d/nose2/badge.png :target: https://crate.io/packages/nose2/ :alt: Number of PyPI downloads .. image:: https://www.versioneye.com/user/projects/52037a30632bac57a00257ea/badge.png :target: https://www.versioneye.com/user/projects/52037a30632bac57a00257ea/ :alt: Dependencies Status Welcome to nose2 ================ nose2 is the next generation of nicer testing for Python, based on the plugins branch of unittest2. nose2 aims to improve on nose by: * providing a better plugin api * being easier for users to configure * simplifying internal interfaces and processes * supporting Python 2 and 3 from the same codebase, without translation * encouraging greater community involvement in its development In service of some those goals, some features of nose *will not* be supported in nose2. See `differences`_ for a thorough rundown. In time -- once unittest2 supports plugins -- nose2 should be able to become just a collection of plugins and configuration defaults. For now, it provides a plugin api similar to the one in the unittest2 plugins branch, and overrides various unittest2 objects. You are witnesses at the new birth of nose, mark 2. Hope you enjoy our new direction! .. _differences: http://readthedocs.org/docs/nose2/en/latest/differences.html Keywords: unittest,testing,tests Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Testing nose2-0.6.4/nose2.egg-info/SOURCES.txt0000664000175000017500000003007712672050226016570 0ustar travistravisAUTHORS MANIFEST.in README.rst license.txt requirements-docs.txt requirements-py26.txt requirements.txt setup.py tox.ini unittest.cfg bin/nose2 docs/Makefile docs/changelog.rst docs/conf.py docs/configuration.rst docs/contents.rst.inc docs/decorators.rst docs/differences.rst docs/getting_started.rst docs/index.rst docs/params.rst docs/plugins.rst docs/such_dsl.rst docs/tools.rst docs/usage.rst docs/dev/compat.rst docs/dev/contributing.rst docs/dev/documenting_plugins.rst docs/dev/event_reference.rst docs/dev/exceptions.rst docs/dev/hook_reference.rst docs/dev/internals.rst docs/dev/loader.rst docs/dev/main.rst docs/dev/plugin_class_reference.rst docs/dev/result.rst docs/dev/runner.rst docs/dev/session_reference.rst docs/dev/utils.rst docs/dev/writing_plugins.rst docs/plugins/attrib.rst docs/plugins/attrib_example.py docs/plugins/buffer.rst docs/plugins/collect.rst docs/plugins/coverage.rst docs/plugins/debugger.rst docs/plugins/discovery.rst docs/plugins/doctests.rst docs/plugins/dundertests.rst docs/plugins/eggdiscovery.rst docs/plugins/failfast.rst docs/plugins/functions.rst docs/plugins/generators.rst docs/plugins/junitxml.rst docs/plugins/layers.rst docs/plugins/loadtests.rst docs/plugins/logcapture.rst docs/plugins/mp.rst docs/plugins/outcomes.rst docs/plugins/parameters.rst docs/plugins/printhooks.rst docs/plugins/prof.rst docs/plugins/result.rst docs/plugins/testcases.rst docs/plugins/testclasses.rst docs/plugins/testid.rst nose2/__init__.py nose2/__main__.py nose2/collector.py nose2/compat.py nose2/config.py nose2/events.py nose2/exceptions.py nose2/loader.py nose2/main.py nose2/result.py nose2/runner.py nose2/session.py nose2/sphinxext.py nose2/suite.py nose2/util.py nose2.egg-info/PKG-INFO nose2.egg-info/SOURCES.txt nose2.egg-info/dependency_links.txt nose2.egg-info/entry_points.txt nose2.egg-info/requires.txt nose2.egg-info/top_level.txt nose2/backports/__init__.py nose2/backports/ordereddict.py nose2/plugins/__init__.py nose2/plugins/attrib.py nose2/plugins/buffer.py nose2/plugins/collect.py nose2/plugins/coverage.py nose2/plugins/debugger.py nose2/plugins/doctests.py nose2/plugins/dundertest.py nose2/plugins/failfast.py nose2/plugins/junitxml.py nose2/plugins/layers.py nose2/plugins/logcapture.py nose2/plugins/mp.py nose2/plugins/outcomes.py nose2/plugins/printhooks.py nose2/plugins/prof.py nose2/plugins/result.py nose2/plugins/testid.py nose2/plugins/loader/__init__.py nose2/plugins/loader/discovery.py nose2/plugins/loader/eggdiscovery.py nose2/plugins/loader/functions.py nose2/plugins/loader/generators.py nose2/plugins/loader/loadtests.py nose2/plugins/loader/parameters.py nose2/plugins/loader/testcases.py nose2/plugins/loader/testclasses.py nose2/tests/__init__.py nose2/tests/_common.py nose2/tests/functional/__init__.py nose2/tests/functional/test_attrib_plugin.py nose2/tests/functional/test_collect_plugin.py nose2/tests/functional/test_coverage.py nose2/tests/functional/test_decorators.py nose2/tests/functional/test_discovery_loader.py nose2/tests/functional/test_doctests_plugin.py nose2/tests/functional/test_dundertest_plugin.py nose2/tests/functional/test_eggdiscovery_loader.py nose2/tests/functional/test_junitxml_plugin.py nose2/tests/functional/test_layers_plugin.py nose2/tests/functional/test_loading.py nose2/tests/functional/test_loadtests_plugin.py nose2/tests/functional/test_logcapture_plugin.py nose2/tests/functional/test_main.py nose2/tests/functional/test_mp_plugin.py nose2/tests/functional/test_printhooks_plugin.py nose2/tests/functional/test_session.py nose2/tests/functional/test_such_dsl.py nose2/tests/functional/test_util.py nose2/tests/functional/support/cfg/a.cfg nose2/tests/functional/support/cfg/b.cfg nose2/tests/functional/support/lib/plugin_a.py nose2/tests/functional/support/scenario/class_fixtures/test_cf_testcase.py nose2/tests/functional/support/scenario/colliding_test_modules/tests/test.py nose2/tests/functional/support/scenario/colliding_test_modules/tests/more_tests/test.py nose2/tests/functional/support/scenario/decorators/test_decorators.py nose2/tests/functional/support/scenario/doctests/docs.py nose2/tests/functional/support/scenario/doctests/docs.rst nose2/tests/functional/support/scenario/doctests/docs.txt nose2/tests/functional/support/scenario/doctests/doctests_pkg1/__init__.py nose2/tests/functional/support/scenario/doctests/doctests_pkg1/docs1.py nose2/tests/functional/support/scenario/doctests/doctests_pkg1/docs1.rst nose2/tests/functional/support/scenario/doctests/doctests_pkg1/docs1.txt nose2/tests/functional/support/scenario/dundertest_attribute/test.py nose2/tests/functional/support/scenario/expected_failures/expected_failures.py nose2/tests/functional/support/scenario/junitxml/chdir/test_junitxml_chdir.py nose2/tests/functional/support/scenario/junitxml/empty_properties/properties.json nose2/tests/functional/support/scenario/junitxml/empty_properties/test_junitxml_empty_properties.py nose2/tests/functional/support/scenario/junitxml/empty_properties/unittest.cfg nose2/tests/functional/support/scenario/junitxml/fail_to_write/test_junitxml_fail_to_write.py nose2/tests/functional/support/scenario/junitxml/fail_to_write/unittest.cfg nose2/tests/functional/support/scenario/junitxml/happyday/test_junitxml_happyday.py nose2/tests/functional/support/scenario/junitxml/missing_properties/test_junitxml_missing_properties.py nose2/tests/functional/support/scenario/junitxml/missing_properties/unittest.cfg nose2/tests/functional/support/scenario/junitxml/with_properties/test_junitxml_with_properties.py nose2/tests/functional/support/scenario/junitxml/with_properties/unittest.cfg nose2/tests/functional/support/scenario/layers/test_layers.py nose2/tests/functional/support/scenario/layers_and_attributes/test_layers_and_attributes.py nose2/tests/functional/support/scenario/layers_setups/higher_layer_setup.py nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_3layers.py nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_no_test.py nose2/tests/functional/support/scenario/layers_setups/higher_layer_testsetup_with_test.py nose2/tests/functional/support/scenario/layers_with_errors/test_layer_setup_fail.py nose2/tests/functional/support/scenario/layers_with_errors/test_layer_teardown_fail.py nose2/tests/functional/support/scenario/layers_with_errors/test_layers_with_errors.py nose2/tests/functional/support/scenario/layers_with_errors/test_such_setup_fail.py nose2/tests/functional/support/scenario/layers_with_errors/test_such_teardown_fail.py nose2/tests/functional/support/scenario/layers_with_errors/test_such_with_errors.py nose2/tests/functional/support/scenario/layers_with_inheritance/test_layers_with_inheritance.py nose2/tests/functional/support/scenario/load_tests/test_filter.py nose2/tests/functional/support/scenario/load_tests/test_simple.py nose2/tests/functional/support/scenario/load_tests_pkg/unittest.cfg nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/__init__.py nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/tests/__init__.py nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg/tests/test_find_these.py nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/__init__.py nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/tests/__init__.py nose2/tests/functional/support/scenario/load_tests_pkg/ltpkg2/tests/test_skip_these.py nose2/tests/functional/support/scenario/logging/logging_keeps_copies_of_mutable_objects.py nose2/tests/functional/support/scenario/many_tests/test_gen_many_func.py nose2/tests/functional/support/scenario/many_tests_socket/nose2.cfg nose2/tests/functional/support/scenario/many_tests_socket/test_gen_many_socket_func.py nose2/tests/functional/support/scenario/module_fixtures/test_mf_func.py nose2/tests/functional/support/scenario/module_fixtures/test_mf_gen_func.py nose2/tests/functional/support/scenario/module_fixtures/test_mf_param_func.py nose2/tests/functional/support/scenario/module_fixtures/test_mf_testcase.py nose2/tests/functional/support/scenario/module_import_err/test_import_err.py nose2/tests/functional/support/scenario/no_tests/a.py nose2/tests/functional/support/scenario/one_test/tests.py nose2/tests/functional/support/scenario/package_in_lib/tests.py nose2/tests/functional/support/scenario/package_in_lib/lib/pkg2/__init__.py nose2/tests/functional/support/scenario/slow/test_slow.py nose2/tests/functional/support/scenario/such_with_params/such_with_params.py nose2/tests/functional/support/scenario/test_class_fail/test_class_fail.py nose2/tests/functional/support/scenario/test_classes/test_classes.py nose2/tests/functional/support/scenario/test_classes/test_fixtures.py nose2/tests/functional/support/scenario/test_with_module/test_coverage.py nose2/tests/functional/support/scenario/test_with_module/lib/__init__.py nose2/tests/functional/support/scenario/test_with_module/lib/mod1.py nose2/tests/functional/support/scenario/tests_in_package/docs.rst nose2/tests/functional/support/scenario/tests_in_package/docs.txt nose2/tests/functional/support/scenario/tests_in_package/setup.py nose2/tests/functional/support/scenario/tests_in_package/unittest.cfg nose2/tests/functional/support/scenario/tests_in_package/pkg1/__init__.py nose2/tests/functional/support/scenario/tests_in_package/pkg1/mod1.py nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/__init__.py nose2/tests/functional/support/scenario/tests_in_package/pkg1/test/test_things.py nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/docs.rst nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/docs.txt nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/setup.py nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/unittest.cfg nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/SOURCES.txt nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/dependency_links.txt nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/EGG-INFO/top_level.txt nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/__init__.py nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/mod1.py nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/test/__init__.py nose2/tests/functional/support/scenario/tests_in_unzipped_eggs/pkgunegg-0.0.0-py2.7.egg/pkgunegg/test/test_things.py nose2/tests/functional/support/scenario/tests_in_zipped_eggs/docs.rst nose2/tests/functional/support/scenario/tests_in_zipped_eggs/docs.txt nose2/tests/functional/support/scenario/tests_in_zipped_eggs/pkgegg-0.0.0-py2.7.egg nose2/tests/functional/support/scenario/tests_in_zipped_eggs/setup.py nose2/tests/functional/support/scenario/tests_in_zipped_eggs/unittest.cfg nose2/tests/functional/support/such/output.txt nose2/tests/functional/support/such/test_regression_same_havings.py nose2/tests/functional/support/such/test_such.py nose2/tests/functional/support/such/test_such_without_layers.py nose2/tests/unit/__init__.py nose2/tests/unit/test_attrib_plugin.py nose2/tests/unit/test_buffer_plugin.py nose2/tests/unit/test_collect_plugin.py nose2/tests/unit/test_collector.py nose2/tests/unit/test_config.py nose2/tests/unit/test_debugger_plugin.py nose2/tests/unit/test_decorators.py nose2/tests/unit/test_doctest_plugin.py nose2/tests/unit/test_dundertest_plugin.py nose2/tests/unit/test_failfast.py nose2/tests/unit/test_functions_loader.py nose2/tests/unit/test_generators_plugin.py nose2/tests/unit/test_junitxml.py nose2/tests/unit/test_layers_plugin.py nose2/tests/unit/test_loader.py nose2/tests/unit/test_logcapture_plugin.py nose2/tests/unit/test_mp_plugin.py nose2/tests/unit/test_outcomes_plugin.py nose2/tests/unit/test_params_plugin.py nose2/tests/unit/test_plugin_api.py nose2/tests/unit/test_printhooks_plugin.py nose2/tests/unit/test_prof_plugin.py nose2/tests/unit/test_result.py nose2/tests/unit/test_session.py nose2/tests/unit/test_testcase_loader.py nose2/tests/unit/test_testclass_loader.py nose2/tests/unit/test_testid_plugin.py nose2/tests/unit/test_util.py nose2/tools/__init__.py nose2/tools/decorators.py nose2/tools/params.py nose2/tools/such.pynose2-0.6.4/nose2.egg-info/dependency_links.txt0000664000175000017500000000000112672050226020743 0ustar travistravis nose2-0.6.4/nose2.egg-info/entry_points.txt0000664000175000017500000000010512672050226020167 0ustar travistravis[console_scripts] nose2 = nose2:discover nose2-2.6 = nose2:discover nose2-0.6.4/nose2.egg-info/requires.txt0000664000175000017500000000012612672050226017274 0ustar travistravissix>=1.1 unittest2>=0.5.1,<0.6 argparse>=1.2.1,<1.3 [coverage_plugin] cov-core>=1.12 nose2-0.6.4/nose2.egg-info/top_level.txt0000664000175000017500000000000612672050226017423 0ustar travistravisnose2 nose2-0.6.4/AUTHORS0000664000175000017500000000015612672050004013221 0ustar travistravisJason Pellerin Augie Fackler Arve Knudsen Wouter Overmeire Omer Katz Ilya Kurnosov Philip Thiem Aloys Baillet nose2-0.6.4/MANIFEST.in0000664000175000017500000000060412672050004013705 0ustar travistravisinclude AUTHORS include requirements.txt include requirements-py26.txt include requirements-docs.txt include tox.ini include unittest.cfg include README.rst include license.txt recursive-include nose2/tests/functional/support *.py *.txt *.cfg *.rst *.json *.egg recursive-include docs *.inc *.py *.rst Makefile graft bin global-exclude __pycache__ global-exclude *~ global-exclude *.pyc nose2-0.6.4/README.rst0000664000175000017500000000361312672050004013641 0ustar travistravis.. image:: https://travis-ci.org/nose-devs/nose2.png?branch=master :target: https://travis-ci.org/nose-devs/nose2 :alt: Build Status .. image:: https://coveralls.io/repos/nose-devs/nose2/badge.png?branch=master :target: https://coveralls.io/r/nose-devs/nose2?branch=master :alt: Coverage Status .. image:: https://landscape.io/github/nose-devs/nose2/master/landscape.png :target: https://landscape.io/github/nose-devs/nose2/master :alt: Code Health .. image:: https://pypip.in/v/nose2/badge.png :target: https://crate.io/packages/nose2/ :alt: Latest PyPI version .. image:: https://pypip.in/d/nose2/badge.png :target: https://crate.io/packages/nose2/ :alt: Number of PyPI downloads .. image:: https://www.versioneye.com/user/projects/52037a30632bac57a00257ea/badge.png :target: https://www.versioneye.com/user/projects/52037a30632bac57a00257ea/ :alt: Dependencies Status Welcome to nose2 ================ nose2 is the next generation of nicer testing for Python, based on the plugins branch of unittest2. nose2 aims to improve on nose by: * providing a better plugin api * being easier for users to configure * simplifying internal interfaces and processes * supporting Python 2 and 3 from the same codebase, without translation * encouraging greater community involvement in its development In service of some those goals, some features of nose *will not* be supported in nose2. See `differences`_ for a thorough rundown. In time -- once unittest2 supports plugins -- nose2 should be able to become just a collection of plugins and configuration defaults. For now, it provides a plugin api similar to the one in the unittest2 plugins branch, and overrides various unittest2 objects. You are witnesses at the new birth of nose, mark 2. Hope you enjoy our new direction! .. _differences: http://readthedocs.org/docs/nose2/en/latest/differences.html nose2-0.6.4/license.txt0000664000175000017500000000267712672050004014346 0ustar travistravisCopyright (c) 2012, Jason Pellerin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- Portions derived from unittest2. unittest2 is Copyright (c) 2001-2012 Python Software Foundation; All Rights Reserved. See: http://docs.python.org/license.html nose2-0.6.4/requirements-docs.txt0000664000175000017500000000001612672050004016356 0ustar travistravisSphinx>=1.0.5 nose2-0.6.4/requirements-py26.txt0000664000175000017500000000013412672050004016227 0ustar travistravismock unittest2==0.5.1 --allow-external argparse --allow-unverified argparse argparse>=1.2.1 nose2-0.6.4/requirements.txt0000664000175000017500000000003012672050004015424 0ustar travistravissix>=1.7 cov-core>=1.12 nose2-0.6.4/setup.py0000664000175000017500000000446612672050004013673 0ustar travistravisimport os import sys NAME = 'nose2' VERSION = '0.6.4' PACKAGES = ['nose2', 'nose2.plugins', 'nose2.plugins.loader', 'nose2.tests', 'nose2.tests.functional', 'nose2.tests.unit', 'nose2.tools', 'nose2.backports'] SCRIPTS = ['bin/nose2'] DESCRIPTION = 'nose2 is the next generation of nicer testing for Python' URL = 'https://github.com/nose-devs/nose2' LONG_DESCRIPTION = open( os.path.join(os.path.dirname(__file__), 'README.rst')).read() CLASSIFIERS = [ 'Development Status :: 3 - Alpha', 'Environment :: Console', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python', 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: Implementation :: CPython', 'Programming Language :: Python :: Implementation :: PyPy', 'Operating System :: OS Independent', 'Topic :: Software Development :: Libraries', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Testing', ] AUTHOR = 'Jason Pellerin' AUTHOR_EMAIL = 'jpellerin+nose@gmail.com' KEYWORDS = ['unittest', 'testing', 'tests'] params = dict( name=NAME, version=VERSION, description=DESCRIPTION, long_description=LONG_DESCRIPTION, packages=PACKAGES, scripts=SCRIPTS, author=AUTHOR, author_email=AUTHOR_EMAIL, url=URL, classifiers=CLASSIFIERS, keywords=KEYWORDS, extras_require={ 'coverage_plugin': ["cov-core>=1.12"], } ) py_version = sys.version[:3] SCRIPT1 = 'nose2' SCRIPT2 = 'nose2-%s' % (py_version,) try: from setuptools import setup except ImportError: from distutils.core import setup else: REQS = ['six>=1.1'] if sys.version_info < (2, 7): REQS.extend(['unittest2>=0.5.1,<0.6', 'argparse>=1.2.1,<1.3']) params['entry_points'] = { 'console_scripts': [ '%s = nose2:discover' % SCRIPT1, '%s = nose2:discover' % SCRIPT2, ], } params['install_requires'] = REQS params['test_suite'] = 'nose2.compat.unittest.collector' setup(**params) nose2-0.6.4/tox.ini0000664000175000017500000000210012672050004013453 0ustar travistravis[tox] envlist=py26,py27,py32,py33,py34,pypy,docs,self27,cov27 # Default settings for py27, py32, py33, py34 and pypy [testenv] deps=-r{toxinidir}/requirements.txt commands=python -m unittest discover [] [testenv:jython] deps=-r{toxinidir}/requirements.txt -r{toxinidir}/requirements-py26.txt commands=unit2 discover [] [testenv:docs] basepython=python2.7 changedir=docs deps=-r{toxinidir}/requirements.txt -r{toxinidir}/requirements-docs.txt commands=sphinx-build -b html -d {envtmpdir}/doctrees . {envtmpdir}/html [testenv:py26] deps=-r{toxinidir}/requirements.txt -r{toxinidir}/requirements-py26.txt commands=unit2 discover [] [testenv:self27] basepython=python2.7 deps=-r{toxinidir}/requirements.txt setenv=PYTHONPATH={toxinidir} commands=python -m nose2.__main__ [] [testenv:cov27] basepython=python2.7 deps=coverage>=3.3 -r{toxinidir}/requirements.txt commands=coverage erase coverage run -m unittest discover [] coverage report --include=*nose2* --omit=*nose2/tests* coverage html -d cover --include=*nose2* --omit=*nose2/tests* nose2-0.6.4/unittest.cfg0000664000175000017500000000006512672050004014510 0ustar travistravis[log-capture] always-on = True clear-handlers = true nose2-0.6.4/PKG-INFO0000664000175000017500000000666212672050226013264 0ustar travistravisMetadata-Version: 1.0 Name: nose2 Version: 0.6.4 Summary: nose2 is the next generation of nicer testing for Python Home-page: https://github.com/nose-devs/nose2 Author: Jason Pellerin Author-email: jpellerin+nose@gmail.com License: UNKNOWN Description: .. image:: https://travis-ci.org/nose-devs/nose2.png?branch=master :target: https://travis-ci.org/nose-devs/nose2 :alt: Build Status .. image:: https://coveralls.io/repos/nose-devs/nose2/badge.png?branch=master :target: https://coveralls.io/r/nose-devs/nose2?branch=master :alt: Coverage Status .. image:: https://landscape.io/github/nose-devs/nose2/master/landscape.png :target: https://landscape.io/github/nose-devs/nose2/master :alt: Code Health .. image:: https://pypip.in/v/nose2/badge.png :target: https://crate.io/packages/nose2/ :alt: Latest PyPI version .. image:: https://pypip.in/d/nose2/badge.png :target: https://crate.io/packages/nose2/ :alt: Number of PyPI downloads .. image:: https://www.versioneye.com/user/projects/52037a30632bac57a00257ea/badge.png :target: https://www.versioneye.com/user/projects/52037a30632bac57a00257ea/ :alt: Dependencies Status Welcome to nose2 ================ nose2 is the next generation of nicer testing for Python, based on the plugins branch of unittest2. nose2 aims to improve on nose by: * providing a better plugin api * being easier for users to configure * simplifying internal interfaces and processes * supporting Python 2 and 3 from the same codebase, without translation * encouraging greater community involvement in its development In service of some those goals, some features of nose *will not* be supported in nose2. See `differences`_ for a thorough rundown. In time -- once unittest2 supports plugins -- nose2 should be able to become just a collection of plugins and configuration defaults. For now, it provides a plugin api similar to the one in the unittest2 plugins branch, and overrides various unittest2 objects. You are witnesses at the new birth of nose, mark 2. Hope you enjoy our new direction! .. _differences: http://readthedocs.org/docs/nose2/en/latest/differences.html Keywords: unittest,testing,tests Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.6 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Operating System :: OS Independent Classifier: Topic :: Software Development :: Libraries Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Testing nose2-0.6.4/setup.cfg0000664000175000017500000000007312672050226013776 0ustar travistravis[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0