def prepare_test(load_config=True, connect_database=True, connect_logger=True): config_file_name = Utils.new_tmp_file() log_file_name = Utils.new_tmp_file() db_file_name = Utils.new_tmp_file() contest_dir = Utils.new_tmp_dir("contest", create=False) with open(config_file_name, 'w') as file: file.write("logfile: %s\n" "db: %s\n" "storedir: %s\n" "contest_path: %s\n" % (log_file_name, db_file_name, Utils.new_tmp_dir(), contest_dir)) if load_config: Config.loaded = False Config.set_config_file(config_file_name) if connect_logger: Logger.connected = False Logger.connect_to_database() Logger.set_log_level("WARNING") if connect_database: Database.connected = False Database.connect_to_database()
def main(): parser = argparse.ArgumentParser() parser.add_argument("-c", "--config", help="Path to the config file", default="config/config.yaml") args = parser.parse_args() if args.config: Config.set_config_file(args.config) Logger.set_log_level(Config.log_level) Logger.connect_to_database() Database.connect_to_database() try: ContestManager.read_from_disk(remove_enc=False) except: Logger.warning("CONTEST", "Failed to read the contest from disk...") server = Server() server.run()
def test_invalid_yaml(self): self._write_config("[42") with self.assertRaises(ruamel.yaml.parser.ParserError): Config.set_config_file(self.configFilePath)
def test_empty_config(self): Config.set_config_file(self.configFilePath)
def test_cannot_load_again(self): self._write_config("test: foo") Config.set_config_file(self.configFilePath) with self.assertRaises(RuntimeError): Config.set_config_file(self.configFilePath)
def test_file_not_found(self): with self.assertRaises(SystemExit): with Utils.nostderr(): Config.set_config_file("/this/file/doesnt/exist")
def test_class_method_generation(self): self._write_config("test: 42") Config.set_config_file(self.configFilePath) self.assertEqual(42, Config.test)