Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor pyupdate improvements #440

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions agent/testflinger_agent/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import tarfile
import tempfile
import uuid
from unittest.mock import patch

import requests_mock as rmock
import pytest

from mock import patch

import testflinger_agent
from testflinger_agent.config import ATTACHMENTS_DIR
from testflinger_agent.errors import TFServerError
Expand Down
2 changes: 1 addition & 1 deletion agent/testflinger_agent/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import json
import pytest
import uuid
from unittest.mock import patch

from mock import patch
import requests_mock as rmock

from testflinger_agent.client import TestflingerClient as _TestflingerClient
Expand Down
1 change: 0 additions & 1 deletion agent/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ skipsdist = true
deps =
black
flake8
mock
pytest
pylint
pytest-mock
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_version():
version = pkg_resources.get_distribution("testflinger").version
except pkg_resources.DistributionNotFound:
version = "devel"
return "Testflinger Server v{}".format(version)
return f"Testflinger Server v{version}"


@v1.post("/job")
Expand Down Expand Up @@ -699,7 +699,7 @@ def job_position_get(job_id):
try:
queue = job_data.json.get("job_queue")
except (AttributeError, TypeError):
return "Invalid json returned for id: {}\n".format(job_id), 400
return f"Invalid json returned for id: {job_id}\n", 400
# Get all jobs with job_queue=queue and return only the _id
jobs = database.mongo.db.jobs.find(
{"job_data.job_queue": queue, "result_data.job_state": "waiting"},
Expand Down
4 changes: 2 additions & 2 deletions server/src/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def create_flask_app(config=None):
@tf_app.errorhandler(NotFound)
def handle_404(exc):
tf_log.error("[404] Not found: %s", request.url)
return "Not found: {}\n".format(exc), 404
return f"Not found: {exc}\n", 404

@tf_app.errorhandler(ConnectionFailure)
def handle_timeout(exc):
Expand All @@ -80,7 +80,7 @@ def handle_timeout(exc):
@tf_app.errorhandler(Exception)
def unhandled_exception(exc):
tf_log.exception("Unhandled Exception: %s", (exc))
return "Unhandled Exception: {}\n".format(exc), 500
return f"Unhandled Exception: {exc}\n", 500

tf_app.register_blueprint(views)
tf_app.register_blueprint(v1, url_prefix="/v1")
Expand Down
12 changes: 6 additions & 6 deletions server/tests/test_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def test_initial_job_state(mongo_app):
# Place a job on the queue
output = app.post("/v1/job", json=job_data)
job_id = output.json.get("job_id")
result_url = "/v1/result/{}".format(job_id)
result_url = f"/v1/result/{job_id}"
response = app.get(result_url)
assert "waiting" == response.json.get("job_state")

Expand All @@ -175,7 +175,7 @@ def test_resubmit_job_state(mongo_app):
job_id = output.json.get("job_id")
job_data["job_id"] = job_id
output = app.post("/v1/job", json=job_data)
result_url = "/v1/result/{}".format(job_id)
result_url = f"/v1/result/{job_id}"
updated_data = app.get(result_url).json
assert "waiting" == updated_data.get("job_state")

Expand Down Expand Up @@ -345,7 +345,7 @@ def test_job_get_id_with_data(mongo_app):
# Place a job on the queue
output = app.post("/v1/job", json=job_data)
job_id = output.json.get("job_id")
job_url = "/v1/job/{}".format(job_id)
job_url = f"/v1/job/{job_id}"
# Request the original json for the job
app.get(job_url)
output = app.get(job_url)
Expand All @@ -365,7 +365,7 @@ def test_job_position(mongo_app):
for pos in range(3):
output = app.post("/v1/job", json=job_data)
job_id.append(output.json.get("job_id"))
output = app.get("/v1/job/{}/position".format(job_id[pos]))
output = app.get(f"/v1/job/{job_id[pos]}/position")
# Initial position should increment for each job as we add them
assert output.text == str(pos)

Expand All @@ -374,11 +374,11 @@ def test_job_position(mongo_app):
# The job we get should be the first one that was added
assert output.json.get("job_id") == job_id[0]
# The position of the remaining jobs should decrement
assert app.get("/v1/job/{}/position".format(job_id[2])).text == "1"
assert app.get(f"/v1/job/{job_id[2]}/position").text == "1"
# Cancel the next job in the queue
output = app.post(f"/v1/job/{job_id[1]}/action", json={"action": "cancel"})
# The position of the remaining job should decrement again
assert app.get("/v1/job/{}/position".format(job_id[2])).text == "0"
assert app.get(f"/v1/job/{job_id[2]}/position").text == "0"


def test_action_post(mongo_app):
Expand Down
2 changes: 1 addition & 1 deletion server/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

from datetime import datetime
import re
from unittest.mock import patch
import mongomock
from mock import patch
from src.views import job_detail, queues_data, agent_detail


Expand Down
2 changes: 0 additions & 2 deletions server/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ deps =
black
flake8
pylint
mock
mongomock
pytest
pytest-mock
pytest-cov
requests
requests-mock
Expand Down