def test_traverse_yields_preorder():
    tree = [[1, 2], [3, 4], [5, [6]]]

    expected = [1, 2, 3, 4, 5, 6]
    result = list(traverse(tree))

    assert expected == result
def test_traverse_yields_preorder():
    tree = [[1, 2], [3, 4], [5, [6]]]

    expected = [1, 2, 3, 4, 5, 6]
    result = list(traverse(tree))

    assert expected == result
Beispiel #3
0
 def _get_address(self):
     """Return record address"""
     address = []
     if 'imprints' in self.record:
         for field in self.record['imprints']:
             if 'place' in field and field['place']:
                 address.append(field['place'])
         if address:
             if len(address) > 1:
                 return address[0]
             else:
                 if any(isinstance(i, list) for i in address):
                     nested_list = list(bibtex_booktitle.traverse(address))
                     return nested_list[0]
                 else:
                     return ''.join(result for result in address)
     else:
         return address
Beispiel #4
0
 def _get_address(self):
     """Return record address"""
     address = []
     if 'imprints' in self.record:
         for field in self.record['imprints']:
             if 'place' in field and field['place']:
                 address.append(field['place'])
         if address:
             if len(address) > 1:
                 return address[0]
             else:
                 if any(isinstance(i, list) for i in address):
                     nested_list = list(bibtex_booktitle.traverse(address))
                     return nested_list[0]
                 else:
                     return ''.join(result for result in address)
     else:
         return address
Beispiel #5
0
 def _get_isbn(self):
     """Return ISBN"""
     isbn_list = []
     result = []
     if 'isbns' in self.record:
         for isbn in self.record['isbns']:
             isbn_list.append(isbn['value'])
         if len(isbn_list) > 1:
             for element in isbn_list:
                 if isinstance(element, list):
                     result.append(element[0])
                 else:
                     result.append(element)
             return ', '.join(element for element in result)
         else:
             if any(isinstance(i, list) for i in isbn):
                 nested_list = list(bibtex_booktitle.traverse(isbn))
                 return nested_list[0]
             else:
                 return ''.join(result for result in isbn)
     else:
         return ''
Beispiel #6
0
 def _get_isbn(self):
     """Return ISBN"""
     isbn_list = []
     result = []
     if 'isbns' in self.record:
         for isbn in self.record['isbns']:
             isbn_list.append(isbn['value'])
         if len(isbn_list) > 1:
             for element in isbn_list:
                 if isinstance(element, list):
                     result.append(element[0])
                 else:
                     result.append(element)
             return ', '.join(element for element in result)
         else:
             if any(isinstance(i, list) for i in isbn):
                 nested_list = list(bibtex_booktitle.traverse(isbn))
                 return nested_list[0]
             else:
                 return ''.join(result for result in isbn)
     else:
         return ''