Beispiel #1
0
def fileExtractor(sheet):
    function_name = ''  #name of the function which returns the list of objects
    group = {}  #group
    index_of_group = {}  #index of group
    index_of_function = []  #index of the function specification
    body = []  # contains the list of all the body data
    indexes_of_body = []  #indexes of the body data
    excel_function = []  #stores all the excel functions which user specified
    index_of_excel_function = []  #indexes of excel function
    body_input = []  #store input value of body
    indexes_of_body_input = []  #store index of body input
    head = {}  #store header
    index_of_head = {}  #store indexes of head,
    head_input = {}  #store head input
    index_of_head_input = {}  #store index of head input
    foot = {}
    index_of_foot = {}
    foot_input = {}
    index_of_foot_input = {}
    once = []
    index_of_once = []
    once_input = []
    index_of_once_input = []
    reserve_postions = []

    #read information user specified
    for col_x in range(sheet.ncols):
        for row_x in range(sheet.nrows):
            value = sheet.cell(row_x, col_x).value  # value in the excel file
            if value:  #if the cell contains data

                #call the function to extract information
                temp_function_name = extract_information(
                    index_of_function, index_of_group, body, indexes_of_body,
                    index_of_excel_function, excel_function, value, row_x,
                    col_x, [], [], body_input, indexes_of_body_input, head,
                    index_of_head, head_input, index_of_head_input, foot,
                    index_of_foot, foot_input, index_of_foot_input, once,
                    index_of_once, once_input, index_of_once_input, group,
                    reserve_postions)

                #append the function_name and the group
                function_name += temp_function_name
    return function_name, index_of_function, group, index_of_group, body, indexes_of_body, index_of_excel_function, excel_function, body_input, indexes_of_body_input, head, index_of_head, head_input, index_of_head_input, foot, index_of_foot, foot_input, index_of_foot_input, once, index_of_once, once_input, index_of_once_input, reserve_postions
Beispiel #2
0
def fileExtractor(sheet):
    function_name = ''#name of the function which returns the list of objects
    group = {} #group
    index_of_group = {} #index of group
    index_of_end_group = {}
    index_of_function = [] #index of the function specification
    body = [] # contains the list of all the body data
    indexes_of_body = [] #indexes of the body data
    excel_function = [] #stores all the excel functions which user specified
    index_of_excel_function = [] #indexes of excel function
    body_input = [] #store input value of body
    indexes_of_body_input = [] #store index of body input
    head = {}#store header
    index_of_head = {} #store indexes of head,
    head_input = {} #store head input
    index_of_head_input = {} #store index of head input
    foot = {}
    index_of_foot = {}
    foot_input = {}
    index_of_foot_input = {}
    once = []
    index_of_once = []
    once_input = []
    index_of_once_input = []
    reserve_postions = []
    
    #read information user specified
    for col_x in range(sheet.ncols):
        for row_x in range(sheet.nrows):
            value = sheet.cell(row_x,col_x).value # value in the excel file
            if value: #if the cell contains data

                #call the function to extract information
                temp_function_name = extract_information(index_of_function, index_of_group, body, indexes_of_body,index_of_excel_function, excel_function, value, row_x, col_x,[],[], body_input, indexes_of_body_input, head, index_of_head, head_input, index_of_head_input, foot, index_of_foot, foot_input, index_of_foot_input, once, index_of_once, once_input, index_of_once_input, group, reserve_postions, index_of_end_group)

                #append the function_name and the group
                function_name += temp_function_name
    return function_name, index_of_function, group, index_of_group, body, indexes_of_body, index_of_excel_function, excel_function, body_input, indexes_of_body_input, head, index_of_head, head_input, index_of_head_input, foot, index_of_foot, foot_input, index_of_foot_input, once, index_of_once, once_input, index_of_once_input, reserve_postions, index_of_end_group
Beispiel #3
0
    def test_extract_information_function(self):
        index_of_function = []
        index_of_head = []
        body = []
        indexes_of_body = []
        index_of_excel_function = []
        excel_function = []
        other_info = []
        index_of_other_info = []

        #call function to test function_name extraction
        function_name, head = extract_information(
            index_of_function, index_of_head, body, indexes_of_body,
            index_of_excel_function, excel_function, '#<function()>', 1, 2,
            other_info, index_of_other_info)
        self.assertEqual(
            function_name,
            'function()')  #test if the function_name is extracted correctly
        self.assertEqual(head, '')  #test if the head is extracted correctly
        self.assertEqual(index_of_function, [
            (1, 2)
        ])  #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head, [])  #the index of head should be empty
        self.assertEqual(body, [])  #the body should be empty
        self.assertEqual(indexes_of_body,
                         [])  #the index of body should be empty
        self.assertEqual(index_of_excel_function,
                         [])  #the index of excel function should be empty
        self.assertEqual(excel_function,
                         [])  #the excel function list should be empty
        self.assertEqual(other_info, [])  #other information should be empty
        self.assertEqual(index_of_other_info,
                         [])  #index of other information should be empty

        #test for head extraction
        function_name, head = extract_information(
            index_of_function, index_of_head, body, indexes_of_body,
            index_of_excel_function, excel_function, '{{head:head}}', 1, 2,
            other_info, index_of_other_info)
        self.assertEqual(function_name,
                         '')  #test if the function_name is extracted correctly
        self.assertEqual(head,
                         'head')  #test if the head is extracted correctly
        self.assertEqual(index_of_function, [
            (1, 2)
        ])  #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,
                         [(1, 2)])  #the index of head should be [(1,2)]
        self.assertEqual(body, [])  #the body should be empty
        self.assertEqual(indexes_of_body,
                         [])  #the index of body should be empty
        self.assertEqual(index_of_excel_function,
                         [])  #the index of excel function should be empty
        self.assertEqual(excel_function,
                         [])  #the excel function list should be empty
        self.assertEqual(other_info, [])  #other information should be empty
        self.assertEqual(index_of_other_info,
                         [])  #index of other information should be empty

        #test for body extraction
        function_name, head = extract_information(
            index_of_function, index_of_head, body, indexes_of_body,
            index_of_excel_function, excel_function, '{{body:body}}', 1, 2,
            other_info, index_of_other_info)
        self.assertEqual(function_name,
                         '')  #test if the function_name is extracted correctly
        self.assertEqual(head, '')  #test if the head is extracted correctly
        self.assertEqual(index_of_function, [
            (1, 2)
        ])  #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,
                         [(1, 2)])  #the index of head should be [(1,2)]
        self.assertEqual(body, ['body'])  #the body should be ['body']
        self.assertEqual(indexes_of_body,
                         [(1, 2)])  #the index of body should be empty
        self.assertEqual(index_of_excel_function,
                         [])  #the index of excel function should be empty
        self.assertEqual(excel_function,
                         [])  #the excel function list should be empty
        self.assertEqual(other_info, [])  #other information should be empty
        self.assertEqual(index_of_other_info,
                         [])  #index of other information should be empty

        #test for excel_function extraction
        function_name, head = extract_information(
            index_of_function, index_of_head, body, indexes_of_body,
            index_of_excel_function, excel_function,
            ':= "{{body:body2}}" + "tung"', 1, 2, other_info,
            index_of_other_info)
        self.assertEqual(function_name,
                         '')  #test if the function_name is extracted correctly
        self.assertEqual(head, '')  #test if the head is extracted correctly
        self.assertEqual(index_of_function, [
            (1, 2)
        ])  #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,
                         [(1, 2)])  #the index of head should be [(1,2)]
        self.assertEqual(
            body, ['body', 'body2'])  #the body should be ['body', 'body2']
        self.assertEqual(indexes_of_body,
                         [(1, 2), (1, 2)])  #the index of body should be empty
        self.assertEqual(
            index_of_excel_function,
            [(1, 2)])  #the index of excel function should be [(1,2)]
        self.assertEqual(excel_function,
                         [':= "{{body:body2}}" + "tung"'
                          ])  #the excel function list should be correct
        self.assertEqual(other_info, [])  #other information should be empty
        self.assertEqual(index_of_other_info,
                         [])  #index of other information should be empty

        #test for other information extraction:
        function_name, head = extract_information(
            index_of_function, index_of_head, body, indexes_of_body,
            index_of_excel_function, excel_function, 'tung', 1, 2, other_info,
            index_of_other_info)
        self.assertEqual(function_name,
                         '')  #test if the function_name is extracted correctly
        self.assertEqual(head, '')  #test if the head is extracted correctly
        self.assertEqual(index_of_function, [
            (1, 2)
        ])  #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,
                         [(1, 2)])  #the index of head should be [(1,2)]
        self.assertEqual(
            body, ['body', 'body2'])  #the body should be ['body', 'body2']
        self.assertEqual(indexes_of_body,
                         [(1, 2), (1, 2)])  #the index of body should be empty
        self.assertEqual(
            index_of_excel_function,
            [(1, 2)])  #the index of excel function should be [(1,2)]
        self.assertEqual(excel_function,
                         [':= "{{body:body2}}" + "tung"'
                          ])  #the excel function list should be correct
        self.assertEqual(other_info,
                         ['tung'])  #other information should be correct
        self.assertEqual(
            index_of_other_info,
            [(1, 2)])  #index of other information should be correct
Beispiel #4
0
    def test_extract_information_function(self):
        index_of_function = []
        index_of_head = []
        body = []
        indexes_of_body = []
        index_of_excel_function = []
        excel_function = []
        other_info = []
        index_of_other_info = []

        #call function to test function_name extraction
        function_name, head = extract_information(index_of_function, index_of_head, body, indexes_of_body,
                        index_of_excel_function, excel_function, '#<function()>', 1, 2, other_info, index_of_other_info)
        self.assertEqual(function_name, 'function()') #test if the function_name is extracted correctly
        self.assertEqual(head, '') #test if the head is extracted correctly
        self.assertEqual(index_of_function, [(1,2)]) #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,[]) #the index of head should be empty
        self.assertEqual(body, []) #the body should be empty
        self.assertEqual(indexes_of_body, []) #the index of body should be empty
        self.assertEqual(index_of_excel_function, []) #the index of excel function should be empty
        self.assertEqual(excel_function, []) #the excel function list should be empty
        self.assertEqual(other_info, []) #other information should be empty
        self.assertEqual(index_of_other_info, []) #index of other information should be empty

        #test for head extraction
        function_name, head = extract_information(index_of_function, index_of_head, body, indexes_of_body,
                        index_of_excel_function, excel_function, '{{head:head}}', 1, 2, other_info, index_of_other_info)
        self.assertEqual(function_name, '') #test if the function_name is extracted correctly
        self.assertEqual(head, 'head') #test if the head is extracted correctly
        self.assertEqual(index_of_function, [(1,2)]) #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,[(1,2)]) #the index of head should be [(1,2)]
        self.assertEqual(body, []) #the body should be empty
        self.assertEqual(indexes_of_body, []) #the index of body should be empty
        self.assertEqual(index_of_excel_function, []) #the index of excel function should be empty
        self.assertEqual(excel_function, []) #the excel function list should be empty
        self.assertEqual(other_info, []) #other information should be empty
        self.assertEqual(index_of_other_info, []) #index of other information should be empty

        #test for body extraction
        function_name, head = extract_information(index_of_function, index_of_head, body, indexes_of_body,
                        index_of_excel_function, excel_function, '{{body:body}}', 1, 2, other_info, index_of_other_info)
        self.assertEqual(function_name, '') #test if the function_name is extracted correctly
        self.assertEqual(head, '') #test if the head is extracted correctly
        self.assertEqual(index_of_function, [(1,2)]) #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,[(1,2)]) #the index of head should be [(1,2)]
        self.assertEqual(body, ['body']) #the body should be ['body']
        self.assertEqual(indexes_of_body, [(1,2)]) #the index of body should be empty
        self.assertEqual(index_of_excel_function, []) #the index of excel function should be empty
        self.assertEqual(excel_function, []) #the excel function list should be empty
        self.assertEqual(other_info, []) #other information should be empty
        self.assertEqual(index_of_other_info, []) #index of other information should be empty

        #test for excel_function extraction
        function_name, head = extract_information(index_of_function, index_of_head, body, indexes_of_body,
                        index_of_excel_function, excel_function, ':= "{{body:body2}}" + "tung"', 1, 2, other_info, index_of_other_info)
        self.assertEqual(function_name, '') #test if the function_name is extracted correctly
        self.assertEqual(head, '') #test if the head is extracted correctly
        self.assertEqual(index_of_function, [(1,2)]) #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,[(1,2)]) #the index of head should be [(1,2)]
        self.assertEqual(body, ['body', 'body2']) #the body should be ['body', 'body2']
        self.assertEqual(indexes_of_body, [(1,2), (1,2)]) #the index of body should be empty
        self.assertEqual(index_of_excel_function, [(1,2)]) #the index of excel function should be [(1,2)]
        self.assertEqual(excel_function, [':= "{{body:body2}}" + "tung"']) #the excel function list should be correct
        self.assertEqual(other_info, []) #other information should be empty
        self.assertEqual(index_of_other_info, []) #index of other information should be empty

        #test for other information extraction:
        function_name, head = extract_information(index_of_function, index_of_head, body, indexes_of_body,
                        index_of_excel_function, excel_function, 'tung', 1, 2, other_info, index_of_other_info)
        self.assertEqual(function_name, '') #test if the function_name is extracted correctly
        self.assertEqual(head, '') #test if the head is extracted correctly
        self.assertEqual(index_of_function, [(1,2)]) #test if the the index of function_name is assigned correctly
        self.assertEqual(index_of_head,[(1,2)]) #the index of head should be [(1,2)]
        self.assertEqual(body, ['body', 'body2']) #the body should be ['body', 'body2']
        self.assertEqual(indexes_of_body, [(1,2), (1,2)]) #the index of body should be empty
        self.assertEqual(index_of_excel_function, [(1,2)]) #the index of excel function should be [(1,2)]
        self.assertEqual(excel_function, [':= "{{body:body2}}" + "tung"']) #the excel function list should be correct
        self.assertEqual(other_info, ['tung']) #other information should be correct
        self.assertEqual(index_of_other_info, [(1,2)]) #index of other information should be correct