# Path: wtframework/wtf/testobjects/basetests.py
# class WTFBaseTest(WatchedTestCase):
# 
#     '''
#     Test can extend this basetest to add additional unit test functionality such as 
#     take screenshot on failure.
# 
#     Example::
# 
#         from wtframework.wtf.testobjects.basetests import WTFBaseTest
#         from wtframework.wtf.web.webdriver import WTF_WEBDRIVER_MANAGER
# 
#         class TestScreenCaptureOnFail(WTFBaseTest):
#             """"
#             These test cases are expected to fail.  They are here to test 
#             the screen capture on failure.
#             """
# 
#             # Comment out decorator to manually test the screen capture.
#             @unittest.expectedFailure
#             def test_fail(self):
#                 driver = WTF_WEBDRIVER_MANAGER.new_driver()
#                 driver.get('http://www.google.com')
#                 self.fail()
#                 #Check your /screenshots folder for a screenshot of Google Homepage.
# 
# 
#     For the screen capture to work, you need to make sure you use WTF_WEBDRIVER_MANAGER for 
#     getting your webdriver instance. This is used for getting the current instance of webdriver 
#     when a test fails in order to take a screenshot.
# 
#     WTFBaseTest is also an instance of WatchedTestCase, which you can use to add additional 
#     call backs you wish to use for handling errors or other test events.
#     '''
# 
#     def __init__(self, methodName='runTest', webdriver_provider=None, screenshot_util=None):
#         """
#         Constructor matches that of UnitTest2 test case, but modified to allow passing in 
#         a ScreenShot utility and register delayed test watchers.
# 
#         Kwargs:
#             methodName (str) : Test method name.
#             webdriver_provider (WebdriverManager) : Default webdriver provider.
#             screenshot_util (CaptureScreenShotOnErrorTestWatcher) : Screenshot capture utility.
# 
#         """
#         super(WTFBaseTest, self).__init__(methodName)
#         self._register_watcher(
#             CaptureScreenShotOnErrorTestWatcher(webdriver_provider, screenshot_util))
# 
#         # Note this watcher should be registered after all other watchers that use
#         # on_test_passed() event.
#         self._delayed_test_watcher = DelayedTestFailTestWatcher()
#         self._register_watcher(self._delayed_test_watcher)
# 
#     def assertWithDelayedFailure(self, assert_method, *args, **kwargs):
#         """
#         Cause an assertion failure to be delayed till the end of the test.
#         This is good to use if you want the test to continue after an assertion
#         fails, and do addtional assertions.  At the end of the test, it will 
#         pool all the test failures into 1 failed assert with a summary of 
#         all the test failures that occurred during the test.
# 
#         Args:
#             assert_method (function) - Assert method to run.
#             args - arguments to pass into the assert method.
# 
#         Kwargs:
#             kwargs - additional kwargs to pass into the assert method.
# 
# 
#         Will assert if percent == 100 at the end of the test.::
# 
#             self.assertWithDelayedFailure(self.AssertEquals, 100, percent)
# 
#         """
#         frame = None
#         try:
#             # attempt to get parent frames
#             frame = inspect.getouterframes(inspect.currentframe())[1]
#         except:
#             pass  # oh well, we couldn't get it.
# 
#         assert_func = lambda: assert_method(*args, **kwargs)
#         generated_exception = self._delayed_test_watcher.delay_failure(
#             assert_func, frame)
# 
#         if generated_exception:
#             # Call our on_fail for our test watchers.  So we can trigger our screen
#             # capture at moment of failure.
#             for test_watcher in self.__wtf_test_watchers__:
#                 test_watcher.on_test_failure(
#                     self, self._resultForDoCleanups, generated_exception)


import unittest
from wtframework.wtf.testobjects.basetests import WTFBaseTest
##########################################################################


# Using WTFBaseTest since it already consumes this test Watcher.


class Test(WTFBaseTest):

    # Note, this test is expected to fail, we want to check if we get 1 exception
    # that embeds the 3 exceptions from the failed asserts.
    # To test this, uncomment out the unittest.skipTest decorator.
    # Then check the exception thrown to see if it includes the 3 exceptions we
    # delayed failure on.
    @unittest.SkipTest
    def test_delayed_test_fail(self):
        "Check that delayed test failures are raised at the end of a test."
        # all 3 are expected to fail, but look in the log message to check for
        # the "Test Passed" message
        self.assertWithDelayedFailure(self.assertEqual, 1, 2)
        self.assertWithDelayedFailure(self.assertTrue, False)
        self.assertWithDelayedFailure(self.assertGreater, 1, 2)
        print "Test ran all the way through.  Now check the console log to make sure "

    def test_delayed_test_pass(self):
        "Check that when assertions pass, no error is thrown afterwards."
        # all 3 are expected to fail, but look in the log message to check for
        # the "Test Passed" message
        self.assertWithDelayedFailure(self.assertEqual, 1, 1)
        self.assertWithDelayedFailure(self.assertTrue, True)
        self.assertWithDelayedFailure(self.assertGreater, 2, 1)

# Path: wtframework/wtf/testobjects/basetests.py
# class WTFBaseTest(WatchedTestCase):
# 
#     '''
#     Test can extend this basetest to add additional unit test functionality such as 
#     take screenshot on failure.
# 
#     Example::
# 
#         from wtframework.wtf.testobjects.basetests import WTFBaseTest
#         from wtframework.wtf.web.webdriver import WTF_WEBDRIVER_MANAGER
# 
#         class TestScreenCaptureOnFail(WTFBaseTest):
#             """"
#             These test cases are expected to fail.  They are here to test 
#             the screen capture on failure.
#             """
# 
#             # Comment out decorator to manually test the screen capture.
#             @unittest.expectedFailure
#             def test_fail(self):
#                 driver = WTF_WEBDRIVER_MANAGER.new_driver()
#                 driver.get('http://www.google.com')
#                 self.fail()
#                 #Check your /screenshots folder for a screenshot of Google Homepage.
# 
# 
#     For the screen capture to work, you need to make sure you use WTF_WEBDRIVER_MANAGER for 
#     getting your webdriver instance. This is used for getting the current instance of webdriver 
#     when a test fails in order to take a screenshot.
# 
#     WTFBaseTest is also an instance of WatchedTestCase, which you can use to add additional 
#     call backs you wish to use for handling errors or other test events.
#     '''
# 
#     def __init__(self, methodName='runTest', webdriver_provider=None, screenshot_util=None):
#         """
#         Constructor matches that of UnitTest2 test case, but modified to allow passing in 
#         a ScreenShot utility and register delayed test watchers.
# 
#         Kwargs:
#             methodName (str) : Test method name.
#             webdriver_provider (WebdriverManager) : Default webdriver provider.
#             screenshot_util (CaptureScreenShotOnErrorTestWatcher) : Screenshot capture utility.
# 
#         """
#         super(WTFBaseTest, self).__init__(methodName)
#         self._register_watcher(
#             CaptureScreenShotOnErrorTestWatcher(webdriver_provider, screenshot_util))
# 
#         # Note this watcher should be registered after all other watchers that use
#         # on_test_passed() event.
#         self._delayed_test_watcher = DelayedTestFailTestWatcher()
#         self._register_watcher(self._delayed_test_watcher)
# 
#     def assertWithDelayedFailure(self, assert_method, *args, **kwargs):
#         """
#         Cause an assertion failure to be delayed till the end of the test.
#         This is good to use if you want the test to continue after an assertion
#         fails, and do addtional assertions.  At the end of the test, it will 
#         pool all the test failures into 1 failed assert with a summary of 
#         all the test failures that occurred during the test.
# 
#         Args:
#             assert_method (function) - Assert method to run.
#             args - arguments to pass into the assert method.
# 
#         Kwargs:
#             kwargs - additional kwargs to pass into the assert method.
# 
# 
#         Will assert if percent == 100 at the end of the test.::
# 
#             self.assertWithDelayedFailure(self.AssertEquals, 100, percent)
# 
#         """
#         frame = None
#         try:
#             # attempt to get parent frames
#             frame = inspect.getouterframes(inspect.currentframe())[1]
#         except:
#             pass  # oh well, we couldn't get it.
# 
#         assert_func = lambda: assert_method(*args, **kwargs)
#         generated_exception = self._delayed_test_watcher.delay_failure(
#             assert_func, frame)
# 
#         if generated_exception:
#             # Call our on_fail for our test watchers.  So we can trigger our screen
#             # capture at moment of failure.
#             for test_watcher in self.__wtf_test_watchers__:
#                 test_watcher.on_test_failure(
#                     self, self._resultForDoCleanups, generated_exception)


# Path: wtframework/wtf/testobjects/tests/test_delayed_failed_test_watcher.py
import unittest
from wtframework.wtf.testobjects.basetests import WTFBaseTest

##########################################################################


# Using WTFBaseTest since it already consumes this test Watcher.


class Test(WTFBaseTest):

    # Note, this test is expected to fail, we want to check if we get 1 exception
    # that embeds the 3 exceptions from the failed asserts.
    # To test this, uncomment out the unittest.skipTest decorator.
    # Then check the exception thrown to see if it includes the 3 exceptions we
    # delayed failure on.
    @unittest.SkipTest
    def test_delayed_test_fail(self):
        "Check that delayed test failures are raised at the end of a test."
        # all 3 are expected to fail, but look in the log message to check for
        # the "Test Passed" message
        self.assertWithDelayedFailure(self.assertEqual, 1, 2)
        self.assertWithDelayedFailure(self.assertTrue, False)
        self.assertWithDelayedFailure(self.assertGreater, 1, 2)
        print "Test ran all the way through.  Now check the console log to make sure "

    def test_delayed_test_pass(self):
        "Check that when assertions pass, no error is thrown afterwards."
        # all 3 are expected to fail, but look in the log message to check for
        # the "Test Passed" message
        self.assertWithDelayedFailure(self.assertEqual, 1, 1)
        self.assertWithDelayedFailure(self.assertTrue, True)
        self.assertWithDelayedFailure(self.assertGreater, 2, 1)

        print "Test ran all the way through.  Now check the console log to make sure "