def assert_failures_in_file(source_file, expected_failures): """Checks the output of Proboscis run for expected failures.""" failures = FailureLines(source_file, expected_failures) # Iterate the output, find all lines of text with the words FAIL or ERROR # and add them to a collection of "actual" failures that can be checked # against expected failures. # 2.7 seems to put the important parts on the next line, while 2.6 has it # on the same line. # I think Nose may also use this first format. if is_jython() or sys.version_info < (2, 7) \ or proboscis.dependencies.use_nose: for line in open(source_file, 'r'): if "FAIL: " in line: failures.add_actual(line[6:].strip()) elif "ERROR: " in line: failures.add_actual(line[7:].strip()) else: error_next = False for line in open(source_file, 'r'): if error_next: failures.add_actual(line.strip()) error_next = False if "ERROR: " in line or "FAIL: " in line: error_next = True failures.assert_all()
def time_out(time): """Raises TimeoutError if the decorated method does not finish in time.""" if compatability.is_jython(): raise ImportError("Not supported.") def cb_timeout(signum, frame): raise TimeoutError("Time out after waiting " + str(time) + " seconds.") def return_method(func): """Turns function into decorated function.""" @wraps(func) def new_method(*kargs, **kwargs): previous_handler = signal.signal(signal.SIGALRM, cb_timeout) try: signal.alarm(time) return func(*kargs, **kwargs) finally: signal.alarm(0) signal.signal(signal.SIGALRM, previous_handler) return new_method return return_method
self.plan.filter(classes=[RandomTestOne]) filtered = self.plan.tests # Should include RandomTestOne, which depends on RandomTestZero, # which depends on init self.assertEqual(3, len(filtered)) from proboscis_example import StartUp self.assertEqual(StartUp, filtered[0].entry.home) from proboscis_example import RandomTestZero self.assertEqual(RandomTestZero, filtered[1].entry.home) self.assertEqual(RandomTestOne, filtered[2].entry.home) if not compatability.is_jython(): @time_out(2) def lackadaisical_multiply(a, b): sum = 0 for i in range(0, b): time.sleep(1) sum = sum + a return sum class TestTimeoutDecorator(unittest.TestCase): def test_should_not_time_out_before_time_exceeded(self): self.assertEqual(0, lackadaisical_multiply(4, 0)) self.assertEqual(8, lackadaisical_multiply(8, 1)) def test_should_timeout_if_time_exceeded(self):
are in tests/proboscis_test.py. """ import os import sys from proboscis.asserts import assert_equal from os.path import join import proboscis from proboscis.compatability import capture_exception from proboscis.compatability import is_jython from proboscis.compatability import reload CAN_USE_WITH = not is_jython() def fake_exit(*args, **kwargs): pass def make_dirs(dir): if not os.path.exists(dir): os.makedirs(dir) def reload_proboscis(): """ Reloading Proboscis like this causes problems- for instance, exceptions aren't caught because the exception to be caught is a
These are basically the higher order tests for Proboscis. Some unit tests are in tests/proboscis_test.py. """ import os import sys from proboscis.asserts import assert_equal from os.path import join import proboscis from proboscis.compatability import capture_exception from proboscis.compatability import is_jython from proboscis.compatability import reload CAN_USE_WITH = not is_jython() def fake_exit(*args, **kwargs): pass def make_dirs(dir): if not os.path.exists(dir): os.makedirs(dir) def reload_proboscis(): """ Reloading Proboscis like this causes problems- for instance, exceptions aren't caught because the exception to be caught is a