Example #1
0
def main(tests=None):
    if not tests:
        tests = set(os.path.basename(x) for x in glob.glob(cwd + '/*.py'))
        tests = sorted(tests)

    failed = []

    for filename in tests:
        if filename in ignore:
            continue
        min_time, max_time = time_ranges.get(filename, default_time_range)

        start = time.time()
        if util.run([sys.executable, '-u', filename],
                    timeout=max_time,
                    cwd=cwd):
            failed.append(filename)
        else:
            took = time.time() - start
            if took < min_time:
                util.log(
                    '! Failed example %s: exited too quickly, after %.1fs (expected %.1fs)',
                    filename, took, min_time)
                failed.append(filename)

    if failed:
        util.log('! Failed examples:\n! - %s', '\n! - '.join(failed))
        sys.exit(1)

    if not tests:
        sys.exit('No tests.')
Example #2
0
 def run_one(cmd, **kwargs):
     kwargs['quiet'] = quiet
     result = util.run(cmd, **kwargs)
     if result:
         if failfast:
             sys.exit(1)
         failed[result.name] = [cmd, kwargs]
     else:
         passed[result.name] = True
    def test(self):
        log = []

        def handle(message, address):
            log.append(message)
            server.sendto(b'reply-from-server', address)

        server = DatagramServer('127.0.0.1:9000', handle)
        server.start()
        try:
            run([
                sys.executable, '-W', 'ignore'
                '-u', 'udp_client.py', 'Test_udp_client'
            ],
                timeout=10,
                cwd='../../examples/')
        finally:
            server.close()
        self.assertEqual(log, [b'Test_udp_client'])
Example #4
0
 def test_runs(self):
     start = time.time()
     min_time, max_time = self.time_range
     if util.run([sys.executable, '-u', self.filename],
                 timeout=max_time,
                 cwd=cwd,
                 quiet=True,
                 buffer_output=True,
                 nested=True,
                 setenv={'GEVENT_DEBUG': 'error'}):
         self.fail("Failed example: " + self.filename)
     else:
         took = time.time() - start
         self.assertGreaterEqual(took, min_time)