Skip to content

Commit

Permalink
Format with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
olzhasar-reef committed May 5, 2024
1 parent e79abc9 commit 09dbcd9
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
12 changes: 3 additions & 9 deletions app/src/bittensor_panel/core/bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def get_subtensor() -> bittensor.subtensor:
try:
return bittensor.subtensor(settings.SUBTENSOR_ADDRESS)
except (SystemExit, Exception) as e:
raise SubtensorConnectionError(
f"Failed to connect to subtensor at: {settings.SUBTENSOR_ADDRESS}"
) from e
raise SubtensorConnectionError(f"Failed to connect to subtensor at: {settings.SUBTENSOR_ADDRESS}") from e


def get_wallet() -> bittensor.wallet:
Expand All @@ -32,9 +30,7 @@ def load_hyperparams() -> dict[str, int] | None:
try:
hyperparams = st.get_subnet_hyperparameters(settings.SUBNET_UID)
except Exception as e:
raise SubtensorServerError(
f"Failed to load hyperparameters from subtensor\n{e}"
) from e
raise SubtensorServerError(f"Failed to load hyperparameters from subtensor\n{e}") from e

if not hyperparams:
return None
Expand All @@ -57,6 +53,4 @@ def update_remote_hyperparam(name: str, value: int) -> bool:
prompt=False,
)
except Exception as exc:
raise SubtensorServerError(
f"Failed to update hyperparameter in subtensor\n{exc}"
) from exc
raise SubtensorServerError(f"Failed to update hyperparameter in subtensor\n{exc}") from exc
8 changes: 2 additions & 6 deletions app/src/bittensor_panel/core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def update_hyperparam(instance: HyperParameter) -> None:
result = update_remote_hyperparam(instance.name, instance.value)

if not result:
raise HyperParameterUpdateFailed(
"Failed to update remote hyperparameter. Subtensor returned False."
)
raise HyperParameterUpdateFailed("Failed to update remote hyperparameter. Subtensor returned False.")

instance.save(update_fields=["value"])

Expand All @@ -33,6 +31,4 @@ def refresh_hyperparams() -> None:
for name, value in hyperparam_dict.items():
objs.append(HyperParameter(name=name, value=value))

HyperParameter.objects.bulk_create(
objs, update_conflicts=True, update_fields=["value"], unique_fields=["name"]
)
HyperParameter.objects.bulk_create(objs, update_conflicts=True, update_fields=["value"], unique_fields=["name"])
8 changes: 2 additions & 6 deletions app/src/bittensor_panel/core/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def mock_refresh_hyperparams(mocker: MockerFixture):
return mocker.patch("bittensor_panel.core.admin.refresh_hyperparams")


def test_refresh_hyperparams_view(
admin_client: Client, mock_refresh_hyperparams: MagicMock
):
def test_refresh_hyperparams_view(admin_client: Client, mock_refresh_hyperparams: MagicMock):
response = admin_client.post("/admin/core/hyperparameter/refresh-hyperparams/")

mock_refresh_hyperparams.assert_called_once()
Expand All @@ -23,9 +21,7 @@ def test_refresh_hyperparams_view(
assert response.url == "/admin/core/hyperparameter/"


def test_refresh_hyperparams_view_exception(
admin_client: Client, mock_refresh_hyperparams: MagicMock
):
def test_refresh_hyperparams_view_exception(admin_client: Client, mock_refresh_hyperparams: MagicMock):
mock_refresh_hyperparams.side_effect = SubtensorConnectionError

response = admin_client.post("/admin/core/hyperparameter/refresh-hyperparams/")
Expand Down
8 changes: 2 additions & 6 deletions app/src/bittensor_panel/core/tests/test_bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def mock_wallet(mocker: MockerFixture):


@pytest.mark.parametrize("result", [True, False])
def test_update_remote_hyperparam(
mock_subtensor: MagicMock, mock_wallet: MagicMock, result: bool, settings
):
def test_update_remote_hyperparam(mock_subtensor: MagicMock, mock_wallet: MagicMock, result: bool, settings):
mock_subtensor.return_value.set_hyperparameter.return_value = result

name = "difficulty"
Expand All @@ -136,9 +134,7 @@ def test_update_remote_hyperparam(
)


def test_update_remote_hyperparam_exception(
mock_subtensor: MagicMock, mock_wallet: MagicMock
):
def test_update_remote_hyperparam_exception(mock_subtensor: MagicMock, mock_wallet: MagicMock):
mock_subtensor.return_value.set_hyperparameter.side_effect = RuntimeError

with pytest.raises(SubtensorServerError):
Expand Down
4 changes: 1 addition & 3 deletions app/src/bittensor_panel/core/tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def hyperparam_dict(faker: Faker):

@pytest.fixture
def mock_load_hyperparams(mocker: MockerFixture, hyperparam_dict: dict[str, int]):
return mocker.patch(
"bittensor_panel.core.services.load_hyperparams", return_value=hyperparam_dict
)
return mocker.patch("bittensor_panel.core.services.load_hyperparams", return_value=hyperparam_dict)


def test_refresh_hyperparams(
Expand Down

0 comments on commit 09dbcd9

Please sign in to comment.