# Path: janome/progress.py
# class ProgressHandler(ABC):
# class SimpleProgressIndicator(ProgressHandler):
#     def on_start(self, total, desc=None):
#     def on_progress(self, value=1):
#     def on_complete(self):
#     def __init__(self, update_frequency=0.0001, format=None):
#     def print_progress(self, terminator=''):
#     def on_start(self, total, value=0, desc=None):
#     def on_progress(self, value=1):
#     def on_complete(self):


import unittest
from janome.progress import SimpleProgressIndicator, logger as p_logger
    def test_simple_progress_indicator(self):
        total = 22
        desc = 'Test loop'

        # create SimpleProgressIndicator, print once in 10 times update
        progress_indicator = SimpleProgressIndicator(update_frequency=0.1)

        # initialize
        progress_indicator.on_start(
            total=total,
            desc=desc)

        self.assertEqual(total, progress_indicator.total)
        self.assertEqual(0, progress_indicator.value)
        self.assertEqual(desc, progress_indicator.desc)

        with self.assertLogs(logger=p_logger) as cm:
            # progress to 1 but no outputs (frequency=0.1)
            progress_indicator.on_progress()
            self.assertEqual(1, progress_indicator.value)
            self.assertEqual(0, len(cm.output))

            # progress to 9 but still no outputs
            progress_indicator.on_progress(8)
            self.assertEqual(9, progress_indicator.value)
            self.assertEqual(0, len(cm.output))

            # progress to 10 then 1 output (frequency=0.1)
            progress_indicator.on_progress(1)
            self.assertEqual(10, progress_indicator.value)

# Path: janome/progress.py
# class ProgressHandler(ABC):
# class SimpleProgressIndicator(ProgressHandler):
#     def on_start(self, total, desc=None):
#     def on_progress(self, value=1):
#     def on_complete(self):
#     def __init__(self, update_frequency=0.0001, format=None):
#     def print_progress(self, terminator=''):
#     def on_start(self, total, value=0, desc=None):
#     def on_progress(self, value=1):
#     def on_complete(self):


# Path: tests/test_progress.py
import unittest
from janome.progress import SimpleProgressIndicator, logger as p_logger

    def test_simple_progress_indicator(self):
        total = 22
        desc = 'Test loop'

        # create SimpleProgressIndicator, print once in 10 times update
        progress_indicator = SimpleProgressIndicator(update_frequency=0.1)

        # initialize
        progress_indicator.on_start(
            total=total,
            desc=desc)

        self.assertEqual(total, progress_indicator.total)
        self.assertEqual(0, progress_indicator.value)
        self.assertEqual(desc, progress_indicator.desc)

        with self.assertLogs(logger=p_logger) as cm:
            # progress to 1 but no outputs (frequency=0.1)
            progress_indicator.on_progress()
            self.assertEqual(1, progress_indicator.value)
            self.assertEqual(0, len(cm.output))

            # progress to 9 but still no outputs
            progress_indicator.on_progress(8)
            self.assertEqual(9, progress_indicator.value)
            self.assertEqual(0, len(cm.output))

            # progress to 10 then 1 output (frequency=0.1)
            progress_indicator.on_progress(1)
            self.assertEqual(10, progress_indicator.value)

            self.assertEqual(1, len(cm.output))