# Path: pyjob/stopwatch.py
# class StopWatch(Time):
#     """Stopwatch class"""
# 
#     def __init__(self):
#         """Instantiate a new :obj:`~pyjob.stopwatch.StopWatch`"""
#         super().__init__(1)
#         self.reset()
# 
#     def __enter__(self):
#         """Contextmanager entry function
# 
#         Note
#         ----
#         For further details see `PEP 343 <https://www.python.org/dev/peps/pep-0343/>`_.
# 
#         """
#         self.start()
#         return self
# 
#     def __exit__(self, *exc):
#         """Contextmanager exit function
# 
#         Note
#         ----
#         For further details see `PEP 343 <https://www.python.org/dev/peps/pep-0343/>`_.
# 
#         """
#         self.stop()
# 
#     def __getitem__(self, id):
#         """Slice the intervals"""
#         return self._intervals[id]
# 
#     def __repr__(self):
#         return f"{self.__class__.__qualname__}(time={self.time}s intervals={len(self._intervals)})"
# 
#     @property
#     def intervals(self):
#         """The intervals taken"""
#         return self._intervals
# 
#     @property
#     def lap(self):
#         """Take a lap snapshot"""
#         if len(self._intervals) > 0 and self._intervals[-1]._running:
#             return self._intervals[-1].lap
#         logger.critical("Cannot add a lap, stopwatch not running!")
# 
#     @property
#     def nintervals(self):
#         """Number of intervals"""
#         return len(self._intervals)
# 
#     @property
#     def running(self):
#         """Stopwatch status"""
#         return len(self._intervals) > 0 and self._intervals[-1]._running
# 
#     @property
#     def time(self):
#         """Time in seconds"""
#         return sum([interval.time for interval in self._intervals])
# 
#     def reset(self):
#         """Reset the timer"""
#         self._intervals = []
#         self._running = False
#         self._iinterval = 0
# 
#     def start(self):
#         """Start the interval"""
#         if len(self._intervals) > 0 and self._intervals[-1]._running:
#             logger.warning("Stopwatch already running!")
#         else:
#             logger.debug("Starting stopwatch ...")
#             self._iinterval += 1
#             interval = Interval(self._iinterval)
#             interval.start()
#             self._intervals += [interval]
#         return interval
# 
#     def stop(self):
#         """Stop the interval"""
#         if len(self._intervals) > 0 and self._intervals[-1]._running:
#             logger.debug("Stopping stopwatch ...")
#             self._intervals[-1].stop()
#         else:
#             logger.warning("Stopwatch not running!")
#         return self._intervals[-1]


import time
import unittest
from pyjob.stopwatch import StopWatch
    def test_stop_2(self):
        sw = StopWatch()
        sw.start()
        time.sleep(1)
        sw.stop()
        assert round(sw.time) == 1.0
        time.sleep(1)
        sw.start()
        time.sleep(2)
        sw.stop()
        assert round(sw.time) == 3.0
        assert sw.nintervals == 2

    def test_stop_3(self):
        sw = StopWatch()
        sw.start()
        time.sleep(1)
        sw.stop()
        time.sleep(1)
        sw.start()
        time.sleep(2)
        sw.stop()
        time.sleep(1)
        sw.start()
        time.sleep(1)
        sw.stop()
        assert round(sw.time) == 4.0
        assert sw.nintervals == 3

    def test_lap_1(self):

# Path: pyjob/stopwatch.py
# class StopWatch(Time):
#     """Stopwatch class"""
# 
#     def __init__(self):
#         """Instantiate a new :obj:`~pyjob.stopwatch.StopWatch`"""
#         super().__init__(1)
#         self.reset()
# 
#     def __enter__(self):
#         """Contextmanager entry function
# 
#         Note
#         ----
#         For further details see `PEP 343 <https://www.python.org/dev/peps/pep-0343/>`_.
# 
#         """
#         self.start()
#         return self
# 
#     def __exit__(self, *exc):
#         """Contextmanager exit function
# 
#         Note
#         ----
#         For further details see `PEP 343 <https://www.python.org/dev/peps/pep-0343/>`_.
# 
#         """
#         self.stop()
# 
#     def __getitem__(self, id):
#         """Slice the intervals"""
#         return self._intervals[id]
# 
#     def __repr__(self):
#         return f"{self.__class__.__qualname__}(time={self.time}s intervals={len(self._intervals)})"
# 
#     @property
#     def intervals(self):
#         """The intervals taken"""
#         return self._intervals
# 
#     @property
#     def lap(self):
#         """Take a lap snapshot"""
#         if len(self._intervals) > 0 and self._intervals[-1]._running:
#             return self._intervals[-1].lap
#         logger.critical("Cannot add a lap, stopwatch not running!")
# 
#     @property
#     def nintervals(self):
#         """Number of intervals"""
#         return len(self._intervals)
# 
#     @property
#     def running(self):
#         """Stopwatch status"""
#         return len(self._intervals) > 0 and self._intervals[-1]._running
# 
#     @property
#     def time(self):
#         """Time in seconds"""
#         return sum([interval.time for interval in self._intervals])
# 
#     def reset(self):
#         """Reset the timer"""
#         self._intervals = []
#         self._running = False
#         self._iinterval = 0
# 
#     def start(self):
#         """Start the interval"""
#         if len(self._intervals) > 0 and self._intervals[-1]._running:
#             logger.warning("Stopwatch already running!")
#         else:
#             logger.debug("Starting stopwatch ...")
#             self._iinterval += 1
#             interval = Interval(self._iinterval)
#             interval.start()
#             self._intervals += [interval]
#         return interval
# 
#     def stop(self):
#         """Stop the interval"""
#         if len(self._intervals) > 0 and self._intervals[-1]._running:
#             logger.debug("Stopping stopwatch ...")
#             self._intervals[-1].stop()
#         else:
#             logger.warning("Stopwatch not running!")
#         return self._intervals[-1]


# Path: pyjob/tests/test_stopwatch.py
import time
import unittest
from pyjob.stopwatch import StopWatch

    def test_stop_2(self):
        sw = StopWatch()
        sw.start()
        time.sleep(1)
        sw.stop()
        assert round(sw.time) == 1.0
        time.sleep(1)
        sw.start()
        time.sleep(2)
        sw.stop()
        assert round(sw.time) == 3.0
        assert sw.nintervals == 2

    def test_stop_3(self):
        sw = StopWatch()
        sw.start()
        time.sleep(1)
        sw.stop()
        time.sleep(1)
        sw.start()
        time.sleep(2)
        sw.stop()
        time.sleep(1)
        sw.start()
        time.sleep(1)
        sw.stop()
        assert round(sw.time) == 4.0
        assert sw.nintervals == 3

    def test_lap_1(self):

        assert StopWatch().lap is None