def test_main_diff(self, sync_mock, teamleader_client_mock, *models_mock): app = App() app.teamleader_sync(full_sync=False) assert sync_mock.call_count == 1 call_arg = sync_mock.call_args[1] assert call_arg['full_sync'] is False
def run_gui(): receiver_port = sys.argv[1] app = QApplication(sys.argv) ex = App(receiver_port) ex.show() app.exec_() print('[GUI] GUI closed')
def app(request): global browser if browser is None: browser = App() # if server == 'stage': # browser.wd.get('http://*****:*****@stage.restaurantsupply.com') if is_logged == True: get(base_url) browser.index_page.login() sleep( 3 ) # значение подгружается через какое-то время, а не при открытии страницы if int(browser.index_page.cart_counter_number.text) > 0: browser.cart_page.empty_cart() def fin(): global browser browser.destroy() browser = None request.addfinalizer(fin) return browser
def test_authcode_callback_invalid(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() result = app.tlc.authcode_callback('auth_code', 'wrong_state') assert result == 'code rejected'
def test_no_yaml(self): """Testing that a new config.yaml gets created if it isn't present """ path = '{}/tests/dirs/test_no_yaml'.format(os.getcwd()) conf_path = '{}/config.yaml'.format(path) # remove any present config file at path try: os.remove(conf_path) except: pass # create directory path if non existent try: os.makedirs(path) except OSError: print('Could not make directories') # move to create directory path try: os.chdir(path) except OSError: print('Could not change path to {}'.path) # run __init__ with no config file app = App() self.assertTrue(os.path.isfile(conf_path)) test_dict = {} with open(conf_path, 'r') as handle: test_dict = yaml.full_load(handle) self.assertEqual(test_dict['yaml_path'], conf_path) self.assertEqual(test_dict['root'], os.getcwd())
def main(): parser = argparse.ArgumentParser(description="MQTT DB gateway") parser.add_argument('method', choices=['start', 'stop', 'reload']) parser.add_argument("--cfg", dest="cfg", action="store", default="/etc/mqtt_db_gateway/mqtt_db_gateway.ini", help="Full path to configuration") parser.add_argument("--pid", dest="pid", action="store", default="/var/run/mqtt_db_gateway/mqtt_db_gateway.pid", help="Full path to PID file") parser.add_argument("--nodaemon", dest="nodaemon", action="store_true", help="Do not daemonize, run in foreground") parsed_args = parser.parse_args() if parsed_args.method == 'stop': Daemon.stop(parsed_args.pid) elif parsed_args.method == 'start': app = App( cfg=parsed_args.cfg, pid=parsed_args.pid, nodaemon=parsed_args.nodaemon ) Daemon.start(app) elif parsed_args.method == 'reload': Daemon.reload(parsed_args.pid)
def predictor(): '''' Receives the file to be classified. It translates to another unique name. ''' filename = request.args.get('filename') image_path = os.path.join(app.config['UPLOAD_FOLDER'], filename) message = App().predict(os.path.abspath(image_path)) return render_template('prediction.html', label=message, filename=filename)
def test_program_cleanup_mqtt(self, mqttclientmock): app = App(cfg='cfg', pid='pid', nodaemon=False) app.mqttclient = mqttclientmock app.close_resources() mqttclientmock.close.assert_called_with()
def test_program_cleanup_engine(self, enginemock): app = App(cfg='cfg', pid='pid', nodaemon=False) app.engine = enginemock app.close_resources() enginemock.close.assert_called_with()
def main(stdscr): app = App(stdscr) app.add_window(Window(30, 10, "Window one").move_to(3, 1)) app.add_window(Window(30, 10, "Window two").move_to(10, 7)) app.add_window(Window(30, 10, "Window three").move_to(17, 13)) app.start()
def test_authcode_callback_valid(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() result = app.tlc.authcode_callback('auth_code', 'code_to_validate_callback') assert result == 'code accepted'
def start(self): self.log.print("validating wifi credentials...","OK") while True: if(self.manage_wifi()): break self.log.print("Configuration complete...","OK") self.log.print("Starting new instance of the app...","OK") app=App(CONFIG['app_name'],CONFIG['app_key'],CONFIG['app_version']) app.start()
def _add_holding(): app = App(DATA_STORE_FILENAME) try: ticker, units = request.form['ticker'].upper(), int(request.form['units']) app.add_holding(ticker, units) return Response('', status=201) except ValueError: abort(400) except OSError as e: abort(500)
def test_readConfig_fileread_noname(self, configparsermock, grpmock): app = App(cfg='cfg', pid='pid', nodaemon=True) instance = configparsermock.return_value grpmock.getgrnam.return_value(('name', 'passwd', 1, 'users')) app.readConfig(None) instance.read.assert_called_with('mqtt_db_gateway.ini')
def run_app(): #initialize our app class with empty values for taxon and protein as we will set these after we decide what the user wishes to run and what advanced settings will be changed before setting taxon and protein query. The classes need to beinitialized in order to save any changes to the state app = App("", "") #here, the welcome information is printed, a list of what the user may want to run is displayed and features can be turned on or off, or advanced settings like bootstrapping, esearch retmax, max accessions processed can all be tweaked. Handler.path_list booleans are turned on or off here which will be used to navigate the program's steps in handle() handler = Handler.welcome(app) #have the user assign their taxon and protein choices, user input for this is handled in the user_input class app.taxon_query = "taxonomy" app.protein_query = "protein" #run the function above with our basal set parameters handle(app, handler)
def _delete_holding(): app = App(DATA_STORE_FILENAME) try: ticker = request.form['ticker'].upper() app.remove_holding(ticker) return Response('', status=204) except ValueError: abort(404) except OSError as e: abort(500)
def _load_autoscaler_apps(self): apps = [] for app in config['APPS']: try: apps.append(App(**app)) except Exception as e: msg = "Could not load {}: The error was: {}".format(app, e) logging.critical(msg) raise CannotLoadConfig(msg) self.autoscaler_apps = apps
def test_unauth_details(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() self.details_unauthorized = True self.resource_name = 'contacts' mock_requests.get = MagicMock(side_effect=self.mock_api_calls) result = app.tlc.request_item(f'/{self.resource_name}.info', 'uuid1') assert result == {'data': 'resource data here', 'id': 'uuid1'} assert not self.details_unauthorized
def test_unauth_listing(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() self.list_unauthorized = True self.resource_name = 'contacts' mock_requests.get = MagicMock(side_effect=self.mock_api_calls) result = app.tlc.request_page(f'/{self.resource_name}.list', 1, 20, None) assert result == [{'id': 'uuid1'}] assert not self.list_unauthorized
def test_good_root(self): '''Test ''' path = '/home/smadonna/Downloads' app = App(path) self.assertEqual(App._config['root'], path) test_dict = {} with open('config.yaml', 'r') as handle: test_dict = yaml.full_load(handle) self.assertEqual(test_dict['root'], path) self.assertEqual(os.getcwd(), path)
def test_current_user(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() # mock requests.get so that api call returns something we want user_data = {'data': {'name': 'current_user'}} mresp = Mock() mock_requests.get.return_value = mresp mresp.status_code = 200 mresp.json.return_value = user_data result = app.tlc.current_user() assert mresp.json.call_count == 1 assert result == user_data['data']
def test_custom_field_get(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() # mock requests.get so that api call returns something we want field_data = {'data': {'id': 'uidhere'}} mresp = Mock() mock_requests.get.return_value = mresp mresp.status_code = 200 mresp.json.return_value = field_data result = app.tlc.get_custom_field('uidhere') assert mresp.json.call_count == 1 assert result == field_data['data']
def test_custom_fields(self, mock_requests, mock_auth_table, *models): ma = mock_auth_table.return_value ma.count.return_value = 0 app = App() # mock requests.get so that api call returns something we want fields_data = {'data': []} mresp = Mock() mock_requests.get.return_value = mresp mresp.status_code = 200 mresp.json.return_value = fields_data fields = app.tlc.list_custom_fields() assert mresp.json.call_count == 1 assert fields == fields_data['data']
def test_readConfig_mandatorysection_nodaemon(self, configparsermock, grpmock): app = App(cfg='cfg', pid='pid', nodaemon=True) instance = configparsermock.return_value grpmock.getgrnam.return_value(('name', 'passwd', 1, 'users')) def get_side_effect(section, key): if section == 'sqlalchemy' and key == 'uri': raise NoSectionError('Mandatory config test') else: return DEFAULT instance.get.side_effect = get_side_effect self.assertRaises(SystemExit, app.readConfig, None)
def test_main_full(self, sync_mock, teamleader_client_mock, tl_auth_mock, contacts_mock, companies_mock, departments_mock, events_mock, invoices_mock, projects_mock, users_mock): # Mock max_last_modified_timestamp to return None companies_mock().max_last_modified_timestamp.return_value = None contacts_mock().max_last_modified_timestamp.return_value = None departments_mock().max_last_modified_timestamp.return_value = None events_mock().max_last_modified_timestamp.return_value = None invoices_mock().max_last_modified_timestamp.return_value = None projects_mock().max_last_modified_timestamp.return_value = None users_mock().max_last_modified_timestamp.return_value = None app = App() app.teamleader_sync(full_sync=True) assert sync_mock.call_count == 1 call_arg = sync_mock.call_args[1] assert call_arg['full_sync'] is True
def test_readConfig_mandatorysection_daemon(self, configparsermock, grpmock, daemonmock, loggermock): app = App(cfg='cfg', pid='pid', nodaemon=False) daemonmock.is_open.return_value = True app.daemon = daemonmock instance = configparsermock.return_value grpmock.getgrnam.return_value(('name', 'passwd', 1, 'users')) def get_side_effect(section, key): if section == 'sqlalchemy' and key == 'uri': raise NoSectionError('Mandatory config test') else: return DEFAULT instance.get.side_effect = get_side_effect self.assertIsNone(app.readConfig(conf_file=None))
def init_dependencies(): config_obj = Config() util_obj = Util() draw_obj = Draw(util_obj) connections_obj = Connections(util_obj) generator_obj = Generator(util_obj) data_obj = Data(generator_obj, util_obj) features_obj = Features(config_obj, util_obj) classify_obj = Classification(config_obj, features_obj, util_obj) independent_obj = Independent(config_obj, classify_obj, util_obj) comments_obj = Comments(config_obj, util_obj) pred_builder_obj = PredicateBuilder(config_obj, comments_obj, generator_obj, util_obj) psl_obj = PSL(config_obj, connections_obj, draw_obj, pred_builder_obj, util_obj) tuffy_obj = Tuffy(config_obj, pred_builder_obj, util_obj) mrf_obj = MRF(config_obj, connections_obj, draw_obj, generator_obj, util_obj) relational_obj = Relational(connections_obj, config_obj, psl_obj, tuffy_obj, mrf_obj, util_obj) label_obj = Label(config_obj, generator_obj, util_obj) purity_obj = Purity(config_obj, generator_obj, util_obj) evaluate_obj = Evaluation(config_obj, generator_obj, connections_obj, util_obj) interpret_obj = Interpretability(config_obj, connections_obj, generator_obj, pred_builder_obj, util_obj) analysis_obj = Analysis(config_obj, label_obj, purity_obj, evaluate_obj, interpret_obj, util_obj) app_obj = App(config_obj, data_obj, independent_obj, relational_obj, analysis_obj, util_obj) return config_obj, app_obj, util_obj
def run(): app = App() app.start() return 0
parser = get_parser() args = parser.parse_args() load = not args.drop config = { "DEBUG": args.debug or False, "FORCE": args.force or False, "VERBOSE": args.verbose or False, "SILENT": args.silent or False, "DATA_DIR": get_data_dir(), "DB_PATH": get_db_path(), "LOAD": load } if args.drop: app = App(config) sys.exit(app.drop_all()) else: app = App(config) if args.sync: if not args.provider: app.sync_all() else: provider = args.provider sys.exit(app.sync(provider)) elif args.clear: if not args.provider: app.clear_all() else: provider = args.provider
def main(): config.init() print("This is the entrypoint to the application") app = App() app.run()