def run_test_with_db(): from django.conf import settings from django.db import connection from django.test.utils import setup_test_environment, teardown_test_environment from django.core.management import call_command old_database_name = None verbosity = 0 try: setup_test_environment() settings.DEBUG = False old_database_name = settings.DATABASES['default']['NAME'] connection.creation.create_test_db(verbosity) # call_command('loaddata', 'devdata/initial_dev_data.json') nose2_argv = [ "-v", "--no-user-config", "--log-level=%d" % logging.WARNING ] test_file, test_names = __get_test_info() nose2_argv.insert(0, test_file) nose2_argv.extend(test_names) import nose2 nose2.main(argv=(nose2_argv)) finally: connection.creation.destroy_test_db(old_database_name, verbosity) teardown_test_environment()
def run_test(): nose2_argv = ["-v", "--no-user-config", "--log-level=%d" % logging.WARNING] test_file, test_names = __get_test_info() nose2_argv.insert(0, test_file) nose2_argv.extend(test_names) import nose2 nose2.main(argv=(nose2_argv))
['clang-tidy', '-quiet', '-header-filter=.*', *additional_flags, *cfiles, *common_files, '--', '-iquote', os.path.join('..', 'common'), '-iquote', implementation.path()], expected_returncode=None, ) # Detect and gracefully avoid segfaults if returncode == -11: raise unittest.SkipTest("clang-tidy segfaulted") else: assert returncode == 0, "Clang-tidy returned %d" % returncode if __name__ == "__main__": # allow a user to specify --fix-errors, to immediately fix errors if len(sys.argv) >= 2 and sys.argv[1] == '-fix-errors': additional_flags = ['-fix-errors'] sys.argv = sys.argv[0:1] + sys.argv[2:] try: import nose2 nose2.main() except ImportError: import nose nose.runmodule()
import nose2 import unittest import logging log = logging.getLogger(__name__) class Test(unittest.TestCase): def test_logging_config(self): log.debug("foo") log.info("bar") assert False if __name__ == '__main__': nose2.main()
def test_cache_expiration(self): from qualysapi import api_objects mymap = api_objects.Map( name = 'Bogus Test Map', ref = 'map/12345.bogus', date = '2015-11-19T06:00:39Z', status = 'Finished', report_id = None, ) self.cache_instance.cache_api_object(obj=mymap, expiration=1) # sleep for 2 seconds, letting the cache expire the key after 1 import time time.sleep(2) fromcache = self.cache_instance.load_api_object( objkey = mymap.getKey(), objtype = api_objects.Map ) self.assertIsNone(fromcache) def test_speed(self): self.assertTrue(False) #stand-alone test execution if __name__ == '__main__': import nose2 nose2.main(argv=['fake', '--log-capture'])
from src import ex_002_even_fib as mut # mut = Module Under Test with such.A('Exercise 002 - Fibonacci generator') as it: @it.should('Generate Fib numbers up to 90') def test_generator(): """ Test the fibonacci generator""" less_than_90 = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89] generated = [fib_no for fib_no in takewhile( lambda x: x < 90, mut.fibonacci_generator())] assert less_than_90 == generated, \ "Equals failed generated vs Hard coded {0}".format(generated) @it.should('Sum up all the even fib-numbers up to 90') def test_sum_of_even(): """ Tests the sum_of_even_fibonacci_numbers method """ # Even fib numbers below 90 are 2 8 34 evensum = 2 + 8 + 34 mutsum = mut.sum_of_even_fibonacci_numbers(90) assert evensum == mutsum, "Incorrect sum, expected {0} got {1}".format(evensum, mutsum) @it.should('Solve the actual Euler problem correctly') def test_main(): """ Tests the main method, compares to the correct Euler answer 4613732""" answer = 4613732 mut_answer = mut.run_main() assert answer == mut_answer, \ "Main calculation incorrect,got {} expected {}".format(mut_answer, answer) it.createTests(globals()) if __name__ == '__main__': nose2.main() # pragma: no cover
import aubio.cmd from nose2 import main from numpy.testing import TestCase class aubio_cmd(TestCase): def setUp(self): self.a_parser = aubio.cmd.aubio_parser() def test_default_creation(self): try: assert self.a_parser.parse_args(['-V']).show_version except SystemExit: url = 'https://bugs.python.org/issue9253' self.skipTest('subcommand became optional in py3, see %s' % url) class aubio_cmd_utils(TestCase): def test_samples2seconds(self): self.assertEqual(aubio.cmd.samples2seconds(3200, 32000), "0.100000\t") def test_samples2milliseconds(self): self.assertEqual(aubio.cmd.samples2milliseconds(3200, 32000), "100.000000\t") def test_samples2samples(self): self.assertEqual(aubio.cmd.samples2samples(3200, 32000), "3200\t") if __name__ == '__main__': main()
'''Fetches a map report given test_map_list having completed with success.''' actions = api_actions.QGActions(cache_connection = self.cache_instance) map_reports = self.subtest_map_list(actions) self.assertIsNotNone(map_reports) self.assertGreaterEqual(len(map_reports),1) mapr = actions.fetchReport(id=1882082) self.assertIsNotNone(mapr) self.assertGreaterEqual(len(mapr),1) self.assertIsInstance(mapr[0], api_objects.MapReport) logging.debug(mapr) #now do tests on the map report def test_report_list(self): ''' Pulls a list of scans''' actions = api_actions.QGActions(cache_connection = self.cache_instance) scans = actions.listScans(state='Finished') self.assertGreaterEqual(len(scans),1) #for counter,scan in enumerate(scans): # logging.debug('%02d:\r%s' % (counter, scan)) #stand-alone test execution if __name__ == '__main__': import nose2 nose2.main(argv=['fake', '--log-capture'])
def testTimeNumberAsString(self): """ This test checks that GetTimeNumberAsString returns a string, and when converting this string to a number, the number is an int. """ timeString = OpTime.GetTimeNumberAsString(OpTime.GetTime()) self.failUnless(isinstance(timeString, basestring)) timeInt = int(timeString) timeFloat = float(timeString) self.failUnless(timeInt == timeFloat) def testTimeString(self): print OpTime.GetTimeString() def testDiffTimeString(self): msg = "The tested method does not return proper strings." elapsed = OpTime.GetDiffTimeString(5) self.failUnless(elapsed.find('seconds') > -1, msg) elapsed = OpTime.GetDiffTimeString(65) self.failUnless(elapsed.find('minutes') > -1, msg) elapsed = OpTime.GetDiffTimeString(3605) self.failUnless(elapsed.find('hours') > -1, msg) if __name__ == '__main__': #optest.main() cfg_path = os.path.normpath( os.path.join(os.environ['OPTOOLBOX'], '..', 'tests', 'unittest.cfg')) argv = [sys.argv[0], '--config', cfg_path] nose2.main(module='testOpTime', argv=argv)
it.assertIn(k, case.actual) try: it.assertEqual(getattr(case.actual, k), v) except Exception as ex: it.fail(ex) @it.should('Be able to delete items using dictionary-style notation (e.g. del obj[name])') def test_item_deletion(case): for k, v in case.expected.items(): it.assertIn(k, case.actual) try: del case.actual[k] it.assertNotIn(k, case.actual) except Exception as ex: it.fail(ex) @it.should('Be able to delete items using object-style notation (e.g. del obj.name)') def test_attr_deletion(case): for k, v in case.expected.items(): it.assertIn(k, case.actual) try: delattr(case.actual, k) it.assertNotIn(k, case.actual) except Exception as ex: it.fail(ex) it.createTests(globals()) if __name__ == '__main__': nose2.main(verbosity=3)
self.assertIsNotNone(tv) myplug.set_launcher('bogus') self.assertEquals(myplug.launcher(), 'bogus') myplug.set_launcher(tv) tv = myplug.nvim_python() self.assertIsNotNone(tv) tv = myplug.nvim_python3() self.assertIsNotNone(tv) tv = myplug.entrypoint() self.assertIsNotNone(tv) myplug.set_entrypoint('bogus') self.assertEquals(myplug.entrypoint(), 'bogus') myplug.set_entrypoint(tv) tv = myplug.cbname() self.assertIsNotNone(tv) # test setting the venv myplug.set_curbuff_as_entrypoint_with_venv( buffname='/Users/magregor/src/pudb.vim/test/test_plugin.py') # stand-alone test execution if __name__ == '__main__': import nose2 logging.basicConfig(level=logging.DEBUG) logger.setLevel(logging.DEBUG) nose2.main(argv=[ 'fake', '--log-capture', 'TestPUDBPlugin.default_test', ])
def run_from_argv(self, argv): import nose2 with run_tests(): nose2.main(module=None, argv=argv[1:])