Example #1
0
File: cli.py Project: kvarq/kvarq
 def run(self):
     try:
         self.analyser.spacing = args.spacing
         self.analyser.scan(fastq, testsuites, do_reverse=not args.no_reverse)
         self.finished = True
     except Exception, e:
         self.exception = e
         self.traceback = format_traceback(sys.exc_info())
Example #2
0
File: genes.py Project: kvarq/kvarq
def load_testsuite(fname):
    """
    :param fname: path of ``.py`` testsuite file

    loads a modular testsuite from a file; see :ref:`testsuites`

    **beware** that the testsuite is a python file and can execute arbitrary
    code

    raises :py:class:`TestsuiteLoadingException` if file format of specified
    testsuite is invalid
    """

    name = os.path.splitext(os.path.basename(fname))[0]
    if "-" in name:
        name = name[: name.index("-")]
    namespace = dict(__file__=fname, __module__="kvarq.testsuites." + name)

    try:
        sys.path.insert(0, os.path.dirname(fname))
        execfile(fname, namespace)
        del sys.path[0]
    except Exception as e:
        raise TestsuiteLoadingException(
            "exception while reading file : %s [%s]" % (str(e), format_traceback(sys.exc_info()))
        )

    if not "GENES_COMPATIBILITY" in namespace:
        raise TestsuiteLoadingException('module defines no "GENES_COMPATIBILITY"')

    compat = StrictVersion(namespace["GENES_COMPATIBILITY"])
    version = StrictVersion(COMPATIBILITY)

    if compat > version or compat.version[0] != version.version[0]:
        raise TestsuiteLoadingException("incompatible : %s needed, got %s" % (compat, version))

    if not name in namespace:
        raise TestsuiteLoadingException('could not import "%s"' % name)
    if not isinstance(namespace[name], Testsuite):
        raise TestsuiteLoadingException('modules defines "%s" but is of type %s' % type(namespace[name]))

    return namespace[name]