def main(): app = QtGui.QApplication(sys.argv) dialog = lambda: QtGui.QMessageBox.question(QtGui.QWidget(), 'First time', \ "It appears you've started the app for the first time. Do you want to load demo data?", QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) DBManager.init_dbmanager(dialog) main = Main() main.show() sys.exit(app.exec_())
def test_check_threshold(self): clients = self.get_client_nodes() data = Main().parse_client(clients[0]) stats = Stats.get_or_create(**data) with patch("app.tasks.send_email.delay"): data = Main().parse_client(clients[0]) stats.cpu_usage = 18 stats.mem_usage = 55 cpu_alert, mem_alert = check_threshold(stats) self.assertEqual(cpu_alert, False) self.assertEqual(mem_alert, True)
def test_validate_arg_syntax(): '''ensure the args passed are syntactically correct''' sys.argv.remove('BADARG') sys.argv.append('project') sys.argv.append('environment') sys.argv.append('platform') main = Main()
def test_pass_bad_cli_args(): '''pass a bad arg get the default help message''' with pytest.raises(SystemExit) as e: sys.argv[0] = 'BADARG' main = Main() assert e.type == SystemExit assert e.value == 2
def run_server(): Main(injector).start(contexts) flask = injector.get(Flask) from waitress import serve print("The service is running.") serve(flask, host="0.0.0.0", port=5000)
def test_parse_client(self): clients = self.get_client_nodes() self.assertEqual(1, len(clients)) data = Main().parse_client(clients[0]) self.assertEqual(type({}), type(data)) self.assertEqual(data["ip"], "11.11.11.11") self.assertEqual(data["port"], 22) self.assertEqual(data["username"], "test_username") self.assertEqual(data["password"], "test_password") self.assertEqual(data["email"], "test_email") self.assertEqual(data["cpu_threshold"], 50.0) self.assertEqual(data["mem_threshold"], 20.0)
# encoding: utf-8 """ openbikebox websocket-client Copyright (c) 2021, binary butterfly GmbH Use of this source code is governed by an MIT-style license that can be found in the LICENSE file. """ from app.main import Main if __name__ == '__main__': Main()
import sys from app.main import Main if __name__ == "__main__": m = Main() if len(sys.argv)>1: for arg in sys.argv[1:]: if arg == "setup": m.setup() else: print("Unknown option ("+arg+")! Options are: setup") else: m.run()
def test_pass_no_cli_args(): '''ensure we get a help message when no args are passed''' with pytest.raises(SystemExit) as e: main = Main() assert e.type == SystemExit assert e.value == 2
def setUp(self): super(ServerTestCase, self).setUp() Main()
def test_get_or_create(self): clients = self.get_client_nodes() data = Main().parse_client(clients[0]) stats = Stats.get_or_create(**data) self.assertEqual(stats.ip, "11.11.11.11")
def test_process_clients_file_incorrect_syntax(self): clients_list = os.path.join(os.path.dirname(__file__), "clients_incorrect.xml") self.assertFalse(Main().process_clients(clients_list))
def test_process_clients_wrong_file_path(self): self.assertFalse(Main().process_clients("wrong_path"))
#! /usr/bin/env python from __future__ import absolute_import import os import sys PROJECT_DIR = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir)) sys.path.append(PROJECT_DIR) sys.path.append(os.path.abspath(os.path.join(PROJECT_DIR, "app"))) if __name__ == "__main__": from app.main import Main aws_bucket_name = None if len(sys.argv) > 1: aws_bucket_name = sys.argv[1] Main().load_images(aws_bucket_name)
#! /usr/bin/env python from __future__ import absolute_import import os import _mypath # noqa if __name__ == "__main__": from app.main import Main clients_list = os.path.abspath( os.path.join(os.path.dirname(__file__), "../app/clients.xml")) Main().process_clients(clients_list)