# Path: nappingcat/patterns.py
# def patterns(path, *args):
#     return CommandPatterns(path, args) 
# 
# Path: nappingcat/exceptions.py
# class NappingCatUnhandled(NappingCatException):
#     pass
# 
# class NappingCatBadPatterns(NappingCatBadConfig):
#     pass


from unittest import TestCase
from nappingcat import patterns
from nappingcat.exceptions import NappingCatUnhandled, NappingCatBadPatterns
import random
        results = patterns.CommandPatterns('tests.patterns_test', '')
        self.assertEqual(random.__class__, results.module.__class__)

        self.assertRaises(ImportError, patterns.CommandPatterns, 'dne', '')

    def test_match_raises_unhandled_if_no_match(self):
        test = patterns.CommandPatterns('', [])
        anything = 'random-%d' % random.randint(1,100)
        self.assertRaises(NappingCatUnhandled, test.match, anything)

    def test_delegates_to_included_patterns(self):
        random_result = random.randint(1,100)
        class TriggerCommandPatterns(patterns.CommandPatterns):
            def match(self, command):
                return random_result
        pat = patterns.CommandPatterns('', [('^hey', TriggerCommandPatterns('', []))])
        self.assertEqual(pat.match('hey'), random_result)

    def test_continues_to_next_match_if_delegate_raises_unhandled(self):
        random_result = random.randint(1,100)
        class TriggerCommandPatterns(patterns.CommandPatterns):
            def match(self, command):
                raise NappingCatUnhandled("OH no!")
        test_fn = lambda *args, **kwargs: random_result
        pat = patterns.CommandPatterns('', [('^hey', TriggerCommandPatterns('', [])), ('^hey', test_fn)])
        target, match = pat.match('hey')
        self.assertEqual(target, test_fn)
        self.assertTrue(hasattr(match, 'groupdict'))    # not a great way to test whether or not it's a regex match object...

    def test_attempts_to_grab_str_target_off_of_module(self):

# Path: nappingcat/patterns.py
# def patterns(path, *args):
#     return CommandPatterns(path, args) 
# 
# Path: nappingcat/exceptions.py
# class NappingCatUnhandled(NappingCatException):
#     pass
# 
# class NappingCatBadPatterns(NappingCatBadConfig):
#     pass


# Path: tests/patterns.py
from unittest import TestCase
from nappingcat import patterns
from nappingcat.exceptions import NappingCatUnhandled, NappingCatBadPatterns
import random

        results = patterns.CommandPatterns('tests.patterns_test', '')
        self.assertEqual(random.__class__, results.module.__class__)

        self.assertRaises(ImportError, patterns.CommandPatterns, 'dne', '')

    def test_match_raises_unhandled_if_no_match(self):
        test = patterns.CommandPatterns('', [])
        anything = 'random-%d' % random.randint(1,100)
        self.assertRaises(NappingCatUnhandled, test.match, anything)

    def test_delegates_to_included_patterns(self):
        random_result = random.randint(1,100)
        class TriggerCommandPatterns(patterns.CommandPatterns):
            def match(self, command):
                return random_result
        pat = patterns.CommandPatterns('', [('^hey', TriggerCommandPatterns('', []))])
        self.assertEqual(pat.match('hey'), random_result)

    def test_continues_to_next_match_if_delegate_raises_unhandled(self):
        random_result = random.randint(1,100)
        class TriggerCommandPatterns(patterns.CommandPatterns):
            def match(self, command):
                raise NappingCatUnhandled("OH no!")
        test_fn = lambda *args, **kwargs: random_result
        pat = patterns.CommandPatterns('', [('^hey', TriggerCommandPatterns('', [])), ('^hey', test_fn)])
        target, match = pat.match('hey')
        self.assertEqual(target, test_fn)
        self.assertTrue(hasattr(match, 'groupdict'))    # not a great way to test whether or not it's a regex match object...

    def test_attempts_to_grab_str_target_off_of_module(self):

        pat = patterns.CommandPatterns('tests.patterns', [