def best_match_under_conditions_interface(window, values): """ :param window: Fenêtre principale PySimpleGUI :param values: Valeurs de la fenêtre principale :return: Affiche le résultat de la fonction best_match_under_condition dans l'interface """ try: site = values["SITE_UNDER_CONDITION"][0] bet = float(values["BET_UNDER_CONDITION"]) minimum_odd = float(values["ODD_UNDER_CONDITION"]) sport = values["SPORT_UNDER_CONDITION"][0] date_min, time_min, date_max, time_max = None, None, None, None if values["DATE_MIN_UNDER_CONDITION_BOOL"]: date_min = values["DATE_MIN_UNDER_CONDITION"] time_min = values["TIME_MIN_UNDER_CONDITION"].replace(":", "h") if values["DATE_MAX_UNDER_CONDITION_BOOL"]: date_max = values["DATE_MAX_UNDER_CONDITION"] time_max = values["TIME_MAX_UNDER_CONDITION"].replace(":", "h") one_site = values["ONE_SITE_UNDER_CONDITION"] old_stdout = sys.stdout # Memorize the default stdout stream sys.stdout = buffer = io.StringIO() if one_site: best_match_under_conditions2(site, minimum_odd, bet, sport, date_max, time_max, date_min, time_min) else: best_match_under_conditions(site, minimum_odd, bet, sport, date_max, time_max, date_min, time_min, one_site) sys.stdout = old_stdout # Put the old stream back in place what_was_printed = buffer.getvalue() # contains the entire contents of the buffer. match, date = infos(what_was_printed) if match is None: window["MATCH_UNDER_CONDITION"].update("Aucun match trouvé") window["DELETE_MATCH_UNDER_CONDITION"].update(visible=False) window["DATE_UNDER_CONDITION"].update("") window["ODDS_UNDER_CONDITION"].update(visible=False) window["RESULT_UNDER_CONDITION"].update(visible=False) window["TEXT_UNDER_CONDITION"].update(visible=False) for i in range(5): window["INDICATORS_UNDER_CONDITION" + str(i)].update(visible=False) window["RESULTS_UNDER_CONDITION" + str(i)].update(visible=False) else: window["MATCH_UNDER_CONDITION"].update(match) window["DELETE_MATCH_UNDER_CONDITION"].update(visible=True) window["RELOAD_ODDS_UNDER_CONDITION"].update(visible=True) window["DATE_UNDER_CONDITION"].update(date) window["ODDS_UNDER_CONDITION"].update(odds_table(what_was_printed), visible=True) window["RESULT_UNDER_CONDITION"].update(stakes(what_was_printed), visible=True) window["TEXT_UNDER_CONDITION"].update(visible=True) for i, elem in enumerate(indicators(what_was_printed)): window["INDICATORS_UNDER_CONDITION" + str(i)].update(elem[0].capitalize(), visible=True) window["RESULTS_UNDER_CONDITION" + str(i)].update(elem[1], visible=True) buffer.close() except IndexError: pass except ValueError: pass
def test_under_condition(update_references=False): PATH_DATA_TEST = os.path.dirname(sb.__file__) + "/resources/data_test.json" sb.ODDS = load_odds(PATH_DATA_TEST) original_stdout = sys.stdout reached = os.path.dirname( sb.__file__) + "/tests/result_under_condition_1_reached.txt" expected = os.path.dirname( sb.__file__) + "/tests/result_under_condition_1_expected.txt" with open(expected if update_references else reached, "w", encoding="utf-8") as f: sys.stdout = f best_match_under_conditions("parionssport", 1.7, 10) sys.stdout = original_stdout assert (update_references or are_identical_files(expected, reached)) reached = os.path.dirname( sb.__file__) + "/tests/result_under_condition_2_reached.txt" expected = os.path.dirname( sb.__file__) + "/tests/result_under_condition_2_expected.txt" with open(expected if update_references else reached, "w", encoding="utf-8") as f: sys.stdout = f best_match_under_conditions("parionssport", 1.7, 10, date_min="23/11/2020") sys.stdout = original_stdout assert (update_references or are_identical_files(expected, reached)) reached = os.path.dirname( sb.__file__) + "/tests/result_under_condition_3_reached.txt" expected = os.path.dirname( sb.__file__) + "/tests/result_under_condition_3_expected.txt" with open(expected if update_references else reached, "w", encoding="utf-8") as f: sys.stdout = f best_match_under_conditions("parionssport", 1.7, 10, date_min="23/11/2020", date_max="29/11/2020") sys.stdout = original_stdout assert (update_references or are_identical_files(expected, reached))
def test_under_condition(): PATH_DATA_TEST = os.path.dirname( sb.__file__) + "/resources/data_test.pickle" sb.ODDS = pickle.load(open(PATH_DATA_TEST, "rb")) original_stdout = sys.stdout reached = os.path.dirname( sb.__file__) + "/tests/result_under_condition_1_reached.txt" expected = os.path.dirname( sb.__file__) + "/tests/result_under_condition_1_expected.txt" with open(reached, "w", encoding="utf-8") as f: sys.stdout = f best_match_under_conditions("parionssport", 1.7, 10) sys.stdout = original_stdout assert (are_identical_files(expected, reached)) reached = os.path.dirname( sb.__file__) + "/tests/result_under_condition_2_reached.txt" expected = os.path.dirname( sb.__file__) + "/tests/result_under_condition_2_expected.txt" with open(reached, "w", encoding="utf-8") as f: sys.stdout = f best_match_under_conditions("parionssport", 1.7, 10, date_min="23/11/2020") sys.stdout = original_stdout assert (are_identical_files(expected, reached)) reached = os.path.dirname( sb.__file__) + "/tests/result_under_condition_3_reached.txt" expected = os.path.dirname( sb.__file__) + "/tests/result_under_condition_3_expected.txt" with open(reached, "w", encoding="utf-8") as f: sys.stdout = f best_match_under_conditions("parionssport", 1.7, 10, date_min="23/11/2020", date_max="29/11/2020") sys.stdout = original_stdout assert (are_identical_files(expected, reached))