Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added map method and changed the name 'list' #81

Merged
merged 2 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)