Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Switch to native asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
davehunt committed Oct 23, 2015
1 parent 4771c90 commit 71e2cd5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
UnittestZero
beautifulsoup4==4.4.1
pytest==2.3.5
requests==2.8.1
19 changes: 11 additions & 8 deletions tests/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from xml.dom.minidom import parseString
from xml.parsers.expat import ExpatError

from unittestzero import Assert
import pytest
from bs4 import BeautifulSoup
import requests
Expand Down Expand Up @@ -44,11 +43,14 @@ def assert_valid_url(self, url, path, user_agent=_user_agent_firefox, locale='en

# HEAD doesn't return page body.
try:
r = requests.get(url, headers=headers, timeout=REQUESTS_TIMEOUT, allow_redirects=True, verify=False)
return Assert.equal(r.status_code, requests.codes.ok,
'Bad URL %s found in %s' % (url, path))
r = requests.get(url, headers=headers, timeout=REQUESTS_TIMEOUT,
allow_redirects=True, verify=False)
except requests.exceptions.RequestException as e:
return Assert.fail('Error connecting to %s in %s: %s' % (url, path, e.message))
raise AssertionError('Error connecting to {0} in {1}: {2}'.format(
url, path, e))
assert requests.codes.ok == r.status_code, \
'Bad URL {0} found in {1}'.format(url, path)
return True

def _parse_response(self, content):
return BeautifulSoup(content)
Expand All @@ -58,12 +60,12 @@ def test_snippet_set_present(self, base_url, path):
full_url = base_url + path

r = self._get_redirect(full_url)
Assert.equal(r.status_code, requests.codes.ok, "URL %s failed with status code: %s" % (full_url, r.status_code))
assert requests.codes.ok == r.status_code, full_url

soup = self._parse_response(r.content)
snippet_set = soup.select("div.snippet_set")

Assert.greater(len(snippet_set), 0, "No snippet set found")
assert len(snippet_set) > 0, 'No snippet set found'

@pytest.mark.parametrize(('path'), test_data)
def test_all_links(self, base_url, path):
Expand All @@ -87,4 +89,5 @@ def test_that_snippets_are_well_formed_xml(self, base_url, path):
try:
parseString(r.content)
except ExpatError as e:
Assert.fail('Snippets at %s do not contain well formed xml. %s' % (full_url, e.message))
raise AssertionError('Snippets at {0} do not contain well formed '
'xml: {1}'.format(full_url, e))

0 comments on commit 71e2cd5

Please sign in to comment.