# Path: alibuild_helpers/log.py
# def dieOnError(err, msg):
#   if err:
#     error("%s", msg)
#     sys.exit(1)
# 
# class ProgressPrint:
#   def __init__(self, begin_msg=""):
#     self.count = -1
#     self.lasttime = 0
#     self.STAGES = [ ".", "..", "...", "....", ".....", "....", "...", ".." ]
#     self.begin_msg = begin_msg
#     self.percent = -1
#   def __call__(self, txt, *args):
#     txt %= args
#     if time.time()-self.lasttime < 0.5:
#       return
#     if self.count == -1 and self.begin_msg:
#       sys.stderr.write("\033[1;35m==>\033[m "+self.begin_msg)
#     self.erase()
#     m = re.search("((^|[^0-9])([0-9]{1,2})%|\[([0-9]+)/([0-9]+)\])", txt)
#     if m:
#       if m.group(3) is not None:
#         self.percent = int(m.group(3))
#       else:
#         num = int(m.group(4))
#         den = int(m.group(5))
#         if num >= 0 and den > 0:
#           self.percent = 100 * num / den
#     if self.percent > -1:
#       sys.stderr.write(" [%2d%%] " % self.percent)
#     self.count = (self.count+1) % len(self.STAGES)
#     sys.stderr.write(self.STAGES[self.count])
#     self.lasttime = time.time()
#   def erase(self):
#     nerase = len(self.STAGES[self.count]) if self.count > -1 else 0
#     if self.percent > -1:
#       nerase = nerase + 7
#     sys.stderr.write("\b"*nerase+" "*nerase+"\b"*nerase)
#   def end(self, msg="", error=False):
#     if self.count == -1:
#       return
#     self.erase()
#     if msg:
#       sys.stderr.write(": %s%s\033[m" % ("\033[31m" if error else "\033[32m", msg))
#     sys.stderr.write("\n")


    from unittest.mock import patch  # In Python 3, mock is built-in
    from mock import patch  # Python 2
from alibuild_helpers.log import dieOnError, ProgressPrint
from time import sleep
import unittest
from __future__ import print_function
# Assuming you are using the mock library to ... mock things
try:
except ImportError:



class LogTestCase(unittest.TestCase):
    @patch('alibuild_helpers.log.error')
    @patch('alibuild_helpers.log.sys')
    def test_dieOnError(self, mock_sys, mock_error):
      dieOnError(True, "Message")
      mock_sys.exit.assert_called_once_with(1)
      mock_error.assert_called_once_with("%s", "Message")
      mock_error.reset_mock()

# Path: alibuild_helpers/log.py
# def dieOnError(err, msg):
#   if err:
#     error("%s", msg)
#     sys.exit(1)
# 
# class ProgressPrint:
#   def __init__(self, begin_msg=""):
#     self.count = -1
#     self.lasttime = 0
#     self.STAGES = [ ".", "..", "...", "....", ".....", "....", "...", ".." ]
#     self.begin_msg = begin_msg
#     self.percent = -1
#   def __call__(self, txt, *args):
#     txt %= args
#     if time.time()-self.lasttime < 0.5:
#       return
#     if self.count == -1 and self.begin_msg:
#       sys.stderr.write("\033[1;35m==>\033[m "+self.begin_msg)
#     self.erase()
#     m = re.search("((^|[^0-9])([0-9]{1,2})%|\[([0-9]+)/([0-9]+)\])", txt)
#     if m:
#       if m.group(3) is not None:
#         self.percent = int(m.group(3))
#       else:
#         num = int(m.group(4))
#         den = int(m.group(5))
#         if num >= 0 and den > 0:
#           self.percent = 100 * num / den
#     if self.percent > -1:
#       sys.stderr.write(" [%2d%%] " % self.percent)
#     self.count = (self.count+1) % len(self.STAGES)
#     sys.stderr.write(self.STAGES[self.count])
#     self.lasttime = time.time()
#   def erase(self):
#     nerase = len(self.STAGES[self.count]) if self.count > -1 else 0
#     if self.percent > -1:
#       nerase = nerase + 7
#     sys.stderr.write("\b"*nerase+" "*nerase+"\b"*nerase)
#   def end(self, msg="", error=False):
#     if self.count == -1:
#       return
#     self.erase()
#     if msg:
#       sys.stderr.write(": %s%s\033[m" % ("\033[31m" if error else "\033[32m", msg))
#     sys.stderr.write("\n")


# Path: tests/test_log.py
    from unittest.mock import patch  # In Python 3, mock is built-in
    from mock import patch  # Python 2
from alibuild_helpers.log import dieOnError, ProgressPrint
from time import sleep
import unittest

from __future__ import print_function
# Assuming you are using the mock library to ... mock things
try:
except ImportError:



class LogTestCase(unittest.TestCase):
    @patch('alibuild_helpers.log.error')
    @patch('alibuild_helpers.log.sys')
    def test_dieOnError(self, mock_sys, mock_error):
      dieOnError(True, "Message")
      mock_sys.exit.assert_called_once_with(1)
      mock_error.assert_called_once_with("%s", "Message")
      mock_error.reset_mock()

      dieOnError(False, "Message")