Changeset 173

Show
Ignore:
Timestamp:
12/27/06 21:54:01 (2 years ago)
Author:
akhavr
Message:

ticket:370:

  • BoolOp formatting works
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pybeast/trunk/Makefile

    • Property svn:keywords set to Id
    r171 r173  
    1 # $Id: Makefile 79 2006-06-23 10:05:42Z akhavr
     1# $Id
    22# Copyright (C) 2001-2006 KDS Software Group http://www.kds.com.ua/ 
    33 
     
    1313test: 
    1414        $(MAKE) -C src build 
    15         $(MAKE) -C db test 
    16         $(MAKE) -C dtest 
    17         $(MAKE) -C ctest 
     15        $(MAKE) -C dtest test 
     16        $(MAKE) -C ctest test 
    1817 
    1918clean: 
  • pybeast/trunk/ctest

    • Property svn:ignore set to
      *pass
  • pybeast/trunk/ctest/Makefile

    • Property svn:keywords set to Id
    r171 r173  
    1 # $Id: Makefile 79 2006-06-23 10:05:42Z akhavr
     1# $Id
    22# Copyright (C) 2001-2006 KDS Software Group 
    33 
  • pybeast/trunk/dtest

    • Property svn:ignore set to
      *pass
      *pyc
  • pybeast/trunk/dtest/Makefile

    • Property svn:keywords set to Id
    r171 r173  
    1 # $Id: Makefile 79 2006-06-23 10:05:42Z akhavr
     1# $Id
    22# Copyright (C) 2001-2006 KDS Software Group 
    33 
     
    77test_results=$(test_scripts:.py=.pass) 
    88 
    9 pythonpath=..:../src 
     9pythonpath=.. 
    1010 
    1111# Targets 
    1212 
    13 .PHONY: build test clean 
     13.PHONY: pylint build test clean 
     14 
     15pylint: test 
     16        $(MAKE) -C .. pylint 
    1417 
    1518test: build $(test_results) 
  • pybeast/trunk/dtest/__init__.py

    r172 r173  
    22# Copyright (C) 2006 KDS Software Group http://www.kds.com.ua 
    33 
     4'''Developer tests for PyBeast - python mutation test checker 
     5 
     6Copyright (C) 2006 KDS Software Group http://www.kds.com.ua 
     7 
     8License: GPL v.2 
     9''' 
  • pybeast/trunk/dtest/py2py.py

    r172 r173  
    22# Copyright (C) 2006 KDS Software Group http://www.kds.com.ua 
    33 
    4 from src.py2py import Pep8Formatter 
     4'''Test src.py2py''' 
     5 
     6from src.py2py import Pep8Formatter, walk 
    57 
    68import compiler 
    79import unittest 
    810 
    9 class BoolOp(unittest.TestCase): 
    10     def testEmpty(self): 
    11         expr = '' 
     11class Expr(unittest.TestCase): 
     12    '''Test src.py2py.Pep8Formatter expr handling ''' 
     13 
     14    def reformat_and_test(self, expr): 
     15        'Parse expr into ast and generate the code back.  Compare and shout' 
    1216        ast = compiler.parse(expr) 
    1317        formatter = Pep8Formatter() 
    14         compiler.walk(ast, formatter) 
     18        walk(ast, formatter) 
     19        msg = 'Failed to reformat "%s" correctly.\n AST: %s\nResult: %s' 
    1520        self.failUnless(formatter.dump()==expr, 
    16                         'Failed to reformat "%s" correctly: %s' % ( 
    17             expr, formatter.dump())) 
    18         return 
     21                        msg % (expr, ast, formatter.dump())) 
     22     
     23    def test_empty_expression(self): 
     24        'Test empty expression'         
     25        self.reformat_and_test('') 
     26 
     27    def test_bool_and(self): 
     28        'Test Bool And expression' 
     29        self.reformat_and_test('a = 1 and 2') 
     30 
     31    def test_bool_and_with_var(self): 
     32        'Test Bool And expression that includes variables' 
     33        self.reformat_and_test('a = a and 1') 
     34 
     35    def test_bool_or(self): 
     36        'Test Bool Or expression' 
     37        self.reformat_and_test('a = 1 or 2') 
     38 
    1939    pass 
    2040 
    21 if __name__=='__main__': unittest.main() 
     41if __name__ == '__main__': 
     42    unittest.main() 
  • pybeast/trunk/src

    • Property svn:ignore set to
      *pyc
  • pybeast/trunk/src/Makefile

    • Property svn:keywords set to Id
    r171 r173  
    1 # $Id: Makefile 79 2006-06-23 10:05:42Z akhavr
     1# $Id
    22# Copyright (C) 2001-2006 KDS Software Group 
    33 
    44build: 
    55 
     6pylint: test 
     7        $(MAKE) -C .. pylint 
     8 
    69test: 
    7         cd ..; $(MAKE) test 
     10        $(MAKE) -C .. test 
    811 
    912clean: 
  • pybeast/trunk/src/__init__.py

    r172 r173  
    22# Copyright (C) 2006 KDS Software Group http://www.kds.com.ua 
    33 
     4'''PyBeast source code - python mutation test checker 
     5 
     6Copyright (C) 2006 KDS Software Group http://www.kds.com.ua 
     7 
     8License: GPL v.2 
     9''' 
  • pybeast/trunk/src/py2py.py

    r172 r173  
    22# Copyright (C) 2006 KDS Software Group http://www.kds.com.ua 
    33 
     4'''Dump python AST into a source code''' 
     5 
     6import compiler 
     7import compiler.ast 
     8 
    49class Pep8Formatter: 
    5     def dump(self): return '' 
     10    'Dump python AST into a PEP8-comforming source code' 
     11 
     12    def __init__(self): 
     13        self.code = '' 
     14 
     15    def visitAnd(self, node, walker): 
     16        'visit And node' 
     17        for subnode in node.nodes: 
     18            walker.dispatch(subnode) 
     19            self.code += ' and' 
     20            continue 
     21        self.code = self.code[:-4] 
     22 
     23    def visitAssName(self, node, *args): 
     24        'visit AssName node' 
     25        self.code += str(node.name) 
     26        if node.flags == 'OP_ASSIGN': 
     27            self.code += ' =' 
     28        return 
     29 
     30    def visitConst(self, node, *args): 
     31        'visit Const node' 
     32        self.code += ' ' + str(node.value) 
     33 
     34    def visitName(self, node, *args): 
     35        'visit Name node' 
     36        self.code += ' ' + str(node.name) 
     37 
     38    def visitOr(self, node, walker): 
     39        'visit Or node' 
     40        for subnode in node.nodes: 
     41            walker.dispatch(subnode) 
     42            self.code += ' or' 
     43            continue 
     44        self.code = self.code[:-3] 
     45 
     46    def dump(self): 
     47        'Return accumulated source code' 
     48        return self.code 
    649    pass 
     50 
     51class ASTDeepWalker(compiler.visitor.ASTVisitor): 
     52    ''' 
     53    compiler.visitor.ASTWalker modified to allow processing nodes 
     54    to call back to continue depth-first traversal 
     55    ''' 
     56     
     57    def dispatch(self, node, *args): 
     58        'modified dispatch method' 
     59        self.node = node 
     60        klass = node.__class__ 
     61        meth = self._cache.get(klass, None) 
     62        if meth is None: 
     63            meth = getattr(self.visitor, 'visit' + klass.__name__, self.default) 
     64            self._cache[klass] = meth 
     65        return meth(node, self) 
     66 
     67def walk(ast, formatter): 
     68    'Walk AST using supplied formatter and ASTDeepWalker' 
     69    compiler.walk(ast, formatter, ASTDeepWalker()) 
     70