How to use nose2 - 10 common examples

To help you get started, we’ve selected a few nose2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github peter-wangxu / persist-queue / tests / test_queue.py View on Github external
    @params(*serializer_params)
    def test_partial_write(self, serializer):
        """Test recovery from previous crash w/ partial write"""

        q = Queue(self.path, **serializer_params[serializer])
        for i in range(100):
            q.put('var%d' % i)
        del q
        with open(os.path.join(self.path, 'q00000'), 'ab') as f:
            pickle.dump('文字化け', f)
        q = Queue(self.path, **serializer_params[serializer])
        self.assertEqual(100, q.qsize())
        for i in range(100):
            self.assertEqual('var%d' % i, q.get())
            q.task_done()
        with self.assertRaises(Empty):
            q.get_nowait()
github peter-wangxu / persist-queue / tests / test_queue.py View on Github external
    @params(*serializer_params)
    def test_put_block_and_wait(self, serializer):
        """Test block until queue is not full."""
        q = Queue(self.path, maxsize=10, **serializer_params[serializer])

        def consumer():
            for i in range(5):
                q.get()
                q.task_done()

        def producer():
            for j in range(16):
                q.put('var%d' % j)

        p = Thread(target=producer)
        p.start()
        c = Thread(target=consumer)
github bayandin / github-board / test / test_load_template.py View on Github external
    @params(
        ("1", [[1 * COMMIT_MULTIPLIER]]),
        ("01", [[0, 1 * COMMIT_MULTIPLIER]]),
        ("0\n1", [[0], [1 * COMMIT_MULTIPLIER]]),
        ("1\n0\n", [[1 * COMMIT_MULTIPLIER], [0]]),
        ("10\n01", [[1 * COMMIT_MULTIPLIER, 0], [0, 1 * COMMIT_MULTIPLIER]]),
        ("\n1", [[1 * COMMIT_MULTIPLIER]]),
        ("", []),
        ("\n", []),
        ("5", [[5 * COMMIT_MULTIPLIER]]),
        ("123", [[1 * COMMIT_MULTIPLIER, 2 * COMMIT_MULTIPLIER, 3 * COMMIT_MULTIPLIER]]),
        ("1\n2\n3", [[1 * COMMIT_MULTIPLIER], [2 * COMMIT_MULTIPLIER], [3 * COMMIT_MULTIPLIER]]),
        ("12\n3", [[1 * COMMIT_MULTIPLIER, 2 * COMMIT_MULTIPLIER], [3 * COMMIT_MULTIPLIER]]),
    )
    def test(self, content, expected_result):
        with mock.patch("github_board.open", mock.mock_open(read_data=content), create=True):
            self.assertListEqual(expected_result, load_template("fake_path"))
github peter-wangxu / persist-queue / tests / test_queue.py View on Github external
    @params(*serializer_params)
    def test_random_read_write(self, serializer):
        """Test random read/write"""

        q = Queue(self.path, **serializer_params[serializer])
        n = 0
        for i in range(1000):
            if random.random() < 0.5:
                if n > 0:
                    q.get_nowait()
                    q.task_done()
                    n -= 1
                else:
                    with self.assertRaises(Empty):
                        q.get_nowait()
            else:
                q.put('var%d' % random.getrandbits(16))
github mgrijalva / nose2-html-report / tests / test_nose_plugin.py View on Github external
def test_outcome_processing_successful_test(self):
        test_function = _test_func
        ev = events.TestOutcomeEvent(test_function, None, result.PASS)

        reporter = create_plugin_instance()
        reporter.testOutcome(ev)

        self.assertEqual(len(reporter.test_results), 1, 'Actual contents: %s' % reporter.test_results)
        test_result = reporter.test_results[0]
        self.assertEqual(test_result['result'], result.PASS)
        self.assertEqual(test_result['name'], test_function.__name__)
        self.assertEqual(test_result['description'], test_function.__doc__)
        self.assertIsNone(test_result['traceback'])
github PQClean / PQClean / test / test_common.py View on Github external
for d in os.listdir('test_common'):
        primitive = re.sub(r"\.c$", "", d)
        if helpers.permit_test('common', None):
            yield check_common, primitive


def check_common(primitive):
    binname = os.path.join('..', 'bin', 'test_common_'+primitive)
    helpers.make(binname)
    helpers.run_subprocess([binname])


if __name__ == '__main__':
    try:
        import nose2
        nose2.main()
    except ImportError:
        import nose
        nose.runmodule()
github mgrijalva / nose2-html-report / tests / test_nose_plugin.py View on Github external
def test_outcome_with_failed_test(self):
        test_function = _test_func_fail
        try:
            test_function()
        except:
            exc_info = sys.exc_info()
        ev = events.TestOutcomeEvent(test_function, None, result.FAIL, exc_info=exc_info)

        reporter = create_plugin_instance()
        reporter.testOutcome(ev)

        self.assertEqual(len(reporter.test_results), 1, 'Actual contents: %s' % reporter.test_results)
        test_result = reporter.test_results[0]
        self.assertEqual(test_result['result'], result.FAIL)
        self.assertEqual(test_result['name'], test_function.__name__)
        self.assertEqual(test_result['description'], test_function.__doc__)
        self.assertIsNotNone(test_result['traceback'])
        self.assertIn('assert 1 == 2', test_result['traceback'])
github sixty-north / cosmic-ray / plugins / test-runners / nose2 / cosmic_ray_nose2_runner / runner.py View on Github external
def _run(self):
        argv = ['']
        argv += self.test_args.split()
        collector = Nose2ResultsCollector()

        with open(os.devnull, 'w') as devnull:
            with redirect_stdout(devnull):
                with redirect_stderr(devnull):
                    nose2.discover(argv=argv, extraHooks=[('testOutcome', collector)], exit=False)
        failures = [x for x in collector.events if x.outcome != 'passed']

        return (not failures, [(str(r.test), traceback.format_exception(*r.exc_info)) for r in failures])
github fabiogibson / django-livesync / runtests.py View on Github external
* http://nose.readthedocs.org/en/latest/usage.html#basic-usage
"""
import os
import sys

import nose2
import django
from django.conf import settings


if __name__ == '__main__':
    settings.configure()
    django.setup()
    settings.BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    settings.DJANGO_LIVESYNC = {'PORT': 9001, 'HOST': '127.0.0.1'}
    result = nose2.discover()
    if not result:
        sys.exit(1)
github openwisp / netjsonconfig / runtests.py View on Github external
#!/usr/bin/env python
# -*- coding: utf-8 -*-

try:
    import nose2
except ImportError:
    message = """nose2 package not installed, install test requirements with:

    pip install -r requirements-test.txt
    """
    raise ImportError(message)

if __name__ == "__main__":
    result = nose2.discover()
    if result is False:
        import sys
        sys.exit(1)