Skip to content

Commit 768ca4a

Browse files
committed
Merge branch 'main' of github.com:yassun7010/turu-py into fix_ci
2 parents dd6aa92 + 09986d9 commit 768ca4a

File tree

10 files changed

+91
-54
lines changed

10 files changed

+91
-54
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ Your Production Code
109109
import os
110110

111111
import turu.sqlite3
112-
from turu.core.record import record_as_csv
112+
from turu.core.record import record_to_csv
113113

114114
from your_package.data import RECORD_DIR
115115
from your_package.schema import Row
116116

117117

118118
def do_something(connection: turu.sqlite3.Connection):
119-
with record_as_csv(
119+
with record_to_csv(
120120
RECORD_DIR / "test.csv",
121121
connection.execute_map(Row, "select 1, 'a'"),
122122
enable=os.environ.get("ENABLE_RECORDING"),

docs/API_documentation/_core.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# turu.core
22

3-
::: turu.core.record.record_as_csv
3+
::: turu.core.record.record_to_csv
44

55
::: turu.core.record.CsvRecorderOptions

docs/data/turu_recording_and_testing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import turu.sqlite3
44
from pydantic import BaseModel
5-
from turu.core.record import record_as_csv
5+
from turu.core.record import record_to_csv
66

77

88
class Row(BaseModel):
@@ -12,7 +12,7 @@ class Row(BaseModel):
1212

1313
# Production code
1414
def do_something(connection: turu.sqlite3.Connection):
15-
with record_as_csv(
15+
with record_to_csv(
1616
"test.csv",
1717
connection.execute_map(Row, "select 1, 'a'"),
1818
enable=os.environ.get("ENABLE_RECORDING"),

docs/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_do_something():
4141

4242
## Recording & Testing
4343

44-
In the production code, the actual rows can be recorded to a csv file using the `record_as_csv` method.
44+
In the production code, the actual rows can be recorded to a csv file using the `record_to_csv` method.
4545

4646
Recording on/off can be controlled with the `enable` option (default is `True`).
4747

turu-core/src/turu/core/record/__init__.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
from turu.core.record.async_record_cursor import AsyncRecordCursor
1414
from turu.core.record.csv_recorder import CsvRecorder, CsvRecorderOptions
1515
from turu.core.record.record_cursor import RecordCursor
16-
from typing_extensions import Unpack
16+
from typing_extensions import Unpack, deprecated
1717

1818

1919
@overload
20-
def record_as_csv(
20+
def record_to_csv(
2121
record_filepath: Union[str, Path],
2222
cursor: turu.core.cursor.GenericCursor,
2323
*,
@@ -28,7 +28,7 @@ def record_as_csv(
2828

2929

3030
@overload
31-
def record_as_csv(
31+
def record_to_csv(
3232
record_filepath: Union[str, Path],
3333
cursor: turu.core.async_cursor.GenericAsyncCursor,
3434
*,
@@ -38,7 +38,7 @@ def record_as_csv(
3838
...
3939

4040

41-
def record_as_csv( # type: ignore
41+
def record_to_csv( # type: ignore
4242
record_filepath: Union[str, Path],
4343
cursor: Union[
4444
turu.core.cursor.GenericCursor, turu.core.async_cursor.GenericAsyncCursor
@@ -57,20 +57,20 @@ def record_as_csv( # type: ignore
5757
"""
5858
if isinstance(cursor, turu.core.cursor.Cursor):
5959
return _GeneratorContextManager(
60-
_record_as_csv, (record_filepath, cursor), dict(enable=enable, **options)
60+
_record_to_csv, (record_filepath, cursor), dict(enable=enable, **options)
6161
)
6262

6363
elif isinstance(cursor, turu.core.async_cursor.AsyncCursor):
6464
return _AsyncGeneratorContextManager(
65-
_record_as_csv_async,
65+
_record_to_csv_async,
6666
(record_filepath, cursor),
6767
dict(enable=enable, **options),
6868
)
6969

7070
raise NotImplementedError(f"cursor type {type(cursor)} is not supported")
7171

7272

73-
def _record_as_csv(
73+
def _record_to_csv(
7474
record_filepath: Union[str, Path],
7575
cursor: turu.core.cursor.GenericCursor,
7676
*,
@@ -97,7 +97,7 @@ def _record_as_csv(
9797
cursor.close()
9898

9999

100-
async def _record_as_csv_async(
100+
async def _record_to_csv_async(
101101
record_filepath: Union[str, Path],
102102
cursor: turu.core.async_cursor.GenericAsyncCursor,
103103
*,
@@ -122,3 +122,40 @@ async def _record_as_csv_async(
122122

123123
finally:
124124
await cursor.close()
125+
126+
127+
@overload
128+
def record_as_csv(
129+
record_filepath: Union[str, Path],
130+
cursor: turu.core.cursor.GenericCursor,
131+
*,
132+
enable: Union[str, bool, None] = True,
133+
**options: Unpack[CsvRecorderOptions],
134+
) -> "_GeneratorContextManager[turu.core.cursor.GenericCursor]":
135+
...
136+
137+
138+
@overload
139+
def record_as_csv(
140+
record_filepath: Union[str, Path],
141+
cursor: turu.core.async_cursor.GenericAsyncCursor,
142+
*,
143+
enable: Union[str, bool, None] = True,
144+
**options: Unpack[CsvRecorderOptions],
145+
) -> _AsyncGeneratorContextManager[turu.core.async_cursor.GenericAsyncCursor]:
146+
...
147+
148+
149+
@deprecated(
150+
"This function is deprecated. Use `record_to_csv` instead.",
151+
)
152+
def record_as_csv( # type: ignore
153+
record_filepath: Union[str, Path],
154+
cursor: Union[
155+
turu.core.cursor.GenericCursor, turu.core.async_cursor.GenericAsyncCursor
156+
],
157+
*,
158+
enable: Union[str, bool, None] = True,
159+
**options: Unpack[CsvRecorderOptions],
160+
):
161+
return record_to_csv(record_filepath, cursor, enable=enable, **options)

turu-core/tests/turu/core/test_record.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import turu.core.mock
88
from pydantic import BaseModel
99
from turu.core.exception import TuruRowTypeNotSupportedError
10-
from turu.core.record import RecordCursor, record_as_csv
10+
from turu.core.record import RecordCursor, record_to_csv
1111
from typing_extensions import Never
1212

1313

@@ -17,30 +17,30 @@ class RowPydantic(BaseModel):
1717

1818

1919
class TestRecord:
20-
def test_record_as_csv_execute_tuple(
20+
def test_record_to_csv_execute_tuple(
2121
self, mock_connection: turu.core.mock.MockConnection
2222
):
2323
expected = [(i, f"name{i}") for i in range(5)]
2424
mock_connection.inject_response(None, expected)
2525

2626
with tempfile.NamedTemporaryFile() as file:
2727
with pytest.raises(TuruRowTypeNotSupportedError):
28-
with record_as_csv(
28+
with record_to_csv(
2929
file.name,
3030
mock_connection.execute("select 1 as ID, 'taro' as NAME"),
3131
) as cursor:
3232
assert cursor.fetchall() == expected
3333

3434
assert Path(file.name).read_text() == ""
3535

36-
def test_record_as_csv_execute_tuple_without_header(
36+
def test_record_to_csv_execute_tuple_without_header(
3737
self, mock_connection: turu.core.mock.MockConnection
3838
):
3939
expected = [(i, f"name{i}") for i in range(5)]
4040
mock_connection.inject_response(None, expected)
4141

4242
with tempfile.NamedTemporaryFile() as file:
43-
with record_as_csv(
43+
with record_to_csv(
4444
file.name,
4545
mock_connection.execute("select 1, 'taro"),
4646
header=False,
@@ -60,14 +60,14 @@ def test_record_as_csv_execute_tuple_without_header(
6060
).lstrip()
6161
)
6262

63-
def test_record_as_csv_execute_map(
63+
def test_record_to_csv_execute_map(
6464
self, mock_connection: turu.core.mock.MockConnection
6565
):
6666
expected = [RowPydantic(id=i, name=f"name{i}") for i in range(5)]
6767
mock_connection.inject_response(RowPydantic, expected)
6868

6969
with tempfile.NamedTemporaryFile() as file:
70-
with record_as_csv(
70+
with record_to_csv(
7171
file.name,
7272
mock_connection.execute_map(RowPydantic, "select 1, 'name"),
7373
) as cursor:
@@ -87,14 +87,14 @@ def test_record_as_csv_execute_map(
8787
).lstrip()
8888
)
8989

90-
def test_record_as_csv_execute_map_without_header_options(
90+
def test_record_to_csv_execute_map_without_header_options(
9191
self, mock_connection: turu.core.mock.MockConnection
9292
):
9393
expected = [RowPydantic(id=i, name=f"name{i}") for i in range(5)]
9494
mock_connection.inject_response(RowPydantic, expected)
9595

9696
with tempfile.NamedTemporaryFile() as file:
97-
with record_as_csv(
97+
with record_to_csv(
9898
file.name,
9999
mock_connection.execute_map(RowPydantic, "select 1, 'name"),
100100
header=False,
@@ -114,14 +114,14 @@ def test_record_as_csv_execute_map_without_header_options(
114114
).lstrip()
115115
)
116116

117-
def test_record_as_csv_execute_map_with_limit_options(
117+
def test_record_to_csv_execute_map_with_limit_options(
118118
self, mock_connection: turu.core.mock.MockConnection
119119
):
120120
expected = [RowPydantic(id=i, name=f"name{i}") for i in range(5)]
121121
mock_connection.inject_response(RowPydantic, expected)
122122

123123
with tempfile.NamedTemporaryFile() as file:
124-
with record_as_csv(
124+
with record_to_csv(
125125
file.name,
126126
mock_connection.execute_map(RowPydantic, "select 1, 'name"),
127127
limit=3,
@@ -141,7 +141,7 @@ def test_record_as_csv_execute_map_with_limit_options(
141141
)
142142

143143
@pytest.mark.parametrize("enable", ["true", True])
144-
def test_record_as_csv_execute_map_with_enable_options(
144+
def test_record_to_csv_execute_map_with_enable_options(
145145
self,
146146
mock_connection: turu.core.mock.MockConnection,
147147
enable: Literal["true", True],
@@ -150,7 +150,7 @@ def test_record_as_csv_execute_map_with_enable_options(
150150
mock_connection.inject_response(RowPydantic, expected)
151151

152152
with tempfile.NamedTemporaryFile() as file:
153-
with record_as_csv(
153+
with record_to_csv(
154154
file.name,
155155
mock_connection.execute_map(RowPydantic, "select 1, 'name"),
156156
enable=enable,
@@ -173,7 +173,7 @@ def test_record_as_csv_execute_map_with_enable_options(
173173
)
174174

175175
@pytest.mark.parametrize("enable", ["false", False, None])
176-
def test_record_as_csv_execute_map_with_disable_options(
176+
def test_record_to_csv_execute_map_with_disable_options(
177177
self,
178178
mock_connection: turu.core.mock.MockConnection,
179179
enable: Literal["false", False, None],
@@ -182,7 +182,7 @@ def test_record_as_csv_execute_map_with_disable_options(
182182
mock_connection.inject_response(RowPydantic, expected)
183183

184184
with tempfile.NamedTemporaryFile() as file:
185-
with record_as_csv(
185+
with record_to_csv(
186186
file.name,
187187
mock_connection.execute_map(RowPydantic, "select 1, 'name"),
188188
enable=enable,
@@ -191,7 +191,7 @@ def test_record_as_csv_execute_map_with_disable_options(
191191

192192
assert Path(file.name).read_text() == ""
193193

194-
def test_record_as_csv_use_custom_method(self):
194+
def test_record_to_csv_use_custom_method(self):
195195
class CustomCursor(turu.core.mock.MockCursor[Never, Any]):
196196
def custom_method(self, value: int) -> None:
197197
pass
@@ -204,7 +204,7 @@ def custom_method(self, value: int) -> None:
204204
pass
205205

206206
with tempfile.NamedTemporaryFile() as file:
207-
with record_as_csv(
207+
with record_to_csv(
208208
file.name,
209209
CustomConnection().cursor(),
210210
) as cursor:

0 commit comments

Comments
 (0)