From 90d9bbbc0fc4f91553bdc306b78ae2be8343492f Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Sat, 3 Mar 2018 08:27:02 -0500 Subject: [PATCH] better tests Signed-off-by: Kenneth Reitz --- requests_html.py | 5 +++-- tests/test_requests_html.py | 10 +++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/requests_html.py b/requests_html.py index 6b4ae4d..c451be8 100644 --- a/requests_html.py +++ b/requests_html.py @@ -302,8 +302,9 @@ class Element(BaseParser): attrs = {k: v for k, v in self.element.items()} # Split class up, as there are ussually many of them: - if 'class' in attrs: - attrs['class'] = tuple(attrs['class'].split()) + for attr in ['class']: + if attr in attrs: + attrs[attr] = tuple(attrs[attr].split()) return attrs diff --git a/tests/test_requests_html.py b/tests/test_requests_html.py index d0f34ee..1cfa72c 100644 --- a/tests/test_requests_html.py +++ b/tests/test_requests_html.py @@ -21,6 +21,14 @@ def test_file_get(): assert r.status_code == 200 +@pytest.mark.ok +def test_class_seperation(): + r = get() + + about = r.html.find('#about', first=True) + assert len(about.attrs['class']) == 2 + + @pytest.mark.ok def test_css_selector(): r = get() @@ -151,4 +159,4 @@ def test_bare_js_eval(): if __name__ == '__main__': - test_anchor_links() + test_class_seperation()