mirror of
https://github.com/microsoft/autogen.git
synced 2026-05-13 03:00:55 -04:00
Extact_code can detect single-line code now (#2)
* Extact_code can detect single-line code now * Add comments for RE * Add test case and adjust UNKNOWN behavior * Remove tmp test files * Update autogen/code_utils.py --------- Co-authored-by: Chi Wang <wang.chi@microsoft.com>
This commit is contained in:
@@ -161,10 +161,23 @@ Example:
|
||||
```
|
||||
print("hello extract code")
|
||||
```
|
||||
"""
|
||||
""",
|
||||
detect_single_line_code=False,
|
||||
)
|
||||
print(codeblocks)
|
||||
|
||||
codeblocks2 = extract_code(
|
||||
"""
|
||||
Example:
|
||||
```
|
||||
print("hello extract code")
|
||||
```
|
||||
""",
|
||||
detect_single_line_code=True,
|
||||
)
|
||||
assert codeblocks2 == codeblocks
|
||||
# import pdb; pdb.set_trace()
|
||||
|
||||
codeblocks = extract_code(
|
||||
"""
|
||||
Example:
|
||||
@@ -190,6 +203,15 @@ print(f"Text: {text}")
|
||||
codeblocks = extract_code("no code block")
|
||||
assert len(codeblocks) == 1 and codeblocks[0] == (UNKNOWN, "no code block")
|
||||
|
||||
# Disable single line code detection
|
||||
line = "Run `source setup.sh` from terminal"
|
||||
codeblocks = extract_code(line, detect_single_line_code=False)
|
||||
assert len(codeblocks) == 1 and codeblocks[0] == (UNKNOWN, line)
|
||||
|
||||
# Enable single line code detection
|
||||
codeblocks = extract_code("Run `source setup.sh` from terminal", detect_single_line_code=True)
|
||||
assert len(codeblocks) == 1 and codeblocks[0] == ("", "source setup.sh")
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.platform in ["darwin", "win32"],
|
||||
|
||||
Reference in New Issue
Block a user