class testWatchdogStartup(object): def __init__(self): self.publisher=None self.dispatcher=None self.subscriber=None self.topic=None self.folder=None self.saveduserpickle = None def setup(self): self.folder = translatepath('special://addon/resources/lib/tests') watchdogStartupSettings = [{'ws_folder':self.folder, 'ws_patterns':'*', 'ws_ignore_patterns':'', 'ws_ignore_directories':True, 'ws_recursive':False, 'key':'E1'}] self.saveduserpickle = WatchdogStartup.getPickle() self.dispatcher = Dispatcher() self.subscriber = testSubscriber() self.topic = Topic('onStartupFileChanges','E1') self.subscriber.addTopic(self.topic) self.dispatcher.addSubscriber(self.subscriber) settings = Settings() flexmock(settings, getWatchdogStartupSettings=watchdogStartupSettings) self.publisher = WatchdogStartup(self.dispatcher, settings) self.dispatcher.start() def teardown(self): WatchdogStartup.savePickle(self.saveduserpickle) self.publisher.abort() self.dispatcher.abort() del self.publisher del self.dispatcher def testWatchdogPublisherCreate(self): fn = os.path.join(self.folder,'test.txt') if os.path.exists(fn): os.remove(fn) self.publisher.start() self.publisher.abort() time.sleep(1) self.subscriber.testq=Queue.Queue() with open(fn, 'w') as f: f.writelines('test') time.sleep(1) self.publisher.start() time.sleep(2) self.publisher.abort() self.dispatcher.abort() os.remove(fn) messages = self.subscriber.retrieveMessages() found = False for message in messages: assert isinstance(message, Message) assert 'listOfChanges' in message.kwargs.keys() tmp = message.kwargs['listOfChanges'] if 'FilesCreated' in tmp.keys() and [fn] in tmp.values(): found = True assert message.topic == self.topic assert found == True if len(messages) > 1: raise AssertionError('Warning: Too many messages found for Watchdog Startup Create')
def setup(self): self.folder = translatepath('special://addon/resources/lib/tests') watchdogStartupSettings = [{'ws_folder':self.folder, 'ws_patterns':'*', 'ws_ignore_patterns':'', 'ws_ignore_directories':True, 'ws_recursive':False, 'key':'E1'}] self.saveduserpickle = WatchdogStartup.getPickle() self.dispatcher = Dispatcher() self.subscriber = testSubscriber() self.topic = Topic('onStartupFileChanges','E1') self.subscriber.addTopic(self.topic) self.dispatcher.addSubscriber(self.subscriber) settings = Settings() flexmock(settings, getWatchdogStartupSettings=watchdogStartupSettings) self.publisher = WatchdogStartup(self.dispatcher, settings) self.dispatcher.start()
def setup(self): self.folder = translatepath('special://addon/resources/lib/tests') watchdogStartupSettings = [{ 'ws_folder': self.folder, 'ws_patterns': '*', 'ws_ignore_patterns': '', 'ws_ignore_directories': True, 'ws_recursive': False, 'key': 'E1' }] self.saveduserpickle = WatchdogStartup.getPickle() self.dispatcher = Dispatcher() self.subscriber = testSubscriber() self.topic = Topic('onStartupFileChanges', 'E1') self.subscriber.addTopic(self.topic) self.dispatcher.addSubscriber(self.subscriber) settings = Settings() flexmock(settings, getWatchdogStartupSettings=watchdogStartupSettings) self.publisher = WatchdogStartup(self.dispatcher, settings) self.dispatcher.start()
def setup(self): self.folder = translatepath("special://addon/resources/lib/tests") watchdogStartupSettings = [ { "ws_folder": self.folder, "ws_patterns": "*", "ws_ignore_patterns": "", "ws_ignore_directories": True, "ws_recursive": False, "key": "E1", } ] self.saveduserpickle = WatchdogStartup.getPickle() self.dispatcher = Dispatcher() self.subscriber = MockSubscriber() self.topic = Topic("onStartupFileChanges", "E1") self.subscriber.addTopic(self.topic) self.dispatcher.addSubscriber(self.subscriber) settings = Settings() flexmock(settings, getWatchdogStartupSettings=watchdogStartupSettings) self.publisher = WatchdogStartup(self.dispatcher, settings) self.dispatcher.start()
def teardown(self): WatchdogStartup.savePickle(self.saveduserpickle) self.publisher.abort() self.dispatcher.abort() del self.publisher del self.dispatcher
class testWatchdogStartup(object): def __init__(self): self.publisher = None self.dispatcher = None self.subscriber = None self.topic = None self.folder = None self.saveduserpickle = None def setup(self): self.folder = translatepath('special://addon/resources/lib/tests') watchdogStartupSettings = [{ 'ws_folder': self.folder, 'ws_patterns': '*', 'ws_ignore_patterns': '', 'ws_ignore_directories': True, 'ws_recursive': False, 'key': 'E1' }] self.saveduserpickle = WatchdogStartup.getPickle() self.dispatcher = Dispatcher() self.subscriber = testSubscriber() self.topic = Topic('onStartupFileChanges', 'E1') self.subscriber.addTopic(self.topic) self.dispatcher.addSubscriber(self.subscriber) settings = Settings() flexmock(settings, getWatchdogStartupSettings=watchdogStartupSettings) self.publisher = WatchdogStartup(self.dispatcher, settings) self.dispatcher.start() def teardown(self): WatchdogStartup.savePickle(self.saveduserpickle) self.publisher.abort() self.dispatcher.abort() del self.publisher del self.dispatcher def testWatchdogPublisherCreate(self): fn = os.path.join(self.folder, 'test.txt') if os.path.exists(fn): os.remove(fn) self.publisher.start() self.publisher.abort() time.sleep(1) self.subscriber.testq = Queue.Queue() with open(fn, 'w') as f: f.writelines('test') time.sleep(1) self.publisher.start() time.sleep(2) self.publisher.abort() self.dispatcher.abort() os.remove(fn) messages = self.subscriber.retrieveMessages() found = False for message in messages: assert isinstance(message, Message) assert 'listOfChanges' in message.kwargs.keys() tmp = message.kwargs['listOfChanges'] if 'FilesCreated' in tmp.keys() and [fn] in tmp.values(): found = True assert message.topic == self.topic assert found == True if len(messages) > 1: raise AssertionError( 'Warning: Too many messages found for Watchdog Startup Create')
class testWatchdogStartup(object): def __init__(self): self.publisher = None self.dispatcher = None self.subscriber = None self.topic = None self.folder = None self.saveduserpickle = None def setup(self): self.folder = translatepath("special://addon/resources/lib/tests") watchdogStartupSettings = [ { "ws_folder": self.folder, "ws_patterns": "*", "ws_ignore_patterns": "", "ws_ignore_directories": True, "ws_recursive": False, "key": "E1", } ] self.saveduserpickle = WatchdogStartup.getPickle() self.dispatcher = Dispatcher() self.subscriber = MockSubscriber() self.topic = Topic("onStartupFileChanges", "E1") self.subscriber.addTopic(self.topic) self.dispatcher.addSubscriber(self.subscriber) settings = Settings() flexmock(settings, getWatchdogStartupSettings=watchdogStartupSettings) self.publisher = WatchdogStartup(self.dispatcher, settings) self.dispatcher.start() def teardown(self): WatchdogStartup.savePickle(self.saveduserpickle) self.publisher.abort() self.dispatcher.abort() del self.publisher del self.dispatcher def testWatchdogPublisherCreate(self): fn = os.path.join(self.folder, "test.txt") if os.path.exists(fn): os.remove(fn) self.publisher.start() self.publisher.abort() time.sleep(1) self.subscriber.testq = Queue.Queue() with open(fn, "w") as f: f.writelines("test") time.sleep(1) self.publisher.start() self.subscriber.waitForMessage(count=2, timeout=2) self.publisher.abort() self.dispatcher.abort() os.remove(fn) messages = self.subscriber.retrieveMessages() found = False for message in messages: assert isinstance(message, Message) assert "listOfChanges" in message.kwargs.keys() tmp = message.kwargs["listOfChanges"] if "FilesCreated" in tmp.keys() and [fn] in tmp.values(): found = True assert message.topic == self.topic assert found == True if len(messages) > 1: raise AssertionError("Warning: Too many messages found for Watchdog Startup Create")
def teardown(self): WatchdogStartup.savePickle(self.saveduserpickle) self.publisher.abort() self.dispatcher.abort() del self.publisher del self.dispatcher