示例#1
0
 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)
示例#2
0
 def test_find_argparse_locates_assignment_stmnt_in_main(self):
   nodes = ast.parse(source_parser._openfile(self._module_with_argparse_in_main))
   main_node = source_parser.find_main(nodes)
   self.assertEqual('main', main_node.name)
   containing_block = source_parser.find_block_containing_argparse([main_node])
   self.assertTrue(containing_block is not None)
   self.assertEqual('main', containing_block.name)
示例#3
0
 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)
示例#4
0
 def test_find_argparse_locates_assignment_stmnt_in_main(self):
   nodes = ast.parse(source_parser._openfile(self._module_with_argparse_in_main))
   main_node = source_parser.find_main(nodes)
   self.assertEqual('main', main_node.name)
   containing_block = source_parser.find_block_containing_argparse([main_node])
   self.assertTrue(containing_block is not None)
   self.assertEqual('main', containing_block.name)
示例#5
0
 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))
示例#6
0
 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))
示例#7
0
  def test_find_argparse_located_object_when_access_through_module_dot_notation(self):
    example_source = '''
def main():
  parser = argparse.ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
    '''
    nodes = ast.parse(example_source)
    main_node = source_parser.find_main(nodes)
    self.assertEqual('main', main_node.name)
    containing_block = source_parser.find_block_containing_argparse([main_node])
    self.assertTrue(containing_block is not None)
示例#8
0
  def test_find_argparse_located_object_when_access_through_module_dot_notation(self):
    example_source = '''
def main():
  parser = argparse.ArgumentParser(description='Example Argparse Program', formatter_class=RawDescriptionHelpFormatter)
    '''
    nodes = ast.parse(example_source)
    main_node = source_parser.find_main(nodes)
    self.assertEqual('main', main_node.name)
    containing_block = source_parser.find_block_containing_argparse([main_node])
    self.assertTrue(containing_block is not None)