Best Python code snippet using yandex-tank
parse.py
Source:parse.py  
...184    EXPECTED_LIST_FORMAT = lists.Format(lists.ListType.ITEMIZED_LIST,185                                        custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,186                                        custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)187    def test_single_list_with_single_item_as_last_line(self):188        expected = [lists.HeaderContentList([_list_item('item')],189                                            self.EXPECTED_LIST_FORMAT)]190        actual = sut.parse(['  * item'])191        check(self, expected, actual)192    def test_single_list_with_single_item_followed_by_empty_line(self):193        expected = [lists.HeaderContentList([_list_item('item')],194                                            self.EXPECTED_LIST_FORMAT)]195        actual = sut.parse(['  * item',196                            ''])197        check(self, expected, actual)198    def test_single_list_with_single_item_with_contents_on_next_line(self):199        expected = [lists.HeaderContentList([200            _list_item('item',201                       [202                           Paragraph([StringText('contents')]),203                       ])],204            self.EXPECTED_LIST_FORMAT)]205        actual = sut.parse(['  * item',206                            '    contents',207                            ])208        check(self, expected, actual)209    def test_single_list_with_single_item_with_contents_on_line_after_separator(self):210        expected = [lists.HeaderContentList([211            _list_item('item',212                       [213                           Paragraph([StringText('contents')]),214                       ])],215            self.EXPECTED_LIST_FORMAT)]216        actual = sut.parse(['  * item',217                            '    contents',218                            ])219        check(self, expected, actual)220    def test_single_list_with_with_contents(self):221        expected = [lists.HeaderContentList([222            _list_item('item 1',223                       [224                           Paragraph([StringText('contents 1')]),225                       ]),226            _list_item('item 2',227                       [228                           Paragraph([StringText('contents 2')]),229                       ]),230        ],231            self.EXPECTED_LIST_FORMAT)]232        actual = sut.parse(['  * item 1',233                            '    contents 1',234                            '  * item 2',235                            '    contents 2',236                            ])237        check(self, expected, actual)238    def test_single_list_with_multiple_items(self):239        expected = [lists.HeaderContentList([_list_item('item 1'),240                                             _list_item('item 2')],241                                            self.EXPECTED_LIST_FORMAT)]242        actual = sut.parse(['  * item 1',243                            '  * item 2'])244        check(self, expected, actual)245    def test_single_list_with_multiple_items_with_other_indentation_level(self):246        expected = [lists.HeaderContentList([_list_item('item 1'),247                                             _list_item('item 2')],248                                            self.EXPECTED_LIST_FORMAT)]249        actual = sut.parse(['    * item 1',250                            '    * item 2'])251        check(self, expected, actual)252    def test_single_list_with_multiple_items_separated_by_empty_line(self):253        expected = [lists.HeaderContentList([_list_item('item 1'),254                                             _list_item('item 2')],255                                            self.EXPECTED_LIST_FORMAT)]256        actual = sut.parse(['  * item 1',257                            '',258                            '  * item 2'])259        check(self, expected, actual)260    def test_spaces_around_header_string_SHOULD_not_appear_in_header(self):261        expected = [lists.HeaderContentList([_list_item('item 1'),262                                             _list_item('item 2')],263                                            self.EXPECTED_LIST_FORMAT)]264        actual = sut.parse(['  *   item 1',265                            '  *  item 2   '])266        check(self, expected, actual)267    def test_single_list_with_multiple_items_with_initial_blank_lines(self):268        expected = [lists.HeaderContentList([_list_item('item 1'),269                                             _list_item('item 2')],270                                            self.EXPECTED_LIST_FORMAT)]271        actual = sut.parse(['',272                            '  * item 1',273                            '  * item 2'])274        check(self, expected, actual)275    def test_single_list_with_multiple_items_with_trailing_blank_lines(self):276        expected = [lists.HeaderContentList([_list_item('item 1'),277                                             _list_item('item 2')],278                                            self.EXPECTED_LIST_FORMAT)]279        actual = sut.parse(['  * item 1',280                            '  * item 2',281                            ''])282        check(self, expected, actual)283    def test_list_in_middle_of_paragraphs(self):284        expected = [285            Paragraph([StringText('first paragraph')]),286            lists.HeaderContentList([_list_item('item 1'),287                                     _list_item('item 2')],288                                    self.EXPECTED_LIST_FORMAT),289            Paragraph([StringText('last paragraph')]),290        ]291        actual = sut.parse(['first paragraph',292                            '',293                            '',294                            '  * item 1',295                            '  * item 2',296                            '',297                            '',298                            'last paragraph'])299        check(self, expected, actual)300    def test_list_with_item_contents_in_middle_of_paragraphs(self):301        expected = [302            Paragraph([StringText('first paragraph')]),303            lists.HeaderContentList([304                _list_item('item 1',305                           [306                               Paragraph([StringText('item contents paragraph')]),307                           ]),308            ],309                self.EXPECTED_LIST_FORMAT),310            Paragraph([StringText('last paragraph')]),311        ]312        actual = sut.parse(['first paragraph',313                            '',314                            '',315                            '  * item 1',316                            '',317                            '    item contents paragraph',318                            '',319                            '',320                            'last paragraph'])321        check(self, expected, actual)322    def test_list_with_item_multiple_paragraphs_contents_in_middle_of_paragraphs(self):323        expected = [324            Paragraph([StringText('first paragraph')]),325            lists.HeaderContentList([326                _list_item('item 1',327                           [328                               Paragraph([StringText('line 1 in contents paragraph 1'),329                                          StringText('line 2 in contents paragraph 1')]),330                               Paragraph([StringText('line 1 in contents paragraph 2')]),331                           ]),332            ],333                self.EXPECTED_LIST_FORMAT),334            Paragraph([StringText('last paragraph')]),335        ]336        actual = sut.parse(['first paragraph',337                            '',338                            '',339                            '  * item 1',340                            '',341                            '    line 1 in contents paragraph 1',342                            '',343                            '    line 2 in contents paragraph 1',344                            '',345                            '',346                            '    line 1 in contents paragraph 2',347                            '',348                            '',349                            'last paragraph'])350        check(self, expected, actual)351    def test_list_with_item_multiple_paragraphs_contents_before_other_item(self):352        expected = [353            lists.HeaderContentList([354                _list_item('item 1',355                           [356                               Paragraph([StringText('item 1 contents paragraph 1')]),357                               Paragraph([StringText('item 1 contents paragraph 2')]),358                           ]),359                _list_item('item 2',360                           [361                               Paragraph([StringText('item 2 contents paragraph 1')]),362                           ]),363            ],364                self.EXPECTED_LIST_FORMAT),365            Paragraph([StringText('last paragraph')]),366        ]367        actual = sut.parse(['  * item 1',368                            '',369                            '    item 1 contents paragraph 1',370                            '',371                            '',372                            '    item 1 contents paragraph 2',373                            '',374                            '  * item 2',375                            '',376                            '    item 2 contents paragraph 1',377                            '',378                            'last paragraph'])379        check(self, expected, actual)380    def test_nested_lists(self):381        expected = [382            lists.HeaderContentList([383                _list_item('item 1',384                           [385                               Paragraph([StringText('item 1 contents paragraph')]),386                               lists.HeaderContentList(387                                   [388                                       _list_item('item 1/1',389                                                  [390                                                      Paragraph([StringText('item 1/1 contents paragraph')]),391                                                  ]),392                                       _list_item('item 1/2',393                                                  []),394                                   ],395                                   self.EXPECTED_LIST_FORMAT),396                           ]),397                _list_item('item 2',398                           []),399            ],400                self.EXPECTED_LIST_FORMAT),401        ]402        actual = sut.parse(['  * item 1',403                            '',404                            '    item 1 contents paragraph',405                            '',406                            '',407                            '      * item 1/1',408                            '',409                            '        item 1/1 contents paragraph',410                            '',411                            '      * item 1/2',412                            '',413                            '  * item 2',414                            ])415        check(self, expected, actual)416class TestOrderedList(unittest.TestCase):417    EXPECTED_LIST_FORMAT = lists.Format(lists.ListType.ORDERED_LIST,418                                        custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,419                                        custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)420    def test_single_list_with_single_item_as_last_line(self):421        expected = [lists.HeaderContentList([_list_item('item')],422                                            self.EXPECTED_LIST_FORMAT)]423        actual = sut.parse(['  1. item'])424        check(self, expected, actual)425    def test_single_list_with_single_item_with_contents_on_next_line(self):426        expected = [lists.HeaderContentList([427            _list_item('item',428                       [429                           Paragraph([StringText('contents')]),430                       ])],431            self.EXPECTED_LIST_FORMAT)]432        actual = sut.parse(['  1. item',433                            '     contents',434                            ])435        check(self, expected, actual)436class TestOrderedAndItemizedLists(unittest.TestCase):437    EXPECTED_ORDERED_LIST_FORMAT = lists.Format(lists.ListType.ORDERED_LIST,438                                                custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,439                                                custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)440    EXPECTED_ITEMIZED_LIST_FORMAT = lists.Format(lists.ListType.ITEMIZED_LIST,441                                                 custom_indent_spaces=sut.DEFAULT_LIST_SETTINGS.custom_indent_spaces,442                                                 custom_separations=sut.DEFAULT_LIST_SETTINGS.custom_separations)443    def test_nested_lists(self):444        expected = [445            lists.HeaderContentList([446                _list_item('itemized item 1',447                           [448                               Paragraph([StringText('item 1 contents paragraph')]),449                               lists.HeaderContentList(450                                   [451                                       _list_item('ordered item 1/1',452                                                  [453                                                      Paragraph([StringText('item 1/1 contents paragraph')]),454                                                  ]),455                                       _list_item('ordered item 1/2',456                                                  []),457                                   ],458                                   self.EXPECTED_ORDERED_LIST_FORMAT),459                           ]),460                _list_item('itemized item 2',461                           []),462            ],463                self.EXPECTED_ITEMIZED_LIST_FORMAT),464        ]465        actual = sut.parse(['  * itemized item 1',466                            '',467                            '    item 1 contents paragraph',468                            '',469                            '',470                            '      1. ordered item 1/1',471                            '',472                            '         item 1/1 contents paragraph',473                            '',474                            '      1. ordered item 1/2',475                            '',476                            '  * itemized item 2',477                            ])478        check(self, expected, actual)479class TestNormalizeAndParse(unittest.TestCase):480    def test_misc(self):481        lines = ['',482                 '   ',483                 'para 1 text 1',484                 '  ',485                 '',486                 '   ',487                 '  para 2 text 1',488                 '  ',489                 'para 2 text 2  ',490                 '  ',491                 '\tpara 2 text 3  ',492                 '',493                 '   ']494        indented_lines = ['  ' + line for line in lines]495        actual = sut.normalize_and_parse(lines_content(indented_lines))496        check(self,497              [Paragraph([StringText('para 1 text 1')]),498               Paragraph([StringText('para 2 text 1'),499                          StringText('para 2 text 2'),500                          StringText('para 2 text 3')])],501              actual)502_text = StringText503def _single_string_para(text: str) -> Paragraph:504    return Paragraph([StringText(text)])505def _list_item(header: str,506               content_paragraphs=()) -> lists.HeaderContentListItem:507    return lists.HeaderContentListItem(_text(header),508                                       list(content_paragraphs))509def check(put: unittest.TestCase,510          expected_items: list,511          actual_items: list):512    equals_paragraph_items(expected_items).apply_with_message(put, actual_items,513                                                              'paragraph-items')514if __name__ == '__main__':...record_dict.py
Source:record_dict.py  
1"""2record_dict.py3A class of dict called record_dict, a subclass of dict.4Allows the getting and putting of data in nested dicts via delimited key strings, such as5    record_dict().get("key1>>>key2>>>key3")6refers to7{8    "key1":{9        "key2":{10            "key3": _obj11        }12    }13}14"""15from typing import Any, Union16class RecordNodeNotFound(ValueError):17    def __bool__(self):18        return False19    __nonzero__ = __bool__20class record_dict(dict):21    def get(22        self,23        key:Union[str, list],24        default:Any=RecordNodeNotFound("Requested node does not exist."), # Using this instead of None allows default to be actually None25        delimiter:str=">>>",        # This a string literal because 26        iterate_lists:bool=True,27        flatten_lists:bool=True,28        **kwargs29    )->Any:30        """31        Like dict.get(), try to fetch a value via a key - but it can search nested dicts inside itself.32        The exact nesting is specified through delimited string - Default delimiter is ">>>", i.e.33            record_dict().get("key1>>>key2>>>key3")34        refers to35        {36            "key1":{37                "key2":{38                    "key3": _obj39                }40            }41        }42        If it fails, default is returned instead.43        In addition, iterate_lists allows the searching of keys inside records, i.e. List[Dict].44        If True, it will continue to search inside any lists it encounters, and look for dicts with the specified subkey instead.45        It will return the values in form of a list at that level.46        """47        if (isinstance(key, str)):48            key = key.split(delimiter)49        _first_key = key.pop(0)50        if (_first_key in self.keys()):51            _first_value = self[_first_key]52            if (len(key) <= 0):53                return _first_value54            else:55                if (isinstance(_first_value, dict)):56                    # Convert dict to record_dict before using the custom .get()57                    return type(self)(_first_value).get(58                        key,59                        default=default,60                        delimiter=delimiter,61                        **kwargs)62                elif (isinstance(_first_value, list)):63                    if (iterate_lists):64                        # If we are iterating lists, then we extract the list and flatten it.65                        _listed_values = [66                            (type(self)(_list_item).get(67                                key.copy(),68                                default=default,69                                delimiter=delimiter,70                                iterate_lists=iterate_lists,71                                flatten_lists=flatten_lists,72                                **kwargs) if (isinstance(_list_item, dict)) else _list_item) \73                                    for _list_item in _first_value74                        ]75                        _flattened_list = []76                        for _list_item in _listed_values:77                            if (isinstance(_list_item, list) and \78                                not isinstance(_list_item, str)):79                                _flattened_list += _list_item80                            else:81                                _flattened_list.append(_list_item)82                        return _flattened_list83                    else:84                        # If we are not iterating lists and we have not exhausted key85                        # Then key is deemed not found, 86                        # Return default.87                        return default88                else:89                    # If we haven't exhausted key and we already found a non-dict non-list object,90                    # then key is not found.91                    # Return default.92                    return default93                    94        else:95            return default96    def put(97        self,98        key:Union[str, list],99        value:Any,100        delimiter:str=">>>",101        iterate_lists:bool=True,102        replace_list_items:bool=True,103        **kwargs,104    )->None:105        """106        Opposite of get(), try to store a value via a key - but it can search nested dicts inside itself.107        The exact nesting is specified through delimited string - Default delimiter is ">>>", i.e.108            record_dict().put("key1>>>key2>>>key3")109        refers to110        {111            "key1":{112                "key2":{113                    "key3": _obj114                }115            }116        }117        If the key does not exists, it is created instead.118        In addition, iterate_lists allows the expansion of lists into records, i.e. List[Dict].119        If True, it will expect a list as value, and iterate through the items to put each one into one record under the specified subkey.120        """121        # Create node if it doesn't exist122        def create_node(123            self,124            first_key:str,125            remaining_keys:list,126            value:Any,127            delimiter:str=">>>",128            iterate_lists:bool=True,129            **kwargs,130            ):131            """132            The node must NOT exist; its much safer to use .put() in every single case.133            Hence this is an internal function of .put().134            """135            if (len(remaining_keys)>0):136                self[first_key] = type(self)()137                self[first_key].put(138                        remaining_keys,139                        value,140                        delimiter=delimiter,141                        iterate_lists=iterate_lists,142                    )143            else:144                self[first_key] = (value.pop(0) if iterate_lists else value)145            return None146        147        if (isinstance(key, str)):148            key = key.split(delimiter)149        if (not isinstance(value, list) or \150            isinstance(value, str)):151            value = [value,]152        """153        This has a slight problem of actually wanting to put([]) into the values;154        but if that is the case, iterate_lists simply doesn't make sense, so we just return None and finish the iteration.155        """156        if (len(value) <= 0 and iterate_lists):157            return None158        _first_key = key.pop(0)159        if (_first_key in self.keys()):160            _first_value = self[_first_key]161            if (len(key) <= 0):162                if (isinstance(_first_value, list) and \163                    not isinstance(_first_value, str)):164                    _element_count = len(self[_first_key])165                    self[_first_key] = value[:_element_count] if iterate_lists else value166                    for _ in range(_element_count):167                        # We cannot use168                        #   value = value[_element_count:]169                        # because we have to keep the same mutable object170                        value.pop(0)171                else:172                    self[_first_key] = value.pop(0) if iterate_lists else value173                return None174            else:175                if (isinstance(_first_value, dict)):176                    # Convert dict to record_dict before using the custom .get()177                    self[_first_key] = type(self)(_first_value)178                    return self[_first_key].put(179                        key,180                        value,181                        delimiter=delimiter,182                        iterate_lists=iterate_lists,183                        **kwargs)184                elif (isinstance(_first_value, list) and \185                    not isinstance(_first_value, str)186                    ):187                    if (iterate_lists):188                        # If we are iterating lists, then we extract the list and flatten it.189                        for _item_id, _list_item in enumerate(_first_value):190                            if (isinstance(_list_item, dict)):191                                self[_first_key][_item_id] = type(self)(self[_first_key][_item_id])192                            else:193                                # The original list item is not a dict, but our key isn't exhausted.194                                # We have to wipe the original value for a new dict.195                                if (replace_list_items):196                                    self[_first_key][_item_id] = type(self)()197                                else:198                                    # If we are not replacing these list items,199                                    # leave the list items as is.200                                    continue201                            self[_first_key][_item_id].put(202                                key.copy(),203                                value, # We don't need to pop this, value is mutable and thus "passed by reference"204                                delimiter=delimiter,205                                iterate_lists=iterate_lists,206                                **kwargs)207                    else:208                        self[_first_key] = value209                else:210                    self[_first_key] = type(self)()211                    return create_node(212                        self[_first_key],213                        key.pop(0),214                        key,215                        value,216                        delimiter=delimiter,217                        iterate_lists=iterate_lists,218                        **kwargs,219                        )220        else:221            return create_node(222                        self,223                        _first_key,224                        key,225                        value,226                        delimiter=delimiter,227                        iterate_lists=iterate_lists,228                        **kwargs,229                        )230# if __name__=="__main__":231# _dict = {232#     "a":{233#         "b":{234#             "c":{235#                 "d":"Something",236#             }237#         }238#     },239#     "123":True,240#     "456":[241#         {242#             "abc":[243#                 "def",244#                 "def2",245#                 "def3",246#             ]247#         },248#         {249#             "abc":"ghi",250#         },251#         "a string",252#     ]253# }254#     _dict = record_dict(_dict)255#     print (_dict.get("123", delimiter=">>>"))256#     print (_dict.put(257#         "456>>>abc", [0,9,8,7,6,5,4,3,2], delimiter=">>>", replace_list_items=True258#     ))...build_list_type.py
Source:build_list_type.py  
1import StringIO2basic_types = [3("string256","character(256)"),4("string128","character(128)"),5("string80","character(80)"),6("string64","character(64)"),7("string32","character(32)"),8("string16","character(16)"),9("string8","character(8)"),10("real","real(4)"),11("double","real(8)"),12("int", "integer(4)"),13("long", "integer(8)"),14#Stupid fortran standard says you can't compare logicals with .eq.  gfortran follows this rule unless you use -fugly-logint15#Because that feature really held back C, didn't it?  There is even a snarky page on the gnu website explaining how it is really for the best.16#("logical", "logical"), 17]18def generate_list_functions(name,declaration):19	header =  """20type fl_{name}_list_item21	{declaration}, pointer :: value22	type(fl_{name}_list_item), pointer :: next23end type fl_{name}_list_item24type fl_{name}_list25	type(fl_{name}_list_item), pointer :: first, last, iter26	integer length27end type fl_{name}_list28""".format(name=name, declaration=declaration)29	body = """30subroutine fl_create_{name}_list(list)31	type(fl_{name}_list) :: list32	list%length=033	nullify(list%first)34	nullify(list%last)35	nullify(list%iter)36end subroutine fl_create_{name}_list37subroutine fl_append_{name}_list(list,value)38	type(fl_{name}_list) :: list39	{declaration} :: value40	41	type(fl_{name}_list_item), pointer :: item42	allocate(item)43	allocate(item%value)44	item%value=value45	nullify(item%next)46	if (.not. associated(list%first)) then47		list%first => item48		list%last => item49		list%length=150	else51		list%last%next => item52		list%last => item53		list%length=list%length+154	endif55	call fl_reset_{name}_iterator_list(list)56end subroutine fl_append_{name}_list57subroutine fl_destroy_{name}_list(list)58	type(fl_{name}_list) :: list59	type(fl_{name}_list_item), pointer :: item, next60	if (.not. associated(list%first)) return61	item=>list%first62	do63		nullify(next)64		if (associated(item%next)) next=>item%next65		deallocate(item%value)66		deallocate(item)67		if (.not. associated(next)) exit68		item=>next69	enddo70	nullify(list%first)71	nullify(list%last)72	nullify(list%iter)73	list%length=074end subroutine fl_destroy_{name}_list75function fl_{name}_list_to_array(list) result(arr)76	type(fl_{name}_list) :: list77	{declaration}, pointer, dimension(:) :: arr78	type(fl_{name}_list_item), pointer :: item79	integer i80	allocate(arr(list%length))81	item=>list%first82	if (list%length>0) then83		do i=1,list%length84			arr(i) = item%value85			if (associated(item%next)) item=>item%next86		enddo87	endif88end function fl_{name}_list_to_array89function fl_member_{name}_list(list,value) result(B)90	logical :: B91	type(fl_{name}_list) :: list92	type(fl_{name}_list_item), pointer :: item93	{declaration} :: value94	B=.false.95	if (associated(list%first)) then96		item => list%first97		do98			if (item%value == value) then99				B=.true.100				exit101			endif102			if (.not. associated(item%next)) exit103			item=>item%next104		enddo105	endif106end function fl_member_{name}_list107function fl_pop_last_{name}_list(list) result(pop)108	type(fl_{name}_list) :: list109	type(fl_{name}_list_item), pointer :: item	110	{declaration} :: pop111	integer i112	if (list%length==0) stop 'Requested last item from empty fl_{name}_list'113	114	pop=list%last%value115	deallocate(list%last%value)116	deallocate(list%last)117	list%length=list%length-1118	if (list%length==0) then119		nullify(list%first)120		nullify(list%last)121	elseif (list%length==1) then122		list%last=>list%first123	else124		item=>list%first125		do i=1,list%length-1126			item=>item%next127		enddo128		nullify(item%next)129	endif130	call fl_reset_{name}_iterator_list(list)	131end function fl_pop_last_{name}_list132function fl_pop_first_{name}_list(list) result(pop)133	type(fl_{name}_list) :: list134	type(fl_{name}_list_item), pointer :: item	135	{declaration} :: pop136	if (list%length==0) stop 'Requested first item from empty fl_{name}_list'137	item => list%first138	nullify(list%first)139	if (associated(item%next)) list%first=>item%next140	pop=item%value141	deallocate(item%value)142	deallocate(item)143	list%length=list%length-1144	call fl_reset_{name}_iterator_list(list)	145end function fl_pop_first_{name}_list146function fl_get_{name}_list(list,n) result(x)147	type(fl_{name}_list) :: list148	integer n,i149	type(fl_{name}_list_item), pointer :: item	150	{declaration} :: x151	if (n>list%length .or. n<1) stop 'Requested out-of-range fl_{name}_list item'152	item=>list%first153	do i=1,n-1154		item=>item%next155	enddo156	x = item%value157end function fl_get_{name}_list158function fl_iterate_{name}_list(list) result(x)159	type(fl_{name}_list) :: list160	{declaration} :: x161	if (list%length==0) stop 'Tried to iterate through empty fl_{name}_list'162	if (.not. associated(list%iter)) list%iter => list%first163	x=list%iter%value164	if (.not. associated(list%iter%next)) then165		nullify(list%iter)166	else167		list%iter => list%iter%next168	endif169end function fl_iterate_{name}_list170subroutine fl_insert_{name}_list(list,value,after)171	type(fl_{name}_list) :: list172	{declaration} :: value173	type(fl_{name}_list_item), pointer :: item, previous,next174	integer i175	integer after176	if (after>list%length .or. after<1) stop 'Tried to insert item in invalid position in fl_{name}_list'177	item=>list%first178	if (after==list%length) then179		item=>list%last180	else181		do i=1,after-1182			item=>item%next183		enddo184	endif185	previous=>item186	nullify(next)187	if (associated(item%next)) next=>item%next188	nullify(item)189	allocate(item)190	allocate(item%value)191	item%value=value192	previous%next=>item193	nullify(item%next)194	if (associated(item%next)) item%next=>next195	list%length = list%length + 1196	call fl_reset_{name}_iterator_list(list)	197end subroutine fl_insert_{name}_list198subroutine fl_reset_{name}_iterator_list(list)199	type(fl_{name}_list) :: list200	nullify(list%iter)201end subroutine fl_reset_{name}_iterator_list202""".format(name=name, declaration=declaration)203	return header,body204	205def generate_modules(types,module_name="fl_lists",uses=None):206	output=StringIO.StringIO()207	headers = []208	bodies = []209	for name,decl in types:210		header,body = generate_list_functions(name,decl)211		headers.append(header)212		bodies.append(body)213	output.write("module {0}\n".format(module_name))214	if uses:215		for use in uses:216			output.write("use {0}\n".format(use))217	output.write("implicit none\n")218	for header in headers:219		output.write("{0}\n".format(header))220	output.write("contains\n")221	for body in bodies:222		output.write("{0}\n".format(body))223	output.write("end module {0}\n".format(module_name))224	output.seek(0)225	return output.read()226		227	228if __name__=="__main__":229	print "!This module was auto-generated from build_list_module.py."230	print "!Edits to it will be lost."231	print...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
