Пример #1
0
    def test_config_file_logger(self):
        msg = 'log message test_config_file_logger'
        with temp_directory() as td:
            configure_file_logger('debug', td)
            logger = logging.getLogger(__name__)
            logger.debug(msg)
            self._flush_logging()

            logfile = os.path.abspath(os.path.join(td, 'debug.log'))
            self.assert_in_file(msg, logfile)
Пример #2
0
    def test_config_file_logger(self):
        msg = 'log message test_config_file_logger'
        with temp_directory() as td:
            configure_file_logger('debug', td)
            logger = logging.getLogger(__name__)
            logger.debug(msg)
            self._flush_logging()

            logfile = os.path.abspath(os.path.join(td, 'debug.log'))
            self.assert_in_file(msg, logfile)
Пример #3
0
    def test_temp_dir(self):
        created_td = ''
        with temp_directory() as td:
            created_td = td
            name = os.path.join(td, 'a.txt')
            with open(name, 'w') as f:
                f.write('foo')

            os.path.isfile(name)

        # verify that the temp directory has been cleaned up
        self.assertFalse(os.path.exists(created_td))

        # -- test failure still cleans up
        try:
            with temp_directory() as td:
                created_td = td
                raise RuntimeError()
        except:
            pass

        self.assertFalse(os.path.exists(created_td))
Пример #4
0
    def test_temp_dir(self):
        created_td = ''
        with temp_directory() as td:
            created_td = td
            name = os.path.join(td, 'a.txt')
            with open(name, 'w') as f:
                f.write('foo')

            os.path.isfile(name)

        # verify that the temp directory has been cleaned up
        self.assertFalse(os.path.exists(created_td))

        # -- test failure still cleans up
        try:
            with temp_directory() as td:
                created_td = td
                raise RuntimeError()
        except:
            pass

        self.assertFalse(os.path.exists(created_td))
Пример #5
0
    def test_default_logging_dict(self):
        msg = 'log message test_default_logging_dict'

        with capture_stderr() as output:
            with temp_directory() as td:
                d = default_logging_dict(td, handlers=['default', 'file'])
                logging.config.dictConfig(d)

                logger = logging.getLogger(__name__)
                logger.debug(msg)
                self._flush_logging()

                logfile = os.path.abspath(os.path.join(td, 'debug.log'))

                self.assert_in_file(msg, logfile)

                self.assertIn(msg, output.getvalue())
Пример #6
0
    def test_default_logging_dict(self):
        msg = 'log message test_default_logging_dict'

        with capture_stderr() as output:
            with temp_directory() as td:
                d = default_logging_dict(td, handlers=['default', 'file'])
                logging.config.dictConfig(d)

                logger = logging.getLogger(__name__)
                logger.debug(msg)
                self._flush_logging()

                logfile = os.path.abspath(os.path.join(td, 'debug.log'))

                self.assert_in_file(msg, logfile)

                self.assertIn(msg, output.getvalue())
Пример #7
0
 def setUpClass(cls):
     cls.temp_dir_cm = temp_directory()
     cls.dir_name = cls.temp_dir_cm.__enter__()
Пример #8
0
 def setUpClass(cls):
     cls.temp_dir_cm = temp_directory()
     cls.dir_name = cls.temp_dir_cm.__enter__()