Skip to content

Commit

Permalink
Merge pull request #81 from Navneet78/func/map
Browse files Browse the repository at this point in the history
Added map method and changed the name 'list'
  • Loading branch information
Hrabal committed Oct 11, 2019
2 parents 723ae85 + 8a98648 commit 9a35928
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
13 changes: 9 additions & 4 deletions tempy/tempy.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,16 @@ def clone(self):
return copy(self)

@classmethod
def join(cls, list):
n = len(list)
def join(cls, list_ele):
n = len(list_ele)
for index in range(1, 2*n-2, 2):
list.insert(index, cls())
return list
list_ele.insert(index, cls())
return list_ele

@classmethod
def map(cls, list_ele):
mapped_list = [cls()(ele) for ele in list_ele]
return mapped_list


class Escaped(DOMElement):
Expand Down
15 changes: 11 additions & 4 deletions tests/test_DOMElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tempy.elements import Tag
from tempy.exceptions import WrongContentError, WrongArgsError, TagError, DOMModByKeyError, DOMModByIndexError
from tempy.tags import Div, A, P, Html, Head, Body, Pre, Br
from tempy.tags import Div, A, P, Html, Head, Body, Pre, Br, Td
from tempy.tempy import DOMElement, Escaped


Expand Down Expand Up @@ -578,7 +578,14 @@ def test_find(self):
self.assertEqual(len(result), 1)

def test_join(self):
tag= Div()
list=['foo', 'Br', 'Div', 'Pre']
result= tag.join(list)
tag = Div()
list_ele = ['foo', 'Br', 'Div', 'Pre']
result = tag.join(list_ele)
self.assertEqual(len(result), 7)

def test_map(self):
tag = Td()
list_ele = ['foo', 'Br', 'Div', 'Pre']
result = tag.map(list_ele)
self.assertEqual(len(result), 4)

0 comments on commit 9a35928

Please sign in to comment.