W3C home > Mailing lists > Public > www-validator-cvs@w3.org > November 2009

validator/misc/testsuite/lib TestCase.py,1.4,1.5 ValidatorsAPIs.py,1.3,1.4

From: Ville Skytta via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 16 Nov 2009 19:47:43 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1NA7Y7-00077W-HK@lionel-hutz.w3.org>
Update of /sources/public/validator/misc/testsuite/lib
In directory hutz:/tmp/cvs-serv27336/lib

Modified Files:
	TestCase.py ValidatorsAPIs.py 
Log Message:
Improve unsuccessful request handling.

Index: TestCase.py
===================================================================
RCS file: /sources/public/validator/misc/testsuite/lib/TestCase.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- TestCase.py	28 Jul 2008 19:38:26 -0000	1.4
+++ TestCase.py	16 Nov 2009 19:47:40 -0000	1.5
@@ -50,7 +50,9 @@
         We first remove irrelevant result keys in the validation results,
         and compare that to the expected results
         """
-        results = self.checker.parse_response(self.checker.call_check(self.docURI))
+        (res, err) = self.checker.call_check(self.docURI)
+        self.assertEqual(err, None)
+        results = self.checker.parse_response(res)
         results_filtered = dict()
         for result_key in self.expectResults.iterkeys():
             if results.has_key(result_key):
@@ -242,4 +244,4 @@
 
 
 if __name__ == '__main__':
-    unittest.main()
\ No newline at end of file
+    unittest.main()

Index: ValidatorsAPIs.py
===================================================================
RCS file: /sources/public/validator/misc/testsuite/lib/ValidatorsAPIs.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ValidatorsAPIs.py	16 Nov 2009 18:52:23 -0000	1.3
+++ ValidatorsAPIs.py	16 Nov 2009 19:47:41 -0000	1.4
@@ -31,9 +31,9 @@
         final_checker_URI = self.check_URI % {"URI": data }
         try:
             response = urllib2.urlopen(final_checker_URI)
-            return response
-        except (urllib2.HTTPError, urllib2.URLError):
-            return None
+        except (urllib2.HTTPError, urllib2.URLError) as exc:
+            return (None, str(exc) + ": " + final_checker_URI)
+        return (response, None)
 
     def parse_response(self, response):
         """Parse a W3C Markup Validator Response via its HTTP headers"""
@@ -61,34 +61,39 @@
     def test_contact_default(self):
         """Test Contacting the default validator instance"""
         default_checker = W3CValidatorHTTP()
-        checked = default_checker.call_check("http://www.w3.org")
-        self.assertNotEqual(checked, None)
+        (res, err) = default_checker.call_check("http://www.w3.org")
+        self.assertEqual(err, None)
+        self.assertNotEqual(res, None)
 
     def test_contact_vwo(self):
         """Test Contacting the main W3C validator instance"""
         default_checker = W3CValidatorHTTP("http://validator.w3.org/check?uri=%(URI)s")
-        checked = default_checker.call_check("http://www.w3.org")
-        self.assertNotEqual(checked, None)
+        (res, err) = default_checker.call_check("http://www.w3.org")
+        self.assertEqual(err, None)
+        self.assertNotEqual(res, None)
 
     def test_parse_response(self):
         """Test parsing response from default validator instance"""
         default_checker = W3CValidatorHTTP()
-        checked = default_checker.call_check("http://www.w3.org")
-        results = default_checker.parse_response(checked)
+        (res, err) = default_checker.call_check("http://www.w3.org")
+        self.assertEqual(err, None)
+        results = default_checker.parse_response(res)
         self.assert_(isinstance(results,dict))
 
     def test_parse_response_invalid(self):
         """Test parsing response for a known invalid resource"""
         default_checker = W3CValidatorHTTP()
-        checked = default_checker.call_check("http://qa-dev.w3.org/wmvs/HEAD/dev/tests/xhtml1-bogus-element.html")
-        results = default_checker.parse_response(checked)
+        (res, err) = default_checker.call_check("http://qa-dev.w3.org/wmvs/HEAD/dev/tests/xhtml1-bogus-element.html")
+        self.assertEqual(err, None)
+        results = default_checker.parse_response(res)
         self.assertNotEquals(results["NumErrors"], 0)
 
     def test_parse_response_valid(self):
         """Test parsing response for a known valid HTML resource"""
         default_checker = W3CValidatorHTTP()
-        checked = default_checker.call_check("http://qa-dev.w3.org/wmvs/HEAD/dev/tests/html20.html")
-        results = default_checker.parse_response(checked)
+        (res, err) = default_checker.call_check("http://qa-dev.w3.org/wmvs/HEAD/dev/tests/html20.html")
+        self.assertEqual(err, None)
+        results = default_checker.parse_response(res)
         self.assertNotEquals([results["NumErrors"], results["Validity"]], [0, "Valid"])
 
 if __name__ == '__main__':
Received on Monday, 16 November 2009 19:47:52 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:40 UTC