From 30128c8e00544eff5bf8c0074cf99f5593497c9b Mon Sep 17 00:00:00 2001 From: navneet78 Date: Tue, 8 Oct 2019 21:46:51 +0530 Subject: [PATCH 1/2] Added map method and changed the name 'list' --- tempy/tempy.py | 14 ++++++++++---- tests/test_DOMElement.py | 15 +++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tempy/tempy.py b/tempy/tempy.py index c487791..a552d91 100755 --- a/tempy/tempy.py +++ b/tempy/tempy.py @@ -703,11 +703,17 @@ 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): diff --git a/tests/test_DOMElement.py b/tests/test_DOMElement.py index e2730e6..48b93e4 100755 --- a/tests/test_DOMElement.py +++ b/tests/test_DOMElement.py @@ -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 @@ -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) + From 8a986483daf5147ac639cc8ca0b26bcac426a54b Mon Sep 17 00:00:00 2001 From: navneet78 Date: Tue, 8 Oct 2019 21:57:12 +0530 Subject: [PATCH 2/2] improved coding style --- tempy/tempy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tempy/tempy.py b/tempy/tempy.py index a552d91..a61891e 100755 --- a/tempy/tempy.py +++ b/tempy/tempy.py @@ -715,7 +715,6 @@ def map(cls, list_ele): return mapped_list - class Escaped(DOMElement): def __init__(self, content, **kwargs): super().__init__(**kwargs)