def testLogRegex(self):
     self.topics = [Topic("onLogRegex", "E1")]
     xsettings = [{"matchIf": "kodi_callbacks", "rejectIf": "", "eventId": "E1"}]
     settings = Settings()
     flexmock(settings, getLogRegexes=xsettings)
     flexmock(settings, general={"LogFreq": 100})
     self.publisher = LogPublisher(self.dispatcher, settings)
     try:
         os.remove(testLog.fn)
     except OSError:
         pass
     finally:
         with open(testLog.fn, "w") as f:
             f.writelines("")
     self.subscriber.addTopic(self.topics[0])
     self.dispatcher.addSubscriber(self.subscriber)
     self.dispatcher.start()
     self.publisher.start()
     t = threading.Thread(target=testLog.logSimulate)
     t.start()
     t.join()
     self.publisher.abort()
     self.dispatcher.abort()
     self.subscriber.waitForMessage(count=1, timeout=2)
     try:
         os.remove(testLog.fn)
     except OSError:
         pass
     messages = self.subscriber.retrieveMessages()
     msgtopics = [msg.topic for msg in messages]
     for topic in self.topics:
         assert topic in msgtopics
 def testLogRegex(self):
     self.topics = [Topic('onLogRegex','E1')]
     xsettings = [{'matchIf':'kodi_callbacks', 'rejectIf':'', 'eventId':'E1'}]
     settings = Settings()
     flexmock(settings, getLogRegexes=xsettings)
     flexmock(settings, general={'LogFreq':100})
     self.publisher = LogPublisher(self.dispatcher, settings)
     try:
         os.remove(testLog.fn)
     except OSError:
         pass
     finally:
         with open(testLog.fn, 'w') as f:
             f.writelines('')
     self.subscriber.addTopic(self.topics[0])
     self.dispatcher.addSubscriber(self.subscriber)
     self.dispatcher.start()
     self.publisher.start()
     t = threading.Thread(target=testLog.logSimulate)
     t.start()
     t.join()
     self.publisher.abort()
     self.dispatcher.abort()
     time.sleep(2)
     try:
         os.remove(testLog.fn)
     except OSError:
         pass
     messages = self.subscriber.retrieveMessages()
     msgtopics = [msg.topic for msg in messages]
     for topic in self.topics:
         assert topic in msgtopics
 def testLogRegex(self):
     self.topics = [Topic('onLogRegex', 'E1')]
     xsettings = [{
         'matchIf': 'kodi_callbacks',
         'rejectIf': '',
         'eventId': 'E1'
     }]
     settings = Settings()
     flexmock(settings, getLogRegexes=xsettings)
     flexmock(settings, general={'LogFreq': 100})
     self.publisher = LogPublisher(self.dispatcher, settings)
     try:
         os.remove(testLog.fn)
     except OSError:
         pass
     finally:
         with open(testLog.fn, 'w') as f:
             f.writelines('')
     self.subscriber.addTopic(self.topics[0])
     self.dispatcher.addSubscriber(self.subscriber)
     self.dispatcher.start()
     self.publisher.start()
     t = threading.Thread(target=testLog.logSimulate)
     t.start()
     t.join()
     self.publisher.abort()
     self.dispatcher.abort()
     time.sleep(2)
     try:
         os.remove(testLog.fn)
     except OSError:
         pass
     messages = self.subscriber.retrieveMessages()
     msgtopics = [msg.topic for msg in messages]
     for topic in self.topics:
         assert topic in msgtopics
class testLog(object):
    path = translatepath('special://addondata')
    if not os.path.exists(path):
        os.mkdir(path)
    setPathRW(path)
    fn = translatepath('special://addondata/kodi.log')

    def __init__(self):
        self.publisher = None
        self.dispatcher = None
        self.subscriber = None
        self.globalidletime = None
        self.starttime = None
        self.topics = None

    @staticmethod
    def logSimulate():
        import random, string
        randomstring = ''.join(
            random.choice(string.lowercase) for i in range(30)) + '\n'
        targetstring = '%s%s%s' % (randomstring[:12], 'kodi_callbacks',
                                   randomstring[20:])
        for i in xrange(0, 10):
            with open(testLog.fn, 'a') as f:
                if i == 5:
                    f.writelines(targetstring)
                else:
                    f.writelines(randomstring)
            time.sleep(0.25)

    def setup(self):
        flexmock(log, logfn=testLog.fn)
        flexmock(log.xbmc, log=printlog)
        flexmock(log.xbmc, sleep=sleep)
        self.dispatcher = Dispatcher()
        self.subscriber = testSubscriber()

    def teardown(self):
        self.publisher.abort()
        self.dispatcher.abort()
        del self.publisher
        del self.dispatcher

    def testLogSimple(self):
        self.topics = [Topic('onLogSimple', 'E1')]
        xsettings = [{
            'matchIf': 'kodi_callbacks',
            'rejectIf': '',
            'eventId': 'E1'
        }]
        settings = Settings()
        flexmock(settings, getLogSimples=xsettings)
        flexmock(settings, general={'LogFreq': 100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, 'w') as f:
                f.writelines('')
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        time.sleep(2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics

    def testLogRegex(self):
        self.topics = [Topic('onLogRegex', 'E1')]
        xsettings = [{
            'matchIf': 'kodi_callbacks',
            'rejectIf': '',
            'eventId': 'E1'
        }]
        settings = Settings()
        flexmock(settings, getLogRegexes=xsettings)
        flexmock(settings, general={'LogFreq': 100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, 'w') as f:
                f.writelines('')
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        time.sleep(2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics
class testLog(object):
    path = translatepath("special://addondata")
    if not os.path.exists(path):
        os.mkdir(path)
    setPathRW(path)
    fn = translatepath("special://addondata/kodi.log")

    def __init__(self):
        self.publisher = None
        self.dispatcher = None
        self.subscriber = None
        self.globalidletime = None
        self.starttime = None
        self.topics = None

    @staticmethod
    def logSimulate():
        import random, string

        randomstring = "".join(random.choice(string.lowercase) for _ in range(30)) + "\n"
        targetstring = "%s%s%s" % (randomstring[:12], "kodi_callbacks", randomstring[20:])
        for i in xrange(0, 10):
            with open(testLog.fn, "a") as f:
                if i == 5:
                    f.writelines(targetstring)
                else:
                    f.writelines(randomstring)
            time.sleep(0.25)

    def setup(self):
        flexmock(log, logfn=testLog.fn)
        flexmock(log.xbmc, log=printlog)
        flexmock(log.xbmc, sleep=sleep)
        self.dispatcher = Dispatcher()
        self.subscriber = MockSubscriber()

    def teardown(self):
        self.publisher.abort()
        self.dispatcher.abort()
        del self.publisher
        del self.dispatcher

    def testLogSimple(self):
        self.topics = [Topic("onLogSimple", "E1")]
        xsettings = [{"matchIf": "kodi_callbacks", "rejectIf": "", "eventId": "E1"}]
        settings = Settings()
        flexmock(settings, getLogSimples=xsettings)
        flexmock(settings, general={"LogFreq": 100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, "w") as f:
                f.writelines("")
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        xthread = threading.Thread(target=testLog.logSimulate)
        xthread.start()
        xthread.join()
        self.publisher.abort()
        self.dispatcher.abort()
        self.subscriber.waitForMessage(count=1, timeout=2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics

    def testLogRegex(self):
        self.topics = [Topic("onLogRegex", "E1")]
        xsettings = [{"matchIf": "kodi_callbacks", "rejectIf": "", "eventId": "E1"}]
        settings = Settings()
        flexmock(settings, getLogRegexes=xsettings)
        flexmock(settings, general={"LogFreq": 100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, "w") as f:
                f.writelines("")
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        self.subscriber.waitForMessage(count=1, timeout=2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics
class testLog(object):
    path = translatepath('special://addondata')
    if not os.path.exists(path):
        os.mkdir(path)
    setPathRW(path)
    fn = translatepath('special://addondata/kodi.log')

    def __init__(self):
        self.publisher=None
        self.dispatcher=None
        self.subscriber=None
        self.globalidletime=None
        self.starttime = None
        self.topics = None

    @staticmethod
    def logSimulate():
        import random, string
        randomstring = ''.join(random.choice(string.lowercase) for i in range(30)) + '\n'
        targetstring = '%s%s%s' %(randomstring[:12],'kodi_callbacks',randomstring[20:])
        for i in xrange(0,10):
            with open(testLog.fn, 'a') as f:
                if i == 5:
                    f.writelines(targetstring)
                else:
                    f.writelines(randomstring)
            time.sleep(0.25)

    def setup(self):
        flexmock(log, logfn=testLog.fn)
        flexmock(log.xbmc, log=printlog)
        flexmock(log.xbmc, sleep=sleep)
        self.dispatcher = Dispatcher()
        self.subscriber = testSubscriber()

    def teardown(self):
        self.publisher.abort()
        self.dispatcher.abort()
        del self.publisher
        del self.dispatcher

    def testLogSimple(self):
        self.topics = [Topic('onLogSimple','E1')]
        xsettings = [{'matchIf':'kodi_callbacks', 'rejectIf':'', 'eventId':'E1'}]
        settings = Settings()
        flexmock(settings, getLogSimples=xsettings)
        flexmock(settings, general={'LogFreq':100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, 'w') as f:
                f.writelines('')
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        time.sleep(2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics

    def testLogRegex(self):
        self.topics = [Topic('onLogRegex','E1')]
        xsettings = [{'matchIf':'kodi_callbacks', 'rejectIf':'', 'eventId':'E1'}]
        settings = Settings()
        flexmock(settings, getLogRegexes=xsettings)
        flexmock(settings, general={'LogFreq':100})
        self.publisher = LogPublisher(self.dispatcher, settings)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        finally:
            with open(testLog.fn, 'w') as f:
                f.writelines('')
        self.subscriber.addTopic(self.topics[0])
        self.dispatcher.addSubscriber(self.subscriber)
        self.dispatcher.start()
        self.publisher.start()
        t = threading.Thread(target=testLog.logSimulate)
        t.start()
        t.join()
        self.publisher.abort()
        self.dispatcher.abort()
        time.sleep(2)
        try:
            os.remove(testLog.fn)
        except OSError:
            pass
        messages = self.subscriber.retrieveMessages()
        msgtopics = [msg.topic for msg in messages]
        for topic in self.topics:
            assert topic in msgtopics