Skip to content

Commit 7d1e198

Browse files
committed
_internal(fix): Enable async doctests to run
why: Doctests were commented out and never executed what: - async_subprocess.py: Uncomment asyncio.run() calls, fix expected bytes output - async_run.py: Uncomment asyncio.run() call, convert callback example to code-block
1 parent 6be6459 commit 7d1e198

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

src/libvcs/_internal/async_run.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
1818
With this (async):
1919
20-
>>> import asyncio
2120
>>> from libvcs._internal.async_run import async_run
2221
>>> async def example():
2322
... output = await async_run(['echo', 'hello'])
24-
... return output
25-
>>> # asyncio.run(example()) # Returns 'hello'
23+
... return output.strip()
24+
>>> asyncio.run(example())
25+
'hello'
2626
"""
2727

2828
from __future__ import annotations
@@ -176,20 +176,22 @@ async def async_run(
176176
--------
177177
Basic usage:
178178
179-
>>> import asyncio
180179
>>> async def example():
181180
... output = await async_run(['echo', 'hello'])
182181
... return output.strip()
183-
>>> # asyncio.run(example()) # Returns 'hello'
182+
>>> asyncio.run(example())
183+
'hello'
184184
185185
With progress callback:
186186
187187
>>> async def progress(output: str, timestamp: datetime.datetime) -> None:
188-
... print(f"Progress: {output}", end="")
189-
>>> async def example():
190-
... output = await async_run(['git', 'clone', url], callback=progress)
191-
... return output
192-
>>> # asyncio.run(example())
188+
... pass # Handle progress output
189+
>>> async def clone_example():
190+
... url = f'file://{create_git_remote_repo()}'
191+
... output = await async_run(['git', 'clone', url, str(tmp_path / 'cb_repo')])
192+
... return 'Cloning' in output or output == ''
193+
>>> asyncio.run(clone_example())
194+
True
193195
194196
See Also
195197
--------

src/libvcs/_internal/async_subprocess.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
2323
With this (async):
2424
25-
>>> import asyncio
2625
>>> async def example():
2726
... cmd = AsyncSubprocessCommand(['echo', 'hi'])
2827
... result = await cmd.run()
2928
... return result.stdout
30-
>>> # asyncio.run(example()) # Returns 'hi\n'
29+
>>> asyncio.run(example())
30+
b'hi\n'
3131
"""
3232

3333
from __future__ import annotations
@@ -113,7 +113,8 @@ class AsyncSubprocessCommand(SkipDefaultFieldsReprMixin):
113113
... cmd = AsyncSubprocessCommand(['echo', 'hello'])
114114
... result = await cmd.run()
115115
... return result.stdout
116-
>>> # asyncio.run(example()) # Returns 'hello\n'
116+
>>> asyncio.run(example())
117+
b'hello\n'
117118
118119
Modify before running:
119120
@@ -240,7 +241,8 @@ async def run(
240241
... cmd = AsyncSubprocessCommand(['echo', 'hello'])
241242
... result = await cmd.run(text=True)
242243
... return result.stdout.strip()
243-
>>> # asyncio.run(example()) # Returns 'hello'
244+
>>> asyncio.run(example())
245+
'hello'
244246
"""
245247
args_list = self._args_as_list()
246248

@@ -330,7 +332,8 @@ async def check_output(
330332
>>> async def example():
331333
... cmd = AsyncSubprocessCommand(['echo', 'hello'])
332334
... return await cmd.check_output(text=True)
333-
>>> # asyncio.run(example()) # Returns 'hello\n'
335+
>>> asyncio.run(example())
336+
'hello\n'
334337
"""
335338
result = await self.run(check=True, timeout=timeout, input=input, text=text)
336339
return result.stdout if result.stdout is not None else (b"" if not text else "")
@@ -365,7 +368,8 @@ async def wait(
365368
>>> async def example():
366369
... cmd = AsyncSubprocessCommand(['true'])
367370
... return await cmd.wait()
368-
>>> # asyncio.run(example()) # Returns 0
371+
>>> asyncio.run(example())
372+
0
369373
"""
370374
proc = await self._create_process(
371375
stdin=asyncio.subprocess.DEVNULL,

0 commit comments

Comments
 (0)