def test_find_argparse_throws_exception_if_not_found(self): with self.assertRaises(source_parser.ParserError): nodes = ast.parse(source_parser._openfile(self._module_with_noargparse)) main_node = source_parser.find_main(nodes) self.assertEqual('main', main_node.name) try_nodes = source_parser.find_try_blocks(main_node) containing_block = source_parser.find_block_containing_argparse([main_node] + try_nodes)
def test_find_argparse_locates_assignment_stmnt_in_try_block(self): nodes = ast.parse(source_parser._openfile(self._module_with_arparse_in_try)) main_node = source_parser.find_main(nodes) self.assertEqual('main', main_node.name) try_nodes = source_parser.find_try_blocks(main_node) self.assertTrue(len(try_nodes) > 0) containing_block = source_parser.find_block_containing_argparse([main_node] + try_nodes) self.assertEqual(ast.TryExcept, type(containing_block))
def test_find_argparse_throws_exception_if_not_found(self): with self.assertRaises(source_parser.ParserError): nodes = ast.parse( source_parser._openfile(self._module_with_noargparse)) main_node = source_parser.find_main(nodes) self.assertEqual('main', main_node.name) try_nodes = source_parser.find_try_blocks(main_node) containing_block = source_parser.find_block_containing_argparse( [main_node] + try_nodes)
def test_find_argparse_locates_assignment_stmnt_in_try_block(self): nodes = ast.parse( source_parser._openfile(self._module_with_arparse_in_try)) main_node = source_parser.find_main(nodes) self.assertEqual('main', main_node.name) try_nodes = source_parser.find_try_blocks(main_node) self.assertTrue(len(try_nodes) > 0) containing_block = source_parser.find_block_containing_argparse( [main_node] + try_nodes) self.assertEqual(ast.TryExcept, type(containing_block))
def test_find_try_blocks_finds_all_tryblock_styles(self): example_source = ''' try: a = 1 except: pass try: pass finally: pass try: pass except: pass else: pass ''' nodes = ast.parse(example_source) try_blocks = source_parser.find_try_blocks(nodes) self.assertEqual(3, len(try_blocks))
def test_find_try_blocks_returns_empty_if_no_blocks_present(self): example_source = 'def main(): pass' nodes = ast.parse(example_source) result = source_parser.find_try_blocks(nodes) self.assertEqual(list(), result)