Skip to content

Commit

Permalink
tox format routine
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaconDesperado committed Apr 29, 2024
1 parent 10a89b7 commit 644827f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
5 changes: 4 additions & 1 deletion flask_mab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion tests/test_app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ commands = pytest tests
deps =
.[dev]
commands = black --check flask_mab tests

[testenv:format]
deps =
.[dev]
commands = black flask_mab tests

0 comments on commit 644827f

Please sign in to comment.