Changeset 188

Show
Ignore:
Timestamp:
12/31/06 00:53:56 (2 years ago)
Author:
akhavr
Message:

ticket:371:

Files:

Legend:

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

    • Property svn:ignore changed from
      *pass
      to
      *pass
      .coverage*
  • pybeast/trunk/ctest/Makefile

    r179 r188  
    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 coverage 
    1414 
    15 test: build $(test_results) 
     15pylint: test 
     16        $(MAKE) -C .. pylint 
     17 
     18test: build clean_coverage $(test_results) coverage 
     19 
     20coverage: 
     21        ./cov -c 
     22        ./cov -r -m ../src/*py 
    1623 
    1724build: 
    18         cd ../src; make 
     25        make -C ../src 
     26 
     27clean_coverage: 
     28        -rm .coverage* 
     29        ./cov -e 
    1930 
    2031clean: 
     
    2536%.pass :: %.py $(srcs) 
    2637        -rm $@ 
    27         PYTHONPATH=$(pythonpath) python $<&& touch $@ 
    28  
    29 # todo add coverage.py support 
     38        PYTHONPATH=$(pythonpath) ./cov -x -p $< && touch $@ 
    3039 
    3140# Deps 
  • pybeast/trunk/dtest/Makefile

    r179 r188  
    2626 
    2727clean_coverage: 
    28         rm .coverage* 
     28        -rm .coverage* 
    2929        ./cov -e 
    3030 
     
    3838        PYTHONPATH=$(pythonpath) ./cov -x -p $< && touch $@ 
    3939 
    40 # todo add coverage.py support 
    41  
    4240# Deps 
    4341 
  • pybeast/trunk/dtest/py2py.py

    r187 r188  
    1717class NeedSpace(unittest.TestCase): 
    1818    'Test need_space before current op function' 
     19 
     20    def test_no_code(self): 
     21        'Test when first letter to be emmitted' 
     22        self.failUnless(not Styler().need_space(['Stmt', 'Mul', 'Add'], ''), 
     23                        'Trying to put a space as a first code symbol') 
    1924     
    2025    def test_unary(self): 
     
    8590        formatter = Pep8Formatter() 
    8691        walk(ast, formatter) 
    87         msg = 'Failed to reformat \n%s\n correctly.\n AST: %s\nResult: \n%s' 
     92         
     93        msg = 'Failed to reformat \n-%s-\n correctly.\n AST: %s\nResult: \n-%s-' 
     94        if len(expr) and expr[-1] != '\n': 
     95            expr += '\n' 
    8896        self.failUnless(formatter.dump()==expr, 
    8997                        msg % (expr, ast, formatter.dump())) 
     
    389397        'Test unicode string' 
    390398        self.reformat_and_test('a = u\'string\'') 
     399 
     400 
     401class Import(Expr): 
     402    'Test import' 
     403 
     404    def test_simple(self): 
     405        'simple import' 
     406        self.reformat_and_test('import compiler\n') 
     407 
     408    def test_import_as(self): 
     409        'import as' 
     410        self.reformat_and_test('import compiler as c\n') 
     411 
     412    def test_import_from(self): 
     413        'from xyz import abc' 
     414        self.reformat_and_test('from unittest import TestCase') 
     415 
     416    def test_import_from_as(self): 
     417        'from xyz import abc as a' 
     418        self.reformat_and_test('from unittest import TestCase as tc') 
    391419         
    392420     
  • pybeast/trunk/src/py2py.py

    r187 r188  
    3636    def need_space(self, op_stack, code): 
    3737        'Determines if we need to put a space before a current op' 
     38        if len(code)==0: 
     39            return False 
     40         
    3841        if len(op_stack)<2: 
    3942            return True 
     
    8992 
    9093        need_parens_now = self.style.need_parens(self.expr_ops_stack) 
     94        if self.style.need_space(self.expr_ops_stack, self.code): 
     95            self.code += ' ' 
    9196        if need_parens_now: 
    92             self.code += ' (' 
     97            self.code += '(' 
    9398             
    9499        walker.dispatch(node.left) 
     
    232237                walker.dispatch(ifs) 
    233238 
     239    def visit_from(self, node, walker): 
     240        'visit From node (from xyz import abc)' 
     241        self.code += 'from %s import' % node.modname 
     242        for name in node.names: 
     243            self.code += ' %s' % name[0] 
     244            if name[1]: 
     245                self.code += ' as %s' % name[1] 
     246            self.code += ',' 
     247        self.code = self.code[:-1] 
     248 
     249    def visit_import(self, node, walker): 
     250        'visit Import node' 
     251        self.code += 'import ' 
     252        for name in node.names: 
     253            self.code += name[0] 
     254            if name[1]: 
     255                self.code += ' as %s' % name[1] 
     256            self.code += ', ' 
     257        self.code = self.code[:-2] 
     258 
    234259    def visit_keyword(self, node, walker): 
    235260        'visit Keyword node' 
     
    251276        defaults.reverse() 
    252277 
    253         self.code += ' lambda' 
     278        if self.style.need_space(self.expr_ops_stack, self.code): 
     279            self.code += ' ' 
     280        self.code += 'lambda' 
    254281 
    255282        prefix = '' 
     
    301328        self.code += str(node.name) 
    302329 
     330    def visit_stmt(self, node, walker): 
     331        'visit Stmt node' 
     332        for stmt_node in node.nodes: 
     333            walker.dispatch(stmt_node) 
     334            self.code += '\n' 
     335 
    303336    def visit_subscript(self, node, walker): 
    304337        'visit Subsvript node' 
     
    316349    def dump(self): 
    317350        'Return accumulated source code' 
    318         return self.code.strip() 
     351        return self.code 
    319352 
    320353    def map_operation(self, name, default):