Skip to content

Commit

Permalink
issue #6.
Browse files Browse the repository at this point in the history
raise SyntaxError when constructing one of the deprecated classes
  • Loading branch information
alisaifee committed Nov 27, 2013
1 parent 1ac0705 commit 25b519c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
7 changes: 1 addition & 6 deletions doc/source/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ Page Objects & Friends
Deprecated Classes
==================
Earlier versions of :mod:`holmium.core` used rather verbose names for Page objects and elements.
As of version 0.2 the classes have been renamed but the older names have been retained as aliases
to the new classes for backward compatibility (an annoying warning will however, be emitted everytime
the old names are used to hopefully convince test authors to update their test code :D ).

.. WARNING::
These aliases will be removed in version 0.4
As of version 0.4 they have been removed and accessing them will raise a :exc:`SyntaxError`.

.. autoclass:: PageObject
.. autoclass:: PageElement
Expand Down
8 changes: 4 additions & 4 deletions holmium/core/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class Deprecated(object):
def __new__(cls, *args, **kwargs):
warnings.warn("The use of %s is deprecated. Use %s instead" % (
cls.cur, cls.alt.__name__)
, DeprecationWarning
, stacklevel=2)
raise SyntaxError("%s has been removed as of version 0.4. Use %s instead" % (
cls.cur, cls.alt.__name__
)
)
return super(Deprecated, cls).__new__(cls)


Expand Down
24 changes: 5 additions & 19 deletions tests/deprecation_tests.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import unittest
import holmium.core
import mock
import selenium.webdriver
class DeprecatedPageTest(unittest.TestCase):
def setUp(self):
self.driver = selenium.webdriver.PhantomJS()
def test_basic_po(self):
with mock.patch('warnings.warn') as warn:
class BasicPage(holmium.core.PageObject):
element = holmium.core.PageElement( holmium.core.Locators.ID, "test_id" )
elements = holmium.core.PageElements( holmium.core.Locators.ID, "test_id" )
elementmap = holmium.core.PageElementMap( holmium.core.Locators.ID, "test_id" )
self.driver.execute_script('document.write("%s");' % """<body><div id='test_id'>test_text</div></body>""")
po = BasicPage(self.driver)
self.assertEquals( "test_text", po.element.text)
self.assertEquals( "test_text", po.elements[0].text)
self.assertEquals( "test_id", po.elementmap["test_text"].get_attribute("id"))
self.assertTrue( warn.call_count == 4 )

def tearDown(self):
if self.driver:
self.driver.quit()
self.assertRaises(SyntaxError, holmium.core.PageObject)
self.assertRaises(SyntaxError, holmium.core.PageElement)
self.assertRaises(SyntaxError, holmium.core.PageElements)
self.assertRaises(SyntaxError, holmium.core.PageElementMap)
self.assertRaises(SyntaxError, holmium.core.HolmiumTestCase)

0 comments on commit 25b519c

Please sign in to comment.