示例#1
0
    def testAntGlob(self):
        files = util.ant_glob('**/*.py')
        self.assertEqual(6, len(files))

        desired = set((os.path.abspath(a)
                       for a in os.listdir('.') if a.endswith('.py')))
        actual = set((os.path.abspath(a) for a in files))
        self.assertEqual(0, len(actual.symmetric_difference(desired)))
示例#2
0
def main(monitors, cfg):
    # ant_glob for testcases
    testpattern = cfg.get('replayer', 'testcase')
    testcases = util.ant_glob(testpattern)

    log.info('collected %d test cases' % len(testcases))
    log.debug(`testcases`)

    assert len(monitors) > 0, 'No monitors available'

    # Load oracles
    oracles = []
    oracle_names = cfg.get('replayer', 'oracles')
    if len(oracle_names.strip()) != 0:
        for pkg, class_ in (s.strip().rsplit('.', 1)
                                for s in oracle_names.split(',')):
            try:
                oracle = getattr(__import__(pkg,fromlist=[class_]), class_)()
                oracle.add_options(cfg)
                oracles.append(oracle)
                log.info('loaded oracle %r' % oracle)
            except (ImportError, AttributeError):
                log.warn('could not load oracle %s.%s' % (pkg, class_))

    lock = threading.Lock()
    steptime = float(cfg.get('general', 'steptime'))
    out_dir = cfg.get('replayer', 'state_dir')
    if not os.path.exists(out_dir):
        log.debug('creating folder %s' % os.path.abspath(out_dir))
        os.makedirs(out_dir)
    results = Results()
    replayers = [ Replayer(monitor = m,
                           config = cfg,
                           oracles = oracles,
                           testcases = testcases,
                           lock = lock,
                           steptime = steptime,
                           out_dir = out_dir,
                           results = results)
                  for m in monitors ]

    for replayer in replayers:
        replayer.start()

    while any(( replayer.is_alive() for replayer in replayers )):
        time.sleep(steptime)

    results_file = cfg.get('replayer', 'results')
    with open(results_file, 'w') as f:
        f.write( results.xmlreport().toprettyxml(indent = '  ') )

    return 0 if not interrupt else 1
示例#3
0
 def testParent(self):
     files = util.ant_glob('../test/util.py')
     self.assertEqual(1, len(files))
     desired = os.path.abspath('util.py')
     actual = os.path.abspath(files[0])
     self.assertEqual(desired, actual)