Exemplo n.º 1
0
class WatcherTestBase(unittest.TestCase):
    def setUp(self):
        self.__db = tempfile.mkstemp()
        dburi = "sqlite:///" + self.__db[1]
        init_database(dburi)

        conf = WatcherTestConfig(dburi)
        self.__sleep_time = conf.DAEMON["wait_delay"] + 1

        self.__watcher = SupysonicWatcher(conf)

    def tearDown(self):
        release_database()
        os.close(self.__db[0])
        os.remove(self.__db[1])

    def _start(self):
        self.__watcher.start()
        time.sleep(0.2)

    def _stop(self):
        self.__watcher.stop()

    def _is_alive(self):
        return self.__watcher.running

    def _sleep(self):
        time.sleep(self.__sleep_time)
Exemplo n.º 2
0
    def setUp(self):
        self.__db = tempfile.mkstemp()
        dburi = "sqlite:///" + self.__db[1]
        init_database(dburi)

        conf = WatcherTestConfig(dburi)
        self.__sleep_time = conf.DAEMON["wait_delay"] + 1

        self.__watcher = SupysonicWatcher(conf)
Exemplo n.º 3
0
    def setUp(self):
        self.__dbfile = tempfile.mkstemp()[1]
        conf = WatcherTestConfig('sqlite:///' + self.__dbfile)
        self.__sleep_time = conf.DAEMON['wait_delay'] + 1

        with self._get_store() as store:
            with io.open('schema/sqlite.sql', 'r') as sql:
                schema = sql.read()
                for statement in schema.split(';'):
                    store.execute(statement)

        self.__watcher = SupysonicWatcher(conf)
        self.__thread = Thread(target=self.__watcher.run)
Exemplo n.º 4
0
class WatcherTestBase(unittest.TestCase):
    @contextmanager
    def _get_store(self):
        store = None
        try:
            store = get_store('sqlite:///' + self.__dbfile)
            yield store
            store.commit()
            store.close()
        except:
            store.rollback()
            store.close()
            raise

    def setUp(self):
        self.__dbfile = tempfile.mkstemp()[1]
        conf = WatcherTestConfig('sqlite:///' + self.__dbfile)
        self.__sleep_time = conf.DAEMON['wait_delay'] + 1

        with self._get_store() as store:
            with io.open('schema/sqlite.sql', 'r') as sql:
                schema = sql.read()
                for statement in schema.split(';'):
                    store.execute(statement)

        self.__watcher = SupysonicWatcher(conf)
        self.__thread = Thread(target=self.__watcher.run)

    def tearDown(self):
        os.unlink(self.__dbfile)

    def _start(self):
        self.__thread.start()
        time.sleep(0.2)

    def _stop(self):
        self.__watcher.stop()
        self.__thread.join()

    def _is_alive(self):
        return self.__thread.is_alive()

    def _sleep(self):
        time.sleep(self.__sleep_time)