def FromHandinDir(files_to_cover, test_pattern='test_.*\\.py$', stmt_weight=0.5, branch_weight=0.5): """Create a new :class:`CoverageScorer`. The files for the students to test is provided in `files_to_cover`, and the file name patterns of unit testing code is defined in `test_pattern`. The `stmt_weight` and the `branch_weight` may also be specified. :param files_to_cover: List of files to measure the coverage rate on. :type files_to_cover: :class:`list` of :class:`str` :param test_pattern: The regex pattern of testing code file names. :type test_pattern: :class:`str` :param stmt_weight: The weight of statement coverage rate. :type stmt_weight: :class:`float` :param branch_weight: The weight of branch coverage rate. :type branch_weight: :class:`float` """ p = re.compile(test_pattern) test_modules = [] for f in dirtree('.'): fpath, fext = os.path.splitext(f) if fext.lower() == '.py' and p.match(f): test_modules.append(fpath.replace('/', '.')) suite = lambda: unittest.TestLoader().loadTestsFromNames(test_modules) return CoverageScorer( suite=suite, filelist=files_to_cover, stmt_weight=stmt_weight, branch_weight=branch_weight, )
def FromHandinDir(ignore_files=None, logs=None): """Create a new :class:`CodeStyleScorer` for all files under the submission working directory unless they belong to `ignore_files`. :param ignore_files: A collection of file names to be ignored. """ ignore_files = ignore_files or [] if isinstance(ignore_files, str) or isinstance(ignore_files, unicode): ignore_files = [ignore_files] return CodeStyleScorer(dirtree("."), (lambda p: p in ignore_files), logs=logs)
def FromHandinDir(ignore_files=None): """Create a new :class:`CodeStyleScorer` for all files under the submission working directory unless they belong to `ignore_files`. :param ignore_files: A collection of file names to be ignored. """ ignore_files = ignore_files or [] if (isinstance(ignore_files, str) or isinstance(ignore_files, unicode)): ignore_files = [ignore_files] return CodeStyleScorer(dirtree('.'), (lambda p: p in ignore_files))
def prepare_hwcode(self): """Prepare the runner context by copying files from `hw/code` into :attr:`tempdir`. This method should be called before :meth:`extract_handin`. """ try: self.tempdir.copyfiles(self.hwcode.path, dirtree(self.hwcode.path), mode=0777) except Exception: logger.exception( "Cannot copy code files into tempdir for homework %(hwid)s " "when executing submission %(handid)s." % {"hwid": self.hw.uuid, "handid": self.uuid} ) raise RuntimeFileCopyFailure()
def prepare_hwcode(self): """Prepare the runner context by copying files from `hw/code` into :attr:`tempdir`. This method should be called before :meth:`extract_handin`. """ try: self.tempdir.copyfiles(self.hwcode.path, dirtree(self.hwcode.path), mode=0777) except Exception: logger.exception( 'Cannot copy code files into tempdir for homework %(hwid)s ' 'when executing submission %(handid)s.' % { 'hwid': self.hw.uuid, 'handid': self.uuid }) raise RuntimeFileCopyFailure()
def FromHandinDir(test_pattern='test_.*\\.py$'): """Create a new :class:`UnitTestScorer` on the given files. The :class:`unittest.suite.TestSuite` objects will be discovered and loaded from the files matching the given pattern when :meth:`do_run` is called. :param test_pattern: The regex pattern of file names. :type test_pattern: :class:`str` """ p = re.compile(test_pattern) test_modules = [] for f in dirtree('.'): fpath, fext = os.path.splitext(f) if fext.lower() == '.py' and p.match(f): test_modules.append(fpath.replace('/', '.')) suite = lambda: unittest.TestLoader().loadTestsFromNames(test_modules) return UnitTestScorer(suite=suite)
import sys sys.path.insert(0, os.path.split(os.path.dirname(__file__))[0]) from railgun.common.fileutil import dirtree if (len(sys.argv) < 4): print('patchall.py from-string to-string pattern [--commit]') sys.exit(0) fromstr = sys.argv[1] tostr = sys.argv[2] pattern = re.compile(sys.argv[3]) preview = not (len(sys.argv) >= 5 and sys.argv[4] == '--commit') flist = dirtree('.') for f in flist: if (not pattern.match(f) or f.startswith('env')): continue with open(f, 'rb') as fobj: inlines = fobj.read().split('\n') changed = False for i, line in enumerate(inlines, 1): pos = line.find(fromstr) if (pos < 0): continue print('%s:%d: %s' % (f, i, line)) inlines[i - 1] = line.replace(fromstr, tostr) changed = True
sys.path.insert(0, os.path.split(os.path.dirname(__file__))[0]) from railgun.common.fileutil import dirtree if len(sys.argv) < 4: print("patchall.py from-string to-string pattern [--commit]") sys.exit(0) fromstr = sys.argv[1] tostr = sys.argv[2] pattern = re.compile(sys.argv[3]) preview = not (len(sys.argv) >= 5 and sys.argv[4] == "--commit") flist = dirtree(".") for f in flist: if not pattern.match(f) or f.startswith("env"): continue with open(f, "rb") as fobj: inlines = fobj.read().split("\n") changed = False for i, line in enumerate(inlines, 1): pos = line.find(fromstr) if pos < 0: continue print("%s:%d: %s" % (f, i, line)) inlines[i - 1] = line.replace(fromstr, tostr) changed = True