# Path: fretwork/log.py
# def configure(log_filename, log_level=logging.INFO):


import logging
import os
import tempfile
import unittest
from fretwork import log
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.




class ConfigureTest(unittest.TestCase):

    def setUp(self):
        self.logfile = tempfile.NamedTemporaryFile(delete=True)

    def test_logger(self):
        # configurer the logger
        #log.configure(self.logfile.name, logging.INFO)
        log.configure(self.logfile.name)
        self.assertTrue(os.path.exists(self.logfile.name))

        # log a message
        logger = logging.getLogger(__name__)
        msg = "Test info log"
        logger.info(msg)

        # read the log file
        log_msg = self.logfile.readline().decode()
        self.assertIn('INFO', log_msg)
        self.assertIn(msg, log_msg)

    def test_logger_warning_level(self):
        # configurer the logger in Warning level
        #log.configure(self.logfile.name, logging.WARNING)

# Path: fretwork/log.py
# def configure(log_filename, log_level=logging.INFO):


# Path: tests/test_log.py
import logging
import os
import tempfile
import unittest
from fretwork import log

# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.




class ConfigureTest(unittest.TestCase):

    def setUp(self):
        self.logfile = tempfile.NamedTemporaryFile(delete=True)

    def test_logger(self):
        # configurer the logger
        #log.configure(self.logfile.name, logging.INFO)
        log.configure(self.logfile.name)
        self.assertTrue(os.path.exists(self.logfile.name))

        # log a message
        logger = logging.getLogger(__name__)
        msg = "Test info log"
        logger.info(msg)

        # read the log file
        log_msg = self.logfile.readline().decode()
        self.assertIn('INFO', log_msg)
        self.assertIn(msg, log_msg)

    def test_logger_warning_level(self):
        # configurer the logger in Warning level
        #log.configure(self.logfile.name, logging.WARNING)

        log.configure(self.logfile.name, 'WARNING')