Skip to content

Commit 33014e4

Browse files
committed
Use f-strings throughout.
1 parent 23e93b2 commit 33014e4

File tree

9 files changed

+22
-30
lines changed

9 files changed

+22
-30
lines changed

compose/testcontainers/compose/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class DockerCompose:
3636
host = compose.get_service_host("hub", 4444)
3737
port = compose.get_service_port("hub", 4444)
3838
driver = webdriver.Remote(
39-
command_executor=("http://{}:{}/wd/hub".format(host,port)),
39+
command_executor=(f"http://{host}:{port}/wd/hub"),
4040
desired_capabilities=CHROME,
4141
)
4242
driver.get("http://automation-remarks.com")
4343
stdout, stderr = compose.get_logs()
4444
if stderr:
45-
print("Errors\\n:{}".format(stderr))
45+
print(f"Errors\\n:{stderr}")
4646
4747
.. code-block:: yaml
4848

core/testcontainers/core/generic.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ def _create_connection_url(self, dialect: str, username: str, password: str,
4444
raise ContainerStartException("container has not been started")
4545
host = host or self.get_container_host_ip()
4646
port = self.get_exposed_port(port)
47-
url = "{dialect}://{username}:{password}@{host}:{port}".format(
48-
dialect=dialect, username=username, password=password, host=host, port=port
49-
)
47+
url = f"{dialect}://{username}:{password}@{host}:{port}"
5048
if db_name:
51-
url += '/' + db_name
49+
url = f"{url}/{db_name}"
5250
return url
5351

5452
def start(self) -> 'DbContainer':

elasticsearch/testcontainers/elasticsearch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _connect(self) -> None:
9393
def get_url(self) -> str:
9494
host = self.get_container_host_ip()
9595
port = self.get_exposed_port(self.port_to_expose)
96-
return 'http://{}:{}'.format(host, port)
96+
return f'http://{host}:{port}'
9797

9898
def start(self) -> "ElasticSearchContainer":
9999
super().start()

google/testcontainers/google/pubsub.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ def __init__(self, image: str = "google/cloud-sdk:emulators", project: str = "te
4242
self.project = project
4343
self.port = port
4444
self.with_exposed_ports(self.port)
45-
self.with_command("gcloud beta emulators pubsub start --project="
46-
"{project} --host-port=0.0.0.0:{port}".format(
47-
project=self.project, port=self.port,
48-
))
45+
self.with_command(
46+
f"gcloud beta emulators pubsub start --project={project} --host-port=0.0.0.0:{port}"
47+
)
4948

5049
def get_pubsub_emulator_host(self) -> str:
51-
return "{host}:{port}".format(host=self.get_container_host_ip(),
52-
port=self.get_exposed_port(self.port))
50+
return f"{self.get_container_host_ip()}:{self.get_exposed_port(self.port)}"
5351

5452
def _get_channel(self, channel: Optional[grpc.Channel] = None) -> grpc.Channel:
5553
if channel is None:

kafka/testcontainers/kafka/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, image: str = "confluentinc/cp-kafka:5.4.3", port_to_expose: i
3030
super(KafkaContainer, self).__init__(image, **kwargs)
3131
self.port_to_expose = port_to_expose
3232
self.with_exposed_ports(self.port_to_expose)
33-
listeners = 'PLAINTEXT://0.0.0.0:{},BROKER://0.0.0.0:9092'.format(port_to_expose)
33+
listeners = f'PLAINTEXT://0.0.0.0:{port_to_expose},BROKER://0.0.0.0:9092'
3434
self.with_env('KAFKA_LISTENERS', listeners)
3535
self.with_env('KAFKA_LISTENER_SECURITY_PROTOCOL_MAP',
3636
'BROKER:PLAINTEXT,PLAINTEXT:PLAINTEXT')
@@ -45,7 +45,7 @@ def __init__(self, image: str = "confluentinc/cp-kafka:5.4.3", port_to_expose: i
4545
def get_bootstrap_server(self) -> str:
4646
host = self.get_container_host_ip()
4747
port = self.get_exposed_port(self.port_to_expose)
48-
return '{}:{}'.format(host, port)
48+
return f'{host}:{port}'
4949

5050
@wait_container_is_ready(UnrecognizedBrokerVersion, NoBrokersAvailable, KafkaError, ValueError)
5151
def _connect(self) -> None:
@@ -57,21 +57,21 @@ def _connect(self) -> None:
5757
def tc_start(self) -> None:
5858
host = self.get_container_host_ip()
5959
port = self.get_exposed_port(self.port_to_expose)
60-
listeners = 'PLAINTEXT://{}:{},BROKER://$(hostname -i):9092'.format(host, port)
60+
listeners = f'PLAINTEXT://{host}:{port},BROKER://$(hostname -i):9092'
6161
data = (
6262
dedent(
63-
"""
63+
f"""
6464
#!/bin/bash
6565
echo 'clientPort=2181' > zookeeper.properties
6666
echo 'dataDir=/var/lib/zookeeper/data' >> zookeeper.properties
6767
echo 'dataLogDir=/var/lib/zookeeper/log' >> zookeeper.properties
6868
zookeeper-server-start zookeeper.properties &
6969
export KAFKA_ZOOKEEPER_CONNECT='localhost:2181'
70-
export KAFKA_ADVERTISED_LISTENERS={}
70+
export KAFKA_ADVERTISED_LISTENERS={listeners}
7171
. /etc/confluent/docker/bash-config
7272
/etc/confluent/docker/configure
7373
/etc/confluent/docker/launch
74-
""".format(listeners)
74+
"""
7575
)
7676
.strip()
7777
.encode('utf-8')
@@ -80,7 +80,7 @@ def tc_start(self) -> None:
8080

8181
def start(self) -> "KafkaContainer":
8282
script = KafkaContainer.TC_START_SCRIPT
83-
command = 'sh -c "while [ ! -f {} ]; do sleep 0.1; done; sh {}"'.format(script, script)
83+
command = f'sh -c "while [ ! -f {script} ]; do sleep 0.1; done; sh {script}"'
8484
self.with_command(command)
8585
super().start()
8686
self.tc_start()

keycloak/testcontainers/keycloak/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def _configure(self) -> None:
4848
def get_url(self) -> str:
4949
host = self.get_container_host_ip()
5050
port = self.get_exposed_port(self.port_to_expose)
51-
return "http://{}:{}".format(host, port)
51+
return f"http://{host}:{port}"
5252

5353
@wait_container_is_ready(requests.exceptions.ConnectionError, requests.exceptions.ReadTimeout)
5454
def _connect(self) -> None:
5555
url = self.get_url()
56-
response = requests.get("{}/auth".format(url), timeout=1)
56+
response = requests.get(f"{url}/auth", timeout=1)
5757
response.raise_for_status()
5858

5959
def start(self) -> "KeycloakContainer":
@@ -64,7 +64,7 @@ def start(self) -> "KeycloakContainer":
6464

6565
def get_client(self, **kwargs) -> KeycloakAdmin:
6666
default_kwargs = dict(
67-
server_url="{}/auth/".format(self.get_url()),
67+
server_url=f"{self.get_url()}/auth/",
6868
username=self.username,
6969
password=self.password,
7070
realm_name="master",

localstack/testcontainers/localstack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_url(self) -> str:
6262
"""
6363
host = self.get_container_host_ip()
6464
port = self.get_exposed_port(self.edge_port)
65-
return 'http://{}:{}'.format(host, port)
65+
return f'http://{host}:{port}'
6666

6767
def start(self, timeout: float = 60) -> "LocalStackContainer":
6868
super().start()

neo4j/testcontainers/neo4j/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ def _configure(self) -> None:
5050
self.with_env("NEO4J_AUTH", f"neo4j/{self.password}")
5151

5252
def get_connection_url(self) -> str:
53-
return "{dialect}://{host}:{port}".format(
54-
dialect="bolt",
55-
host=self.get_container_host_ip(),
56-
port=self.get_exposed_port(self.bolt_port),
57-
)
53+
return f"bolt://{self.get_container_host_ip()}:{self.get_exposed_port(self.bolt_port)}"
5854

5955
@wait_container_is_ready()
6056
def _connect(self) -> None:

postgres/testcontainers/postgres/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def _configure(self) -> None:
6060

6161
def get_connection_url(self, host=None) -> str:
6262
return super()._create_connection_url(
63-
dialect="postgresql+{}".format(self.driver), username=self.username,
63+
dialect=f"postgresql+{self.driver}", username=self.username,
6464
password=self.password, db_name=self.dbname, host=host,
6565
port=self.port_to_expose,
6666
)

0 commit comments

Comments
 (0)