From 6b4e383afd3f1a7f72899ed568a04aa60e5282e8 Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Mon, 5 Dec 2011 13:53:35 -0500 Subject: [PATCH 1/2] Refactored some unit tests to make compatible with both Python 2.6 and 2.7. --- test/unit/locators/test_elementfinder.py | 12 ++++++------ test/unit/locators/test_windowmanager.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unit/locators/test_elementfinder.py b/test/unit/locators/test_elementfinder.py index 8f4df6ece..e3495159d 100644 --- a/test/unit/locators/test_elementfinder.py +++ b/test/unit/locators/test_elementfinder.py @@ -14,20 +14,20 @@ def test_find_with_invalid_prefix(self): def test_find_with_null_browser(self): finder = ElementFinder() - with self.assertRaises(AssertionError): - finder.find(None, "id=test1") + self.assertRaises(AssertionError, + finder.find, None, "id=test1") def test_find_with_null_locator(self): finder = ElementFinder() browser = mock() - with self.assertRaises(AssertionError): - finder.find(browser, None) + self.assertRaises(AssertionError, + finder.find, browser, None) def test_find_with_empty_locator(self): finder = ElementFinder() browser = mock() - with self.assertRaises(AssertionError): - finder.find(browser, "") + self.assertRaises(AssertionError, + finder.find, browser, "") def test_find_with_no_tag(self): finder = ElementFinder() diff --git a/test/unit/locators/test_windowmanager.py b/test/unit/locators/test_windowmanager.py index af639cc8b..05f191674 100644 --- a/test/unit/locators/test_windowmanager.py +++ b/test/unit/locators/test_windowmanager.py @@ -16,8 +16,8 @@ def test_select_with_invalid_prefix(self): def test_select_with_null_browser(self): manager = WindowManager() - with self.assertRaises(AssertionError): - manager.select(None, "name=test1") + self.assertRaises(AssertionError, + manager.select, None, "name=test1") def test_select_by_title(self): manager = WindowManager() From 9dbfe01ef9be0055c2692fdb2a48b2b5cd847cad Mon Sep 17 00:00:00 2001 From: Ed Manlove Date: Mon, 5 Dec 2011 14:16:28 -0500 Subject: [PATCH 2/2] Refactored remaining unit tests to make compatible with both Python 2.6 and 2.7. --- test/unit/locators/test_elementfinder.py | 7 +++-- test/unit/locators/test_windowmanager.py | 35 ++++++++++++++---------- test/unit/utils/test_browsercache.py | 7 +++-- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/test/unit/locators/test_elementfinder.py b/test/unit/locators/test_elementfinder.py index e3495159d..e3cc2fbe9 100644 --- a/test/unit/locators/test_elementfinder.py +++ b/test/unit/locators/test_elementfinder.py @@ -8,9 +8,10 @@ class ElementFinderTests(unittest.TestCase): def test_find_with_invalid_prefix(self): finder = ElementFinder() browser = mock() - with self.assertRaises(ValueError) as context: - finder.find(browser, "something=test1") - self.assertEqual(context.exception.message, "Element locator with prefix 'something' is not supported") + try: + self.assertRaises(ValueError, finder.find, browser, "something=test1") + except ValueError as e: + self.assertEqual(e.message, "Element locator with prefix 'something' is not supported") def test_find_with_null_browser(self): finder = ElementFinder() diff --git a/test/unit/locators/test_windowmanager.py b/test/unit/locators/test_windowmanager.py index 05f191674..7858343a2 100644 --- a/test/unit/locators/test_windowmanager.py +++ b/test/unit/locators/test_windowmanager.py @@ -10,9 +10,10 @@ class WindowManagerTests(unittest.TestCase): def test_select_with_invalid_prefix(self): manager = WindowManager() browser = mock() - with self.assertRaises(ValueError) as context: - manager.select(browser, "something=test1") - self.assertEqual(context.exception.message, "Window locator with prefix 'something' is not supported") + try: + self.assertRaises(ValueError, manager.select, browser, "something=test1") + except ValueError as e: + self.assertEqual(e.message, "Window locator with prefix 'something' is not supported") def test_select_with_null_browser(self): manager = WindowManager() @@ -56,9 +57,10 @@ def test_select_by_title_no_match(self): { 'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html' }, { 'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html' }) - with self.assertRaises(ValueError) as context: - manager.select(browser, "title=Title -1") - self.assertEqual(context.exception.message, "Unable to locate window with title 'Title -1'") + try: + self.assertRaises(ValueError, manager.select, browser, "title=Title -1") + except ValueError as e: + self.assertEqual(e.message, "Unable to locate window with title 'Title -1'") def test_select_by_name(self): manager = WindowManager() @@ -97,9 +99,10 @@ def test_select_by_name_no_match(self): { 'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html' }, { 'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html' }) - with self.assertRaises(ValueError) as context: - manager.select(browser, "name=win-1") - self.assertEqual(context.exception.message, "Unable to locate window with name 'win-1'") + try: + self.assertRaises(ValueError, manager.select, browser, "name=win-1") + except ValueError as e: + self.assertEqual(e.message, "Unable to locate window with name 'win-1'") def test_select_by_url(self): manager = WindowManager() @@ -138,9 +141,10 @@ def test_select_by_url_no_match(self): { 'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html' }, { 'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html' }) - with self.assertRaises(ValueError) as context: - manager.select(browser, "url=http://localhost/page-1.html") - self.assertEqual(context.exception.message, "Unable to locate window with URL 'http://localhost/page-1.html'") + try: + self.assertRaises(ValueError, manager.select, browser, "url=http://localhost/page-1.html") + except ValueError as e: + self.assertEqual(e.message, "Unable to locate window with URL 'http://localhost/page-1.html'") def test_select_with_null_locator(self): manager = WindowManager() @@ -217,9 +221,10 @@ def test_select_by_default_no_match(self): { 'name': 'win2', 'title': "Title 2", 'url': 'http://localhost/page2.html' }, { 'name': 'win3', 'title': "Title 3", 'url': 'http://localhost/page3.html' }) - with self.assertRaises(ValueError) as context: - manager.select(browser, "win-1") - self.assertEqual(context.exception.message, "Unable to locate window with name or title 'win-1'") + try: + self.assertRaises(ValueError, manager.select, browser, "win-1") + except ValueError as e: + self.assertEqual(context.exception.message, "Unable to locate window with name or title 'win-1'") def test_select_with_sloppy_prefix(self): manager = WindowManager() diff --git a/test/unit/utils/test_browsercache.py b/test/unit/utils/test_browsercache.py index 12ebc50f1..50abcbd7b 100644 --- a/test/unit/utils/test_browsercache.py +++ b/test/unit/utils/test_browsercache.py @@ -7,9 +7,10 @@ class BrowserCacheTests(unittest.TestCase): def test_no_current_message(self): cache = BrowserCache() - with self.assertRaises(RuntimeError) as context: - cache.current.anyMember() - self.assertEqual(context.exception.message, "No current browser") + try: + self.assertRaises(RuntimeError, cache.current.anyMember()) + except RuntimeError as e: + self.assertEqual(e.message, "No current browser") def test_browsers_property(self): cache = BrowserCache()