# Path: hypebot/core/util_lib.py
# def Access(obj, path, default=None):
# def ArrowTime(hour=0, minute=0, second=0, tz='UTC', weekday=None):
# def CanonicalizeName(raw_name: Text):
# def UnformatHypecoins(value):
# def ExtractRegex(pattern: Text,
#                  string: Text) -> Optional[Tuple[List[Text], Text]]:
# def FormatHypecoins(amount, abbreviate=False):
# def SafeCast(value, desired_type, default=None):
# def TimeDeltaToHumanDuration(time_delta, precision=1):
# def SafeUrl(url, params=None):
#   def __init__(self, items: Iterable[Text],
#                initial_weights: Optional[Iterable[float]] = None):
#   def Freeze(self):
#   def GetItem(self) -> Text:
#   def GetWeight(self, item: Text) -> Optional[float]:
#   def GetAndDownweightItem(self) -> Text:
#   def ModifyWeight(self, item: Text, update_fn: Callable[[float],
#                                                          float]) -> float:
#   def _NormalizeProbs(self):
# def Bold(string):
# def Italic(string):
# def Underline(string):
# def Colorize(string, color, irc=True):
# def StripColor(string):
# def Dankify(string):
# def FuzzyBool(value):
# def Sparkline(values):
#   def __init__(self, user: user_pb2.User):
#   def __init__(self):
#   def RecordActivity(self, user: user_pb2.User, channel: channel_pb2.Channel):
#   def LastActivity(self, user: user_pb2.User):
#   def AddUser(self,
#               user: user_pb2.User,
#               channel: Optional[channel_pb2.Channel] = None):
#   def AllHumans(self, channel: Optional[channel_pb2.Channel] = None):
#   def AllBots(self, channel: Optional[channel_pb2.Channel] = None):
#   def AllUsers(self, channel: Optional[channel_pb2.Channel] = None):
# def MatchesAny(channels, channel):
# def _CardAsTextList(card: message_pb2.Card) -> List[Text]:
# def _AppendToMessage(msg: hype_types.Message,
#                      response: hype_types.CommandResponse):
# def MakeMessage(response: hype_types.CommandResponse) -> hype_types.Message:
# DECIMAL_POWERS = ('', 'k', 'm', 'b', 't', 'q', 'p')
#   YEAR_IN_DAYS = 365.25  # Approximate.
#   MONTH_IN_DAYS = YEAR_IN_DAYS / 12.0  # Average.
#   HOUR_IN_SECONDS = 60 * 60.0
#   MINUTE_IN_SECONDS = 60.0
# _MIRC_COLORS = {
#     'white': (0, '#ffffff'),
#     'black': (1, '#000000'),
#     'blue': (2, '#000075'),
#     'green': (3, '#009300'),
#     'red': (4, '#ff0000'),
#     'brown': (5, '#750000'),
#     'purple': (6, '#9c009c'),
#     'orange': (7, '#fc7500'),
#     'yellow': (8, '#ffff00'),
#     'light green': (9, '#00fc00'),
#     'cyan': (10, '#009393'),
#     'light cyan': (11, '#00ffff'),
#     'light blue': (12, '#0000fc'),
#     'pink': (13, '#ff00ff'),
#     'grey': (14, '#757575'),
#     'light grey': (15, '#d2d2d2'),
# }
# class WeightedCollection(object):
# class _UserTrack(object):
# class UserTracker(object):


import unittest
import arrow
import mock
from hypebot.core import util_lib

  def testExtractRegex_MultipleMatchesAreExtracted(self):
    # pytype can't seem to figure out that result isn't None (or isn't None
    # after asserting it isn't anyways). So we just use it directly instead of
    # destructuring the tuple.
    result = util_lib.ExtractRegex(r'[a-z]+', 'mone1234mtwo')
    self.assertIsNotNone(result)
    self.assertEqual(2, len(result[0]))
    self.assertIn('mone', result[0])
    self.assertIn('mtwo', result[0])
    self.assertEqual('1234', result[1])

  def testExtractRegex_NestedCapturesStillRemoveFullRegex(self):
    result = util_lib.ExtractRegex(r'g(.+)', 'Captures with groups')
    self.assertIsNotNone(result)
    self.assertEqual(1, len(result[0]))
    self.assertEqual('roups', result[0][0])
    self.assertEqual('Captures with ', result[1])


class WeightedCollectionTest(unittest.TestCase):

  def testEmptyCollection(self):
    c = util_lib.WeightedCollection([])

    i = c.GetItem()

    self.assertIsNone(i)

  def testSingleItem(self):

# Path: hypebot/core/util_lib.py
# def Access(obj, path, default=None):
# def ArrowTime(hour=0, minute=0, second=0, tz='UTC', weekday=None):
# def CanonicalizeName(raw_name: Text):
# def UnformatHypecoins(value):
# def ExtractRegex(pattern: Text,
#                  string: Text) -> Optional[Tuple[List[Text], Text]]:
# def FormatHypecoins(amount, abbreviate=False):
# def SafeCast(value, desired_type, default=None):
# def TimeDeltaToHumanDuration(time_delta, precision=1):
# def SafeUrl(url, params=None):
#   def __init__(self, items: Iterable[Text],
#                initial_weights: Optional[Iterable[float]] = None):
#   def Freeze(self):
#   def GetItem(self) -> Text:
#   def GetWeight(self, item: Text) -> Optional[float]:
#   def GetAndDownweightItem(self) -> Text:
#   def ModifyWeight(self, item: Text, update_fn: Callable[[float],
#                                                          float]) -> float:
#   def _NormalizeProbs(self):
# def Bold(string):
# def Italic(string):
# def Underline(string):
# def Colorize(string, color, irc=True):
# def StripColor(string):
# def Dankify(string):
# def FuzzyBool(value):
# def Sparkline(values):
#   def __init__(self, user: user_pb2.User):
#   def __init__(self):
#   def RecordActivity(self, user: user_pb2.User, channel: channel_pb2.Channel):
#   def LastActivity(self, user: user_pb2.User):
#   def AddUser(self,
#               user: user_pb2.User,
#               channel: Optional[channel_pb2.Channel] = None):
#   def AllHumans(self, channel: Optional[channel_pb2.Channel] = None):
#   def AllBots(self, channel: Optional[channel_pb2.Channel] = None):
#   def AllUsers(self, channel: Optional[channel_pb2.Channel] = None):
# def MatchesAny(channels, channel):
# def _CardAsTextList(card: message_pb2.Card) -> List[Text]:
# def _AppendToMessage(msg: hype_types.Message,
#                      response: hype_types.CommandResponse):
# def MakeMessage(response: hype_types.CommandResponse) -> hype_types.Message:
# DECIMAL_POWERS = ('', 'k', 'm', 'b', 't', 'q', 'p')
#   YEAR_IN_DAYS = 365.25  # Approximate.
#   MONTH_IN_DAYS = YEAR_IN_DAYS / 12.0  # Average.
#   HOUR_IN_SECONDS = 60 * 60.0
#   MINUTE_IN_SECONDS = 60.0
# _MIRC_COLORS = {
#     'white': (0, '#ffffff'),
#     'black': (1, '#000000'),
#     'blue': (2, '#000075'),
#     'green': (3, '#009300'),
#     'red': (4, '#ff0000'),
#     'brown': (5, '#750000'),
#     'purple': (6, '#9c009c'),
#     'orange': (7, '#fc7500'),
#     'yellow': (8, '#ffff00'),
#     'light green': (9, '#00fc00'),
#     'cyan': (10, '#009393'),
#     'light cyan': (11, '#00ffff'),
#     'light blue': (12, '#0000fc'),
#     'pink': (13, '#ff00ff'),
#     'grey': (14, '#757575'),
#     'light grey': (15, '#d2d2d2'),
# }
# class WeightedCollection(object):
# class _UserTrack(object):
# class UserTracker(object):


# Path: hypebot/core/util_lib_test.py
import unittest
import arrow
import mock
from hypebot.core import util_lib


  def testExtractRegex_MultipleMatchesAreExtracted(self):
    # pytype can't seem to figure out that result isn't None (or isn't None
    # after asserting it isn't anyways). So we just use it directly instead of
    # destructuring the tuple.
    result = util_lib.ExtractRegex(r'[a-z]+', 'mone1234mtwo')
    self.assertIsNotNone(result)
    self.assertEqual(2, len(result[0]))
    self.assertIn('mone', result[0])
    self.assertIn('mtwo', result[0])
    self.assertEqual('1234', result[1])

  def testExtractRegex_NestedCapturesStillRemoveFullRegex(self):
    result = util_lib.ExtractRegex(r'g(.+)', 'Captures with groups')
    self.assertIsNotNone(result)
    self.assertEqual(1, len(result[0]))
    self.assertEqual('roups', result[0][0])
    self.assertEqual('Captures with ', result[1])


class WeightedCollectionTest(unittest.TestCase):

  def testEmptyCollection(self):
    c = util_lib.WeightedCollection([])

    i = c.GetItem()

    self.assertIsNone(i)

  def testSingleItem(self):

    c = util_lib.WeightedCollection(['a'])