Files
doczyai-pipelines/fieldExtraction/tests/string_funcs_test.py
T
Alex Galarce 3740588efa Merged in refactor/daip-2-9-code-refactor (pull request #339)
Refactor/daip2-9 code refactor

* add missing import

* refactor ac_smart_chunking.py

* update tests

* removed old and unused imports

* removed outdated import

* forgot to import re

* refactor bottom up funcs

* remove unused imports from file_processing.py

* refactor dict_operations.py

* remove unused import from conditional_funcs.py

* replace top_down_funcs with one_to_n_funcs and remove top_down_funcs.py

* remove duplicate import from one_to_n_funcs.py

* refactor all utils.py imports

* refactor error handling by removing last code in utils and integrating InvalidDateException into postprocessing_funcs

* refactor import in claude_funcs.py to use string_funcs directly and (hopefully) resolve circular import

* refactor regex_funcs.py to use postprocessing_funcs for add_hyphen_if_needed calls

* refactor hotfix_helper_funcs.py to use postprocessing_funcs for add_hyphen_if_needed calls

* refactor postprocess.py to remove unused imports

* add numpy import to string_funcs

* fix tests after utils refactor

* move adhoc from tests to scripts

* remove unused imports

* remove scripts from mypy checking

* isort

* Merged main into refactor/daip-2-9-code-refactor


Approved-by: Katon Minhas
2025-01-06 15:39:29 +00:00

52 lines
2.8 KiB
Python

import pytest
from enums.delimiters import Delimiter
from string_funcs 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"