53b38ea15c
Refactor/split investment and client * refactor: clean up tests * Renamed tests/qcqa to tests/qa_qc for consistency * comment out faulty test - see docstring note at top * split to client/investment * add __init__.py to investment and client to avoid mypy confusion * fix imports * update imports for consistency across investment module * move back to one config * try changing import to relative * add init.py to src * try relative import * try one more sys.path.append * fix path for client main * fix imports in file_processing * make prompts common * move keywords out to `src` * move smart_chunking_funcs to `src` * fix mypy error * start moving to explicit imports * remove old keywords and fix imports for keywords and prompts * change all imports to full paths * fix unit tests * add readme for new way of running things * isort after all that import work * remove unused sys.path.append from some tests Approved-by: Katon Minhas
53 lines
2.8 KiB
Python
53 lines
2.8 KiB
Python
import pytest
|
|
|
|
from src.enums.delimiters import Delimiter
|
|
from src.utils.string_utils import extract_text_from_delimiters
|
|
|
|
|
|
class TestExtractTextFromDelimiters:
|
|
# Test case for valid inputs
|
|
|
|
def test_pipe_delimiter_match_first_position(self):
|
|
raw_text = "Here is the answer |this is a pipe answer| and |more text.|"
|
|
result = extract_text_from_delimiters(raw_text,delimiter=Delimiter.PIPE,match_index=0)
|
|
assert result == "this is a pipe answer"
|
|
|
|
def test_pipe_delimiter_match_last_position(self):
|
|
raw_text = "Here is the answer |this is a pipe answer| and |more text.|"
|
|
result = extract_text_from_delimiters(raw_text,delimiter=Delimiter.PIPE,match_index=-1)
|
|
assert result == "more text."
|
|
|
|
def test_pipe_delimiter_match_any_position(self):
|
|
raw_text = "|Here| is the answer |this is a pipe answer| and |more text.|"
|
|
result = extract_text_from_delimiters(raw_text,delimiter=Delimiter.PIPE,match_index=1)
|
|
assert result == "this is a pipe answer"
|
|
|
|
def test_backtick_delimiter_match_first_position(self):
|
|
raw_text = "Here is the answer `this is a backtick answer` and `more text.`"
|
|
result = extract_text_from_delimiters(raw_text, delimiter=Delimiter.BACKTICK, match_index=0)
|
|
assert result == "this is a backtick answer"
|
|
|
|
def test_backtick_delimiter_match_last_position(self):
|
|
raw_text = "Here is the answer `this is a backtick answer` and `more text.`"
|
|
result = extract_text_from_delimiters(raw_text, delimiter=Delimiter.BACKTICK, match_index=-1)
|
|
assert result == "more text."
|
|
|
|
def test_backtick_delimiter_match_any_position(self):
|
|
raw_text = "`Here` is the answer `this` is a `backtick answer` and `more text.`"
|
|
result = extract_text_from_delimiters(raw_text, delimiter=Delimiter.BACKTICK, match_index=2)
|
|
assert result == "backtick answer"
|
|
|
|
def test_triple_backtick_delimiter_match_first_position(self):
|
|
raw_text = "Here is the answer ```this is a triple backtick answer``` and more text."
|
|
result = extract_text_from_delimiters(raw_text, delimiter=Delimiter.TRIPLE_BACKTICK, match_index=0)
|
|
assert result == "this is a triple backtick answer"
|
|
|
|
def test_triple_backtick_delimiter_match_last_position(self):
|
|
raw_text = "Here is the answer ```this``` is a ```triple``` backtick ```answer``` and more text."
|
|
result = extract_text_from_delimiters(raw_text, delimiter=Delimiter.TRIPLE_BACKTICK, match_index=-1)
|
|
assert result == "answer"
|
|
|
|
def test_triple_backtick_delimiter_match_any_position(self):
|
|
raw_text = "```Here``` is the answer ```this is a triple backtick answer``` and ```more text.```"
|
|
result = extract_text_from_delimiters(raw_text, delimiter=Delimiter.TRIPLE_BACKTICK, match_index=1)
|
|
assert result == "this is a triple backtick answer" |