def testFindTestsAsArgs(self): """Test finding of tests passed as args.""" self.args += '--' self.args += self.sample_test_names c = coverage.Coverage(self.options, self.args) c.FindTests() self.confirmSampleTestsArePresent(c.tests)
def testRunBasicProcess(self): """Test a simple run of a subprocess.""" c = coverage.Coverage(self.options, self.args) for code in range(2): retcode = c.Run([ sys.executable, '-u', '-c', 'import sys; sys.exit(%d)' % code ], ignore_error=True) self.assertEqual(code, retcode)
def testFindTestsFromBundleFile(self): """Test finding of tests from a bundlefile.""" (fd, filename) = tempfile.mkstemp() f = os.fdopen(fd, 'w') f.write(str(self.sample_test_names)) f.close() self.options.bundles = filename c = coverage.Coverage(self.options, self.args) c.FindTests() self.confirmSampleTestsArePresent(c.tests) os.unlink(filename)
def testExclusionList(self): """Test the gtest_filter exclusion list.""" c = coverage.Coverage(self.options, self.args) self.assertFalse(c.GtestFilter('doesnotexist_test')) fake_exclusions = { sys.platform: { 'foobar': ('a', 'b'), 'doesnotexist_test': ('Evil.Crash', 'Naughty.Test') } } self.assertFalse(c.GtestFilter('barfoo')) filter = c.GtestFilter('doesnotexist_test', fake_exclusions) self.assertEquals('--gtest_filter=-Evil.Crash:-Naughty.Test', filter)
def testRunExcessivelySlowProcess(self): """Test program which DOES hit our timeout. Initial lines should print but quickly it takes too long and should be killed. """ self.options.timeout = 2.5 c = coverage.Coverage(self.options, self.args) slowscript = ('import time\n' 'for x in range(1,10):\n' ' print "sleeping for %d" % x\n' ' time.sleep(x)\n') self.assertRaises(Exception, c.Run, [sys.executable, '-u', '-c', slowscript])
def testRunSlowProcess(self): """Test program which prints slowly but doesn't hit our timeout. Overall runtime is longer than the timeout but output lines trickle in keeping things alive. """ self.options.timeout = 2.5 c = coverage.Coverage(self.options, self.args) slowscript = ('import sys, time\n' 'for x in range(10):\n' ' time.sleep(0.5)\n' ' print "hi mom"\n' 'sys.exit(0)\n') retcode = c.Run([sys.executable, '-u', '-c', slowscript]) self.assertEqual(0, retcode)
def testSanity(self): """Sanity check we're able to actually run the tests. Simply creating a Coverage instance checks a few things (e.g. on Windows that the coverage tools can be found).""" c = coverage.Coverage(self.options, self.args)