From 644827fc414ac369a4427b1972adfbb16a00860f Mon Sep 17 00:00:00 2001 From: Mark Grey Date: Mon, 29 Apr 2024 14:47:21 -0400 Subject: [PATCH] tox format routine --- flask_mab/__init__.py | 5 ++++- tests/test_app.py | 6 +++--- tests/test_app_factory.py | 4 +++- tests/test_blueprints.py | 4 +++- tox.ini | 5 +++++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/flask_mab/__init__.py b/flask_mab/__init__.py index 49159a7..42346c5 100644 --- a/flask_mab/__init__.py +++ b/flask_mab/__init__.py @@ -163,7 +163,10 @@ def persist_bandits(response): @app.after_request def remember_bandit_arms(response): if request.bandits_save: - for bandit_id, (arm, _), in request.bandits.items(): + for ( + bandit_id, + (arm, _), + ) in request.bandits.items(): # hook event for saving an impression here app.extensions["mab"].bandits[bandit_id].pull_arm(arm) diff --git a/tests/test_app.py b/tests/test_app.py index f8d74e9..af9ce9c 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -61,9 +61,9 @@ def test_suggest_decorated(self): def test_from_cookie_reward_decorated(self): first_req = self.app_client.get("/show_btn_decorated") assert "X-MAB-Debug" in first_req.headers.keys() - chosen_arm, _ = json.loads(parse_cookie(first_req.headers["Set-Cookie"])["MAB"])[ - "color_button" - ] + chosen_arm, _ = json.loads( + parse_cookie(first_req.headers["Set-Cookie"])["MAB"] + )["color_button"] self.app_client.get("/reward_decorated") assert ( self.app.extensions["mab"].bandits["color_button"][chosen_arm]["reward"] > 0 diff --git a/tests/test_app_factory.py b/tests/test_app_factory.py index 87c44fc..2b47ed9 100644 --- a/tests/test_app_factory.py +++ b/tests/test_app_factory.py @@ -70,7 +70,9 @@ def test_suggest_decorated(self): > 0 ) assert ( - json.loads(parse_cookie(rv.headers["Set-Cookie"])["MAB"])[self.name_to_test][0] + json.loads(parse_cookie(rv.headers["Set-Cookie"])["MAB"])[ + self.name_to_test + ][0] == chosen_arm ) diff --git a/tests/test_blueprints.py b/tests/test_blueprints.py index 78bf04b..caddef0 100644 --- a/tests/test_blueprints.py +++ b/tests/test_blueprints.py @@ -70,7 +70,9 @@ def test_improper_configuration(self): rv = app_client.get("/") with self.assertRaises(MABConfigException): - app_client.set_cookie("MAB", '{"some_bandit": ["blue", true]}', domain="localhost") + app_client.set_cookie( + "MAB", '{"some_bandit": ["blue", true]}', domain="localhost" + ) app_client.get("/reward") def get_arm(self, headers): diff --git a/tox.ini b/tox.ini index 3f1ff6f..ce9a775 100644 --- a/tox.ini +++ b/tox.ini @@ -15,3 +15,8 @@ commands = pytest tests deps = .[dev] commands = black --check flask_mab tests + +[testenv:format] +deps = + .[dev] +commands = black flask_mab tests