Exemplo n.º 1
0
Arquivo: setup.py Projeto: dthng/cram
 def run(self):
     import doctest
     import cram
     failures, tests = doctest.testmod(cram)
     sys.stdout.write('doctests: %s/%s passed\n' %
                      (tests - failures, tests))
     os.environ['PYTHON'] = sys.executable
     if self.coverage:
         # Note that when coverage.py is run, it uses the version
         # of Python it was installed with, NOT the version
         # setup.py was run with.
         os.environ['COVERAGE'] = '1'
         os.environ['COVERAGE_FILE'] = os.path.abspath('./.coverage')
     cram.main(['-v', 'tests'])
Exemplo n.º 2
0
Arquivo: setup.py Projeto: myint/cram
 def run(self):
     import doctest
     import cram
     failures, tests = doctest.testmod(cram)
     sys.stdout.write('doctests: %s/%s passed\n' %
                      (tests - failures, tests))
     os.environ['PYTHON'] = sys.executable
     if self.coverage:
         # Note that when coverage.py is run, it uses the version
         # of Python it was installed with, NOT the version
         # setup.py was run with.
         os.environ['COVERAGE'] = '1'
         os.environ['COVERAGE_FILE'] = os.path.abspath('./.coverage')
     cram.main(['-v', 'tests'])
Exemplo n.º 3
0
def main(args):
    # paranoia: our script name is the same as the library we want
    # from an external repo, so delete the main in this module to
    # avoid accidental infinite recursion in case the imports bind the
    # wrong way. That shouldn't happen with the absolute_import change
    # above, but this saved a fair amount of confusion while setting up
    # this contraption.
    global main
    del main
    # Import the bogon cram from external
    from external import cram as fakecram
    # insert it into the start of sys.path
    sys.path.insert(0, os.path.dirname(fakecram.__file__))
    from cram import _main
    args = args[1:]
    unused_opts, paths, unused_getusage = _main._parseopts(args)
    td = tempfile.mkdtemp(dir=os.environ['TEST_TMPDIR'])
    for p in paths:
        dest = os.path.join(td, os.path.basename(p))
        shutil.copyfile(p, dest)
        for i, x in enumerate(args):
            if x == p:
                args[i] = dest
    # now we can import cram and be on our merry way
    import cram
    sys.exit(cram.main(args))
Exemplo n.º 4
0
    def run(self):
        import doctest
        import cram
        import pkgutil

        if getattr(pkgutil, 'walk_packages', None) is not None:
            def getmodules():
                """Yield all cram modules"""
                yield cram
                path = cram.__path__
                for loader, name, ispkg in pkgutil.walk_packages(path):
                    if name == '__main__':
                        continue
                    yield loader.find_module(name).load_module(name)
        else:
            def getmodules():
                """Yield all cram modules"""
                pkgdir = os.path.join(CRAM_DIR, 'cram')
                for root, dirs, files in os.walk(pkgdir):
                    if '__pycache__' in dirs:
                        dirs.remove('__pycache__')
                    for fn in files:
                        if not fn.endswith('.py') or fn == '__main__.py':
                            continue

                        modname = fn.replace(os.sep, '.')[:-len('.py')]
                        if modname.endswith('.__init__'):
                            modname = modname[:-len('.__init__')]
                        modname = '.'.join(['cram', modname])
                        if '.' in modname:
                            fromlist = [modname.rsplit('.', 1)[1]]
                        else:
                            fromlist = []

                        yield __import__(modname, {}, {}, fromlist)

        totalfailures = totaltests = 0
        for module in getmodules():
            failures, tests = doctest.testmod(module)
            totalfailures += failures
            totaltests += tests
        sys.stdout.write('doctests: %s/%s passed\n' %
                         (totaltests - totalfailures, totaltests))

        os.environ['PYTHON'] = sys.executable
        if self.coverage:
            # Note that when coverage.py is run, it uses the version
            # of Python it was installed with, NOT the version
            # setup.py was run with.
            os.environ['COVERAGE'] = '1'
            os.environ['COVERAGE_FILE'] = os.path.join(CRAM_DIR, '.coverage')

        args = ['-v']
        if self.xunit_file is not None:
            xunit_file = os.path.abspath(self.xunit_file)
            args.append('--xunit-file=%s' % pipes.quote(xunit_file))

        ret = cram.main(args + ['tests'])
        if ret or totalfailures:
            raise DistutilsError('tests failed')
Exemplo n.º 5
0
    def run(self):
        import cram
        import sys

        test_root = os.path.abspath("tests/cram")
        tests = [os.path.join(test_root, test) for test in os.listdir("tests/cram")]

        sys.exit(cram.main(tests))
Exemplo n.º 6
0
 def test_(self):
     self.assertFalse(
         main(['--shell', 'bash',
               os.path.join(DIR, test_name)]))
Exemplo n.º 7
0
 def run(self):
     import cram
     os.environ["PYTHON"] = sys.executable
     cram.main(["-v", "tests"])
Exemplo n.º 8
0
 def run_tests(self):
     import cram
     sys.exit(cram.main(['tests.t']))
Exemplo n.º 9
0
 def run_tests(self):
     import cram
     sys.exit(cram.main(['tests.t']))
Exemplo n.º 10
0
 def run(self):
     import cram
     os.environ["PYTHON"] = sys.executable
     cram.main(["-v", "tests"])
Exemplo n.º 11
0
#!/usr/bin/env python
import sys

import cram

try:
    sys.exit(cram.main(sys.argv[1:]))
except KeyboardInterrupt:
    pass
Exemplo n.º 12
0
def check_file(path):
    """Run cram over a single file, and return the number of
    failures."""
    return cram.main([str(path)])