Skip to content

Commit 33a4365

Browse files
committed
docs: fix docs build failure due to bad example code
1 parent 04fdf92 commit 33a4365

File tree

5 files changed

+63
-134
lines changed

5 files changed

+63
-134
lines changed

docs/modules/influxdb.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ pip install testcontainers[influxdb] influxdb-client
2020

2121
## Usage example
2222

23+
<!--codeinclude-->
24+
2325
[Creating an InfluxDB container](../../modules/influxdb/example_basic.py)
26+
27+
<!--/codeinclude-->

docs/modules/mssql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Testcontainers module for Microsoft SQL Server.
1111
Please run the following command to add the MSSQL module to your python dependencies:
1212

1313
```bash
14-
pip install testcontainers[mssql] sqlalchemy pymssql
14+
pip install testcontainers[mssql] pymssql
1515
```
1616

1717
## Usage example

docs/modules/mssql/example_basic.py

Lines changed: 0 additions & 50 deletions
This file was deleted.

modules/influxdb/example_basic.py

Lines changed: 55 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -44,92 +44,63 @@ def basic_example():
4444
query_api = client.query_api()
4545

4646
# Query data
47-
query = f'''
48-
from(bucket: "{bucket}")
49-
|> range(start: -1h)
50-
|> filter(fn: (r) => r["_measurement"] == "test_measurement")
51-
'''
47+
query = f'from(bucket: "{bucket}") |> range(start: -1h) |> filter(fn: (r) => r["_measurement"] == "test_measurement")'
5248

5349
result = query_api.query(query)
5450
print("\nQuery results:")
5551
for table in result:
5652
for record in table.records:
57-
print(
58-
json.dumps(
59-
{
60-
"measurement": record.get_measurement(),
61-
"time": record.get_time().isoformat(),
62-
"location": record.values.get("location"),
63-
"device": record.values.get("device"),
64-
"field": record.get_field(),
65-
"value": record.get_value(),
66-
},
67-
indent=2,
68-
)
69-
)
53+
record_data = {
54+
"measurement": record.get_measurement(),
55+
"time": record.get_time().isoformat(),
56+
"location": record.values.get("location"),
57+
"device": record.values.get("device"),
58+
"field": record.get_field(),
59+
"value": record.get_value(),
60+
}
61+
print(json.dumps(record_data, indent=2))
7062

7163
# Create aggregation query
72-
agg_query = f'''
73-
from(bucket: "{bucket}")
74-
|> range(start: -1h)
75-
|> filter(fn: (r) => r["_measurement"] == "test_measurement")
76-
|> group(columns: ["location"])
77-
|> mean()
78-
'''
64+
agg_query = f'from(bucket: "{bucket}") |> range(start: -1h) |> filter(fn: (r) => r["_measurement"] == "test_measurement") |> group(columns: ["location"]) |> mean()'
7965

8066
agg_result = query_api.query(agg_query)
8167
print("\nAggregation results:")
8268
for table in agg_result:
8369
for record in table.records:
84-
print(
85-
json.dumps(
86-
{
87-
"location": record.values.get("location"),
88-
"field": record.get_field(),
89-
"mean": record.get_value(),
90-
},
91-
indent=2,
92-
)
93-
)
70+
record_data = {
71+
"location": record.values.get("location"),
72+
"field": record.get_field(),
73+
"mean": record.get_value(),
74+
}
75+
print(json.dumps(record_data, indent=2))
9476

9577
# Create window query
96-
window_query = f'''
97-
from(bucket: "{bucket}")
98-
|> range(start: -1h)
99-
|> filter(fn: (r) => r["_measurement"] == "test_measurement")
100-
|> window(every: 5m)
101-
|> mean()
102-
'''
78+
window_query = f'from(bucket: "{bucket}") |> range(start: -1h) |> filter(fn: (r) => r["_measurement"] == "test_measurement") |> window(every: 5m) |> mean()'
10379

10480
window_result = query_api.query(window_query)
10581
print("\nWindow results:")
10682
for table in window_result:
10783
for record in table.records:
108-
print(
109-
json.dumps(
110-
{
111-
"window_start": record.get_start().isoformat(),
112-
"window_stop": record.get_stop().isoformat(),
113-
"field": record.get_field(),
114-
"mean": record.get_value(),
115-
},
116-
indent=2,
117-
)
118-
)
84+
record_data = {
85+
"window_start": record.get_start().isoformat(),
86+
"window_stop": record.get_stop().isoformat(),
87+
"field": record.get_field(),
88+
"mean": record.get_value(),
89+
}
90+
print(json.dumps(record_data, indent=2))
11991

12092
# Create task
121-
task_flux = f'''
122-
option task = {{
123-
name: "test_task",
124-
every: 1h
125-
}}
126-
127-
from(bucket: "{bucket}")
128-
|> range(start: -1h)
129-
|> filter(fn: (r) => r["_measurement"] == "test_measurement")
130-
|> mean()
131-
|> to(bucket: "{bucket}", measurement: "test_measurement_agg")
132-
'''
93+
task_flux = (
94+
"option task = {\n"
95+
' name: "test_task",\n'
96+
" every: 1h\n"
97+
"}\n\n"
98+
f'from(bucket: "{bucket}")\n'
99+
" |> range(start: -1h)\n"
100+
' |> filter(fn: (r) => r["_measurement"] == "test_measurement")\n'
101+
" |> mean()\n"
102+
f' |> to(bucket: "{bucket}", measurement: "test_measurement_agg")'
103+
)
133104

134105
tasks_api = client.tasks_api()
135106
task = tasks_api.create_task(name="test_task", flux=task_flux, org=org)
@@ -138,12 +109,13 @@ def basic_example():
138109
# Get task info
139110
task_info = tasks_api.find_task_by_id(task.id)
140111
print("\nTask info:")
141-
print(
142-
json.dumps(
143-
{"id": task_info.id, "name": task_info.name, "status": task_info.status, "every": task_info.every},
144-
indent=2,
145-
)
146-
)
112+
task_data = {
113+
"id": task_info.id,
114+
"name": task_info.name,
115+
"status": task_info.status,
116+
"every": task_info.every,
117+
}
118+
print(json.dumps(task_data, indent=2))
147119

148120
# Create dashboard
149121
dashboards_api = client.dashboards_api()
@@ -159,11 +131,12 @@ def basic_example():
159131
# Get dashboard info
160132
dashboard_info = dashboards_api.find_dashboard_by_id(dashboard.id)
161133
print("\nDashboard info:")
162-
print(
163-
json.dumps(
164-
{"id": dashboard_info.id, "name": dashboard_info.name, "cells": len(dashboard_info.cells)}, indent=2
165-
)
166-
)
134+
dashboard_data = {
135+
"id": dashboard_info.id,
136+
"name": dashboard_info.name,
137+
"cells": len(dashboard_info.cells),
138+
}
139+
print(json.dumps(dashboard_data, indent=2))
167140

168141
# Create bucket
169142
buckets_api = client.buckets_api()
@@ -173,7 +146,12 @@ def basic_example():
173146
# Get bucket info
174147
bucket_info = buckets_api.find_bucket_by_id(new_bucket.id)
175148
print("\nBucket info:")
176-
print(json.dumps({"id": bucket_info.id, "name": bucket_info.name, "org_id": bucket_info.org_id}, indent=2))
149+
bucket_data = {
150+
"id": bucket_info.id,
151+
"name": bucket_info.name,
152+
"org_id": bucket_info.org_id,
153+
}
154+
print(json.dumps(bucket_data, indent=2))
177155

178156
# Clean up
179157
tasks_api.delete_task(task.id)

modules/mssql/example_basic.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import pyodbc
1+
import pymssql
22

33
from testcontainers.mssql import MsSqlContainer
44

@@ -12,11 +12,8 @@ def basic_example():
1212
password = mssql.password
1313
database = mssql.database
1414

15-
# Create connection string
16-
conn_str = f"DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={host},{port};DATABASE={database};UID={username};PWD={password}"
17-
1815
# Connect to MSSQL
19-
connection = pyodbc.connect(conn_str)
16+
connection = pymssql.connect(server=host, port=port, user=username, password=password, database=database)
2017
print("Connected to MSSQL")
2118

2219
# Create cursor
@@ -40,7 +37,7 @@ def basic_example():
4037
cursor.executemany(
4138
"""
4239
INSERT INTO test_table (name, value, category)
43-
VALUES (?, ?, ?)
40+
VALUES (%s, %s, %s)
4441
""",
4542
test_data,
4643
)

0 commit comments

Comments
 (0)