Skip to content

Commit

Permalink
[style] F-strings are not necessary if there is no placeholder (#2307)
Browse files Browse the repository at this point in the history
  • Loading branch information
vil02 authored Jan 27, 2025
1 parent 9ee336d commit 13a692f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions fixcore/tests/fixcore/cli/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async def test_create_query_parts(cli: CLI) -> None:
commands = await cli.evaluate_cli_command("search some_int==0 | aggregate foo, bla as bla: sum(bar) as a")
assert (
commands[0].executable_commands[0].arg
== f"'aggregate(reported.foo, reported.bla as bla: sum(reported.bar) as a):reported.some_int == 0 sort a asc'"
== "'aggregate(reported.foo, reported.bla as bla: sum(reported.bar) as a):reported.some_int == 0 sort a asc'"
)

# multiple head/tail commands are combined correctly
Expand All @@ -216,7 +216,7 @@ async def test_create_query_parts(cli: CLI) -> None:
commands = await cli.evaluate_cli_command("search is(volume) | tail -10")
assert (
commands[0].executable_commands[0].arg
== f"'is(\"volume\") sort reported.kind desc, reported.name desc, reported.id desc limit 10 reversed '"
== "'is(\"volume\") sort reported.kind desc, reported.name desc, reported.id desc limit 10 reversed '"
)
commands = await cli.evaluate_cli_command("search is(volume) sort name | tail -10 | head 5")
assert commands[0].executable_commands[0].arg == "'is(\"volume\") sort reported.name desc limit 5, 5 reversed '"
Expand Down
28 changes: 14 additions & 14 deletions fixcore/tests/fixcore/cli/command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,21 +1017,21 @@ async def test_pagerduty_alias(cli: CLI, echo_http_server: Tuple[int, List[Tuple
@pytest.mark.asyncio
async def test_welcome(cli: CLI) -> None:
ctx = CLIContext(console_renderer=ConsoleRenderer.default_renderer())
result = await cli.execute_cli_command(f"welcome", list_sink, ctx)
result = await cli.execute_cli_command("welcome", list_sink, ctx)
assert "Fix" in result[0][0]


@pytest.mark.asyncio
async def test_tip_of_the_day(cli: CLI) -> None:
ctx = CLIContext(console_renderer=ConsoleRenderer.default_renderer())
result = await cli.execute_cli_command(f"totd", list_sink, ctx)
result = await cli.execute_cli_command("totd", list_sink, ctx)
assert generic_tips[0].command_line in result[0][0]


@pytest.mark.asyncio
async def test_certificate(cli: CLI) -> None:
result = await cli.execute_cli_command(
f"certificate create --common-name foo.inventory.fix.security --dns-names bla --ip-addresses 1.2.3.4 --days-valid 1",
"certificate create --common-name foo.inventory.fix.security --dns-names bla --ip-addresses 1.2.3.4 --days-valid 1",
list_sink,
)
# will create 2 files
Expand All @@ -1054,14 +1054,14 @@ async def test_execute_task(cli: CLI) -> None:

# execute-task in source position
source_result = await cli.execute_cli_command(
f'execute-task --command success_task --arg "--foo bla test"', list_sink
'execute-task --command success_task --arg "--foo bla test"', list_sink
)
assert len(source_result[0]) == 1
assert source_result[0] == [{"result": "done!"}]

# execute task in flow position: every incoming node creates a new task
flow_result = await cli.execute_cli_command(
f'search all limit 3 | execute-task --command success_task --arg "--t {{id}}"', list_sink
'search all limit 3 | execute-task --command success_task --arg "--t {id}"', list_sink
)
assert len(flow_result[0]) == 3

Expand All @@ -1077,15 +1077,15 @@ async def history_count(cmd: str) -> int:
five_min_later = utc_str(now + timedelta(minutes=5))
assert await history_count("history") == 112 # 112 inserts for the filled graph db
assert await history_count(f"history --after {five_min_ago}") == 112
assert await history_count(f"history --after 5m") == 112
assert await history_count("history --after 5m") == 112
assert await history_count(f"history --after {five_min_later}") == 0
assert await history_count(f"history --before {five_min_ago}") == 0
assert await history_count(f"history --before 5m") == 0
assert await history_count(f"history --change node_created") == 112
assert await history_count(f"history --change node_updated") == 0
assert await history_count(f"history --change node_deleted") == 0
assert await history_count(f"history --change node_created --change node_updated --change node_deleted") == 112
assert await history_count(f"history is(foo)") == 10
assert await history_count("history --before 5m") == 0
assert await history_count("history --change node_created") == 112
assert await history_count("history --change node_updated") == 0
assert await history_count("history --change node_deleted") == 0
assert await history_count("history --change node_created --change node_updated --change node_deleted") == 112
assert await history_count("history is(foo)") == 10
# combine all selectors
assert await history_count(f"history --after 5m --before {five_min_later} --change node_created is(foo)") == 10

Expand Down Expand Up @@ -1429,12 +1429,12 @@ async def check(streamer: JsStream) -> None:

# search with aggregation does not export anything
with pytest.raises(Exception):
await sync_and_check(f"search all | aggregate kind:sum(1) | db sync sqlite --database foo")
await sync_and_check("search all | aggregate kind:sum(1) | db sync sqlite --database foo")

# define all parameters and check the connection string
with pytest.raises(Exception) as ex:
await sync_and_check(
f"db sync sqlite --database db --host bla --port 1234 --user test --password check --arg foo=bla foo2=bla2",
"db sync sqlite --database db --host bla --port 1234 --user test --password check --arg foo=bla foo2=bla2",
expected_table_count=11,
)
assert "sqlite://test:check@bla:1234" in str(ex.value)
Expand Down
10 changes: 5 additions & 5 deletions fixcore/tests/fixcore/dependencies_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def test_parse_override() -> None:
def parse(args: str) -> List[Tuple[str, JsonElement]]:
return parse_args(args.split()).config_override # type: ignore

assert parse(f"--override a=foo") == [("a", "foo")]
assert parse(f"--override a=foo,bla") == [("a", ["foo", "bla"])]
assert parse(f"--override a=foo,bla b=a,b,c") == [("a", ["foo", "bla"]), ("b", ["a", "b", "c"])]
assert parse(f'--override a="value,with,comma,in,quotes"') == [("a", "value,with,comma,in,quotes")]
assert parse(f'--override a=some,value,"with,comma"') == [("a", ["some", "value", "with,comma"])]
assert parse("--override a=foo") == [("a", "foo")]
assert parse("--override a=foo,bla") == [("a", ["foo", "bla"])]
assert parse("--override a=foo,bla b=a,b,c") == [("a", ["foo", "bla"]), ("b", ["a", "b", "c"])]
assert parse('--override a="value,with,comma,in,quotes"') == [("a", "value,with,comma,in,quotes")]
assert parse('--override a=some,value,"with,comma"') == [("a", ["some", "value", "with,comma"])]


class ExampleService(Service):
Expand Down
4 changes: 2 additions & 2 deletions fixcore/tests/fixcore/model/model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_datetime() -> None:
assert a.coerce_if_required("12mo").startswith("20") # type: ignore
with pytest.raises(Exception) as no_date:
a.check_valid("simply no date")
assert str(no_date.value) == f"Invalid isoformat string: 'simply no date'"
assert str(no_date.value) == "Invalid isoformat string: 'simply no date'"


def test_date() -> None:
Expand All @@ -199,7 +199,7 @@ def test_date() -> None:
assert a.coerce_if_required("12mo").startswith("20") # type: ignore
with pytest.raises(Exception) as no_date:
a.check_valid("simply no date")
assert str(no_date.value) == f"Invalid isoformat string: 'simply no date'"
assert str(no_date.value) == "Invalid isoformat string: 'simply no date'"


def test_dictionary() -> None:
Expand Down
18 changes: 9 additions & 9 deletions fixcore/tests/fixcore/web/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def update_model(self, update: List[Kind]) -> Model:
return model

async def list_graphs(self) -> Set[str]:
async with self.session.get(self.base_path + f"/graph") as response:
async with self.session.get(self.base_path + "/graph") as response:
return set(await response.json())

async def get_graph(self, name: str) -> Optional[AccessJson]:
Expand Down Expand Up @@ -179,7 +179,7 @@ async def search_aggregate(self, graph: str, search: str) -> List[AccessJson]:
raise AttributeError(await r.text())

async def subscribers(self) -> List[Subscriber]:
async with self.session.get(self.base_path + f"/subscribers") as r:
async with self.session.get(self.base_path + "/subscribers") as r:
if r.status == 200:
return from_js(await r.json(), List[Subscriber])
else:
Expand Down Expand Up @@ -235,7 +235,7 @@ async def delete_subscriber(self, uid: str) -> None:

async def cli_evaluate(self, graph: str, command: str, **env: str) -> List[Tuple[ParsedCommands, List[AccessJson]]]:
props = {"graph": graph, "section": "reported", **env}
async with self.session.post(self.base_path + f"/cli/evaluate", data=command, params=props) as r:
async with self.session.post(self.base_path + "/cli/evaluate", data=command, params=props) as r:
if r.status == 200:
return [
(
Expand All @@ -249,21 +249,21 @@ async def cli_evaluate(self, graph: str, command: str, **env: str) -> List[Tuple

async def cli_execute(self, graph: str, command: str, **env: str) -> List[JsonElement]:
props = {"graph": graph, "section": "reported", **env}
async with self.session.post(self.base_path + f"/cli/execute", data=command, params=props) as r:
async with self.session.post(self.base_path + "/cli/execute", data=command, params=props) as r:
if r.status == 200:
return AccessJson.wrap_list(await r.json()) # type: ignore
else:
raise AttributeError(await r.text())

async def cli_info(self) -> AccessJson:
async with self.session.get(self.base_path + f"/cli/info") as r:
async with self.session.get(self.base_path + "/cli/info") as r:
if r.status == 200:
return AccessJson.wrap_object(await r.json())
else:
raise AttributeError(await r.text())

async def configs(self) -> List[str]:
async with self.session.get(self.base_path + f"/configs") as r:
async with self.session.get(self.base_path + "/configs") as r:
if r.status == 200:
return AccessJson.wrap_list(await r.json()) # type: ignore
else:
Expand Down Expand Up @@ -299,7 +299,7 @@ async def delete_config(self, config_id: str) -> None:
raise AttributeError(await r.text())

async def get_configs_model(self) -> Model:
async with self.session.get(self.base_path + f"/configs/model") as r:
async with self.session.get(self.base_path + "/configs/model") as r:
if r.status == 200:
model_json = await r.json()
model = Model.from_kinds([from_js(kind, Kind) for kind in model_json["kinds"].values()]) # type: ignore
Expand All @@ -326,14 +326,14 @@ async def put_config_validation(self, cfg: ConfigValidation) -> ConfigValidation
return from_js(await response.json(), ConfigValidation)

async def ping(self) -> str:
async with self.session.get(self.base_path + f"/system/ping") as r:
async with self.session.get(self.base_path + "/system/ping") as r:
if r.status == 200:
return await r.text()
else:
raise AttributeError(await r.text())

async def ready(self) -> str:
async with self.session.get(self.base_path + f"/system/ready") as r:
async with self.session.get(self.base_path + "/system/ready") as r:
if r.status == 200:
return await r.text()
else:
Expand Down
2 changes: 1 addition & 1 deletion fixcore/tests/fixcore/web/api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ async def create_core_client(
"--no-scheduling",
"--ignore-interrupted-tasks",
"--override",
f"fixcore.api.https_port=null",
"fixcore.api.https_port=null",
f"fixcore.api.http_port={http_port}",
"fixcore.api.web_hosts=0.0.0.0",
"fixcore.graph.use_view=false",
Expand Down
4 changes: 2 additions & 2 deletions fixcore/tools/grapher.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def node(level, identity, replace: bool = False, kind: Optional[str] = None):
reported["kind"] = kind
metadata = {"level": level}
metadata = metadata | {"replace": True} if replace else metadata
desired = {"name": f"some cool name", "age": 29}
desired = {"name": "some cool name", "age": 29}
js = {"id": identity, "reported": reported, "metadata": metadata, "desired": desired}
# replace flag is now on metadata level
# js = js | {"replace": True} if replace else js
Expand All @@ -57,7 +57,7 @@ def edge(from_node, to_node, edge_type):
print(json.dumps({"from": from_node, "to": to_node, "edge_type": edge_type}))


root = f"root"
root = "root"
collector_root = f"{collector}_root"
node(0, root, kind="graph_root")
node(0, collector_root, replace=True, kind="cloud")
Expand Down
6 changes: 3 additions & 3 deletions fixcore/tools/render_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
from pathlib import Path
import shlex
except ImportError:
print(f"Can't import one or more modules. Is fix dev environment activated?")
print(f"Hint: see https://inventory.fix.security/docs/contributing/components for more info.")
print("Can't import one or more modules. Is fix dev environment activated?")
print("Hint: see https://inventory.fix.security/docs/contributing/components for more info.")
exit(1)

JsonElement = Union[str, int, float, bool, None, Mapping[str, Any], Sequence[Any]]
Expand Down Expand Up @@ -221,7 +221,7 @@ def send_analytics(run_id: str, event: str):
client.api_key = api_key
for consumer in client.consumers:
consumer.api_key = api_key
system_id = f"dot-rendering-script"
system_id = "dot-rendering-script"
now = utc()
client.identify(system_id, {"run_id": run_id, "created_at": now})
client.capture(
Expand Down

0 comments on commit 13a692f

Please sign in to comment.