Skip to content

Commit

Permalink
fixed gawel#23
Browse files Browse the repository at this point in the history
  • Loading branch information
gawel committed Dec 21, 2013
1 parent 064020f commit bbb0b77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
10 changes: 9 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
1.2.7 (unreleased)
------------------

- Nothing changed yet.
- Use pep8 name for methods but keep an alias for camel case method.
Eg: remove_attr and removeAttr works
Fix #57

- .text() now return an empty string instead of None if there is no text node.
Fix #45

- Fixed #23: removeClass adds class attribute to elements which previously
lacked one


1.2.6 (2013-10-11)
Expand Down
6 changes: 4 additions & 2 deletions pyquery/pyquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,9 @@ def remove_class(self, value):
classes = set((tag.get('class') or '').split())
classes.difference_update(values)
classes.difference_update([''])
tag.set('class', ' '.join(classes))
classes = ' '.join(classes)
if classes.strip():
tag.set('class', classes)
return self

@with_camel_case_alias
Expand Down Expand Up @@ -1057,7 +1059,7 @@ def text(self, value=no_default):

if value is no_default:
if not self:
return None
return ''

text = []

Expand Down
9 changes: 7 additions & 2 deletions tests/test_pyquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_pseudo_classes(self):
self.assertEqual(e('div:first').text(), 'node1')
self.assertEqual(e('div:last').text(), 'node3')
self.assertEqual(e('div:even').text(), 'node1 node3')
self.assertEqual(e('div div:even').text(), None)
self.assertEqual(e('div div:even').text(), '')
self.assertEqual(e('body div:even').text(), 'node1 node3')
self.assertEqual(e('div:gt(0)').text(), 'node2 node3')
self.assertEqual(e('div:lt(1)').text(), 'node1')
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_pseudo_classes(self):
def test_on_the_fly_dom_creation(self):
e = self.klass(self.html)
assert e('<p>Hello world</p>').text() == 'Hello world'
assert e('').text() is None
assert e('').text() == ''


class TestTraversal(TestCase):
Expand Down Expand Up @@ -366,6 +366,11 @@ def test_remove(self):
val = d('a:last').html()
assert val == ' My link text 2', repr(val)

def test_class(self):
d = pq('<div></div>')
d.removeClass('xx')
assert 'class' not in str(d), str(d)


class TestHTMLParser(TestCase):
xml = "<div>I'm valid XML</div>"
Expand Down

0 comments on commit bbb0b77

Please sign in to comment.