def test_updater(self, tmp_update_folder, app_path): db_p = tmp_update_folder.join("internals.db") idb = clsutils.InternalDatabase(str(db_p)) with mock.patch("happypanda.common.constants.internal_db_path", str(db_p)),\ mock.patch("happypanda.common.constants.internaldb", idb),\ mock.patch("happypanda.common.clsutils.internaldb", idb),\ mock.patch("happypanda.common.constants.app_path", app_path),\ mock.patch("updater.constants.internal_db_path", str(db_p)): assert constants.internal_db_path == str(db_p) happyupd.main() db = constants.internaldb d = db[constants.updater_key] assert d['state'] == constants.UpdateState.Success.value assert all( os.path.exists(os.path.join(constants.app_path, x)) for x in asset_files)
def process_notify_step(message): try: notify = user_dict[message.chat.id] notify.notify = int(message.text.strip()) chk = notify.exist(message.chat.id) if chk: bot.send_message(message.chat.id, 'Вы уже подписаны на данное уведомление') else: notify.save(message.chat.id) mrkup = global_kbd() bot.send_message(message.chat.id, u'Вы подписались на уведомление.', reply_markup=mrkup) updater.main() except ValueError: bot.reply_to(message, 'Укажите число от 1 до 3') bot.register_next_step_handler(message, process_notify_step) except: bot.reply_to(message, 'Что-то пошло не так. Попробуйте снова.') bot.register_next_step_handler(message, process_notify_step)
def test_updater_overwrite(self, tmp_update_folder, app_path): all( os.path.exists(os.path.join(constants.app_path, x)) for x in asset_files) db_p = tmp_update_folder.join("internals.db") p = str(tmp_update_folder.mkdir("updater_register2")) idb = clsutils.InternalDatabase(str(db_p)) with mock.patch("happypanda.common.constants.internal_db_path", str(db_p)),\ mock.patch("happypanda.common.constants.internaldb", idb),\ mock.patch("happypanda.common.clsutils.internaldb", idb),\ mock.patch("happypanda.common.constants.app_path", app_path),\ mock.patch("happypanda.common.utils.create_temp_dir") as utils_temp,\ mock.patch("happypanda.core.commands.io_cmd.CoreFS.delete"),\ mock.patch("happypanda.common.constants.dir_update", p): utils_temp.return_value = str( tmp_update_folder.mkdir("updater_release2")) assert updater.register_release(asset_url_platform, silent=False, restart=True) idb = clsutils.InternalDatabase(str(db_p)) with mock.patch("happypanda.common.constants.internal_db_path", str(tmp_update_folder.join("internals"))),\ mock.patch("happypanda.common.constants.app_path", app_path),\ mock.patch("happypanda.common.constants.internaldb", idb),\ mock.patch("happypanda.common.clsutils.internaldb", idb),\ mock.patch("updater.constants.internal_db_path", str(db_p)): assert constants.internal_db_path == str(db_p) with mock.patch("updater.atexit.register") as aexit: happyupd.main() assert aexit.called db = constants.internaldb d = db[constants.updater_key] assert d['state'] == constants.UpdateState.Success.value assert all( os.path.exists(os.path.join(constants.app_path, x)) for x in asset_files)
def to_tabular_format(attribute: str, values: List[dict]) -> str: '''Convert the values into one-column tabular data format. Credit for panda's dataframe snippet: [email protected]''' if len(values) == 0: return "No values found.\nTry 'python discoverer.py --help' for more information." columns = [attribute] df = DataFrame(values, index=range(1, len(values) + 1), columns=[attribute]) return df def main(): '''Read the metadata file and run the query.''' with open(METADATA_FILENAME) as f: metadata = json.load(f) attribute = parse_attribute() values = get_distinct_values(attribute, metadata) tabular_results = to_tabular_format(attribute, values) print(tabular_results) if __name__ == '__main__': updater.main() main()
#-*- coding: utf-8 -*- # # Copyright (C) 2007 Gianni Valdambrini, Develer S.r.l (http://www.develer.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Author: Gianni Valdambrini [email protected] __version__ = "$Revision$"[11:-2] __docformat__ = 'restructuredtext' # This is a dummy module, needed by installer to leaves out the real python code # from the package. So the updater can update the python code without touching # the package (that is platform-dependent, so it require more work to modify) import updater updater.main()