예제 #1
0
def check_python_file(filename, errors):
    """Check each modified Python file to make sure it adheres to the
       standards"""
    temptest = re.compile('\s+def\s+temp_hide_test.*')
    test= re.compile('\s+def\s+(test_[abcdefghijklmnopqrstuvwxyz0123456789_]*)\(')
    tests=[]
    for (num, line) in enumerate(file(filename, "r")):
        _check_do_not_commit(line, filename, num, errors)
        if temptest.match(line):
            errors.append('%s:%d: Test case has the temp_hide_ prefix' \
                          % (filename, num+1))
        m= test.match(line)
        if line.startswith(">>>>>>> "):
            errors.append("%s:%d: error: Incomplete merge found."% (filename, num+1))
        if m:
            g= m.group(1)
            if g in tests:
                errors.append('%s:%d: Test case has multiple tests with the same name %s' \
                          % (filename, num+1, g))
            tests.append(m.group(1))
    fh = file(filename, "r")
    r = Reindenter(fh)
    try:
        if 'compat_python' not in filename and r.run():
            errors.append('Python file ' + filename + ' has odd indentation; ' \
                          + 'please run through tools/reindent.py first.')
    except Exception:
        print >> sys.stderr, "reindent.py FAILED on %s:" % filename
        raise
예제 #2
0
def check_file(ui, repo, path, rev):
    """Check a particular (file, revision) pair for whitespace issues.

    Return True if whitespace problems exist, else False.

    """
    ui.debug("checking file %s at revision %s for whitespace issues\n" %
             (path, node.short(repo[rev].node())))

    # Check Python files using reindent.py
    if path.endswith('.py'):
        content = StringIO(repo[rev][path].data())
        reindenter = Reindenter(content)
        if reindenter.run():
            ui.warn(" - file %s is not whitespace-normalized in %s\n"
                    % (path, str(repo[rev])))
            return True

    # Check ReST files for tabs and trailing whitespace
    elif path.endswith('.rst'):
        lines = StringIO(repo[rev][path].data()).readlines()
        for line in lines:
            if '\t' in line:
                ui.warn(" - file %s contains tabs in %s\n"
                        % (path, str(repo[rev])))
                return True

            elif line.rstrip('\r\n') != line.rstrip('\r\n '):
                ui.warn(" - file %s has trailing whitespace in %s\n"
                        % (path, str(repo[rev])))
                return True

    return False
예제 #3
0
def check_python_file(filename, errors):
    """Check each modified Python file to make sure it adheres to the
       standards"""
    fh = file(filename, "r")
    r = Reindenter(fh)
    if r.run():
        errors.append('Python file ' + filename + ' has odd indentation; ' \
                      + 'please run through reindent.py first.')
예제 #4
0
def check_python_file(filename, errors):
    """Check each modified Python file to make sure it adheres to the
       standards"""
    fh = file(filename, "r")
    r = Reindenter(fh)
    if r.run():
        errors.append('Python file ' + filename + ' has odd indentation; ' \
                      + 'please run through reindent.py first.')
예제 #5
0
	def testReindenter(self):
		with open('test_before.py') as before, open('test_after.py') as after:
			indenter = Reindenter(before, '\t')
			expected = after.readlines()
		
		self.assertTrue(indenter())
		self.assertEqual(indenter.after, expected)