Skip to content

Commit

Permalink
Merge pull request robotframework#14 from emanlove/make-utests-python…
Browse files Browse the repository at this point in the history
…26-compatible

Make utests python26 compatible
  • Loading branch information
j1z0 committed Dec 12, 2011
2 parents 1af0ffe + 9dbfe01 commit 46a58da
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
19 changes: 10 additions & 9 deletions test/unit/locators/test_elementfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ 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()
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()
Expand Down
39 changes: 22 additions & 17 deletions test/unit/locators/test_windowmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ 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()
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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions test/unit/utils/test_browsercache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 46a58da

Please sign in to comment.