Exemple #1
0
    def test_uninstall_all(self):
        before_handlers_root = root.handlers[:]
        before_handlers_child = child.handlers[:]

        l1 = LogCapture()
        l2 = LogCapture('one.child')

        # We can see that the LogCaptures have changed the
        # handlers, removing existing ones and installing
        # their own:

        assert len(root.handlers) == 1
        assert root.handlers != before_handlers_root
        assert len(child.handlers) == 1
        assert child.handlers != before_handlers_child

        # Now we show the function in action:

        LogCapture.uninstall_all()

        # ...and we can see the handlers are back as
        # they were beefore:

        assert before_handlers_root == root.handlers
        assert before_handlers_child == child.handlers
    def test_uninstall_all(self):
        before_handlers_root = root.handlers[:]
        before_handlers_child = child.handlers[:]

        l1 = LogCapture()
        l2 = LogCapture('one.child')

        # We can see that the LogCaptures have changed the
        # handlers, removing existing ones and installing
        # their own:

        assert len(root.handlers) == 1
        assert root.handlers != before_handlers_root
        assert len(child.handlers) == 1
        assert child.handlers != before_handlers_child

        # Now we show the function in action:

        LogCapture.uninstall_all()

        # ...and we can see the handlers are back as
        # they were beefore:

        assert before_handlers_root == root.handlers
        assert before_handlers_child == child.handlers
Exemple #3
0
    def test_move(self):
        l = LogCapture()

        drivar = DrivarHolonomic()
        drivar.initialize()
        drivar.motor_move()
        #         l.check(('drivar.DrivarHolonomic', 'DEBUG', 'Drivar : initialized'),
        #                 ('drivar.DrivarHolonomic', 'INFO', 'Drivar : Moving all wheels with power 70.'),
        #                 ('drivar.DrivarHolonomic', 'INFO', 'Drivar : Stopping the vehicle.'))
        drivar.motor_turn()

        l.uninstall_all()
    def test_two_logcaptures_on_same_logger(self):
        # If you create more than one LogCapture on a single
        # logger, the 2nd one installed will stop the first
        # one working!

        l1 = LogCapture()
        root.info('1st message')
        assert str(l1) == "root INFO\n  1st message"
        l2 = LogCapture()
        root.info('2nd message')

        # So, l1 missed this message:
        assert str(l1) == "root INFO\n  1st message"

        # ...because l2 kicked it out and recorded the message:

        assert str(l2) == "root INFO\n  2nd message"

        LogCapture.uninstall_all()
Exemple #5
0
    def test_two_logcaptures_on_same_logger(self):
        # If you create more than one LogCapture on a single
        # logger, the 2nd one installed will stop the first
        # one working!

        l1 = LogCapture()
        root.info('1st message')
        assert str(l1) == "root INFO\n  1st message"
        l2 = LogCapture()
        root.info('2nd message')

        # So, l1 missed this message:
        assert str(l1) == "root INFO\n  1st message"

        # ...because l2 kicked it out and recorded the message:

        assert str(l2) == "root INFO\n  2nd message"

        LogCapture.uninstall_all()
    def test_uninstall_more_than_once(self):
        # There's no problem with uninstalling a LogCapture
        # more than once:

        old_level = root.level
        try:
           root.setLevel(49)
           l = LogCapture()
           assert root.level == 1
           l.uninstall()
           assert root.level == 49
           root.setLevel(69)
           l.uninstall()
           assert root.level == 69
        finally:
           root.setLevel(old_level)

        # And even when loggers have been uninstalled, there's
        # no problem having uninstall_all as a backstop:

        l.uninstall_all()
Exemple #7
0
    def test_uninstall_more_than_once(self):
        # There's no problem with uninstalling a LogCapture
        # more than once:

        old_level = root.level
        try:
            root.setLevel(49)
            l = LogCapture()
            assert root.level == 1
            l.uninstall()
            assert root.level == 49
            root.setLevel(69)
            l.uninstall()
            assert root.level == 69
        finally:
            root.setLevel(old_level)

        # And even when loggers have been uninstalled, there's
        # no problem having uninstall_all as a backstop:

        l.uninstall_all()
Exemple #8
0
 def teardown_class(cls):
     LogCapture.uninstall_all()
     logging.shutdown()
     if os.path.isfile(TEST_OUTPUT_LOG):
         os.remove(TEST_OUTPUT_LOG)
Exemple #9
0
def tearDown(test):
    TempDirectory.cleanup_all()
    LogCapture.uninstall_all()
Exemple #10
0
 def teardown_method(self):
     LogCapture.uninstall_all()
     logging.shutdown()
     if os.path.isfile(TEST_OUTPUT_LOG):
         os.remove(TEST_OUTPUT_LOG)
Exemple #11
0
 def teardown_method(self):
     LogCapture.uninstall_all()
     configure_loggers_from_string('all=off', connection=True)
     if os.path.isfile(TEST_OUTPUT_LOG):
         os.remove(TEST_OUTPUT_LOG)
def tearDown(test):
    TempDirectory.cleanup_all()
    LogCapture.uninstall_all()
Exemple #13
0
 def tearDown(self):
     LogCapture.uninstall_all()
Exemple #14
0
 def tearDown(self):
     LogCapture.uninstall_all()
def teardown_module():
    LogCapture.uninstall_all()
Exemple #16
0
class TestBase(object):

    """Tests Servercheck base class"""

    def __init__(self):
        """TODO: to be defined1. """
        self.logger = logging.getLogger('TestBase')

        self.passing_msg = 'Test has Passed'
        self.failing_msg = 'Test has Failed'

        self.report_logname = 'servercheck'

    def setup(self):
        self.log_capture = LogCapture()
        self.verbose_tester = BaseTester(verbose=True,
                                         item='verbose_test')

        self.default_tester = BaseTester(item='default_test')

        self.verbose_logname = '{}.{}.verbose_test'.format('servercheck',
                                                           self.verbose_tester.__class__.__name__)  # nopep8
        self.default_logname = '{}.{}.default_test'.format('servercheck',
                                                        self.default_tester.__class__.__name__)  # nopep8

    def teardown(self):
        self.log_capture.uninstall_all()

    def test_verbose_output_from_passing_test(self):
        self.verbose_tester.passed(self.passing_msg)

        self.log_capture.check(
            (self.verbose_logname,
             'INFO',
             '\033[1;32mPASS: {}\033[0m'.format(self.passing_msg)
             )
        )

    def test_default_output_from_passing_test(self):
        self.default_tester.passed(self.passing_msg)

        self.log_capture.check()

    def test_verbose_output_from_failing_test(self):
        self.verbose_tester.failed(self.failing_msg)

        self.log_capture.check(
            (self.verbose_logname,
             'WARNING',
             '\033[1;31mFAIL: {}\033[0m'.format(self.failing_msg)
             )
        )

    def test_default_output_from_failing_test(self):
        self.default_tester.failed(self.failing_msg)

        self.log_capture.check(
            (self.default_logname,
             'WARNING',
             '\033[1;31mFAIL: {}\033[0m'.format(self.failing_msg)
             )
        )

    def test_report_with_no_failing_tests(self):
        self.default_tester.passed(self.passing_msg)

        self.default_tester.report()

        self.log_capture.check(
            (self.report_logname,
             'INFO',
             '----- Report: -----\n\n'
             '\033[1;32mAll tests passed, YAY!\033[0m\n\n'
             '-------------------',
             )
        )

    def test_report_with_one_failing_test(self):
        self.default_tester.failed(self.failing_msg)

        self.default_tester.report()

        self.log_capture.check(
            (self.default_logname,
             'WARNING',
             '\033[1;31mFAIL: {}\033[0m'.format(self.failing_msg)
             ),
            (self.report_logname,
             'WARNING',
             '----- Report: -----\n\n'
             '\033[1;31mFAIL: {}\033[0m\n\n'
             '-------------------'.format(self.failing_msg),
             ),
        )

    def test_report_with_multiple_failing_tests(self):
        self.default_tester.failed(self.failing_msg)
        self.default_tester.failed(self.failing_msg)

        self.default_tester.report()

        self.log_capture.check(
            (self.default_logname,
             'WARNING',
             '\033[1;31mFAIL: {}\033[0m'.format(self.failing_msg)
             ),
            (self.default_logname,
             'WARNING',
             '\033[1;31mFAIL: {}\033[0m'.format(self.failing_msg)
             ),
            (self.report_logname,
             'WARNING',
             '----- Report: -----\n\n'
             '\033[1;31mFAIL: {}\033[0m\n'
             '\033[1;31mFAIL: {}\033[0m\n\n'
             '-------------------'.format(self.failing_msg,
                                          self.failing_msg)
             )
        )