generated from streamlit/chatbot-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into jeromehardaway/update-code
- Loading branch information
Showing
21 changed files
with
134 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[run] | ||
omit = | ||
tests/* | ||
*/tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run Unit Tests with Pytest | ||
|
||
on: [ push, pull_request ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests with coverage report | ||
run: | | ||
pytest --cov --cov-report=term-missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ __pycache__/ | |
# C extensions | ||
*.so | ||
|
||
.DS_Store | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ tiktoken>=0.5.1 | |
cachetools>=5.3.2 | ||
dataclasses-json>=0.6.1 | ||
asyncio>=3.4.3 | ||
aiohttp>=3.9.1 | ||
aiohttp>=3.9.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import io | ||
import pytest | ||
import os | ||
|
||
TEST_RESOURCE_DIR = f"{os.path.dirname(__file__)}/resources" | ||
|
||
|
||
def load_resource_file(file_name): | ||
with open(file_name, "rb") as file: | ||
data = io.BytesIO(file.read()) | ||
return data | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def file_resources(): | ||
library = {} | ||
for filename in os.listdir(TEST_RESOURCE_DIR): | ||
library[filename.split(".")[0]] = load_resource_file(f"{TEST_RESOURCE_DIR}/{filename}") | ||
yield library | ||
|
||
|
||
def pytest_configure(config): | ||
config.addinivalue_line( | ||
"markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')" | ||
) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from streamlit_app import extract_text_from_pdf, extract_text_from_word | ||
import pytest | ||
|
||
|
||
class TestDOCXExtraction: | ||
def test_extract_text_from_word_with_only_text(self, file_resources): | ||
assert extract_text_from_word(file_resources["docx_text_only"]) == "This document has text!" | ||
|
||
def test_extract_text_from_word_with_empty_file(self, file_resources): | ||
assert extract_text_from_word(file_resources["docx_blank"]) == "" | ||
|
||
def test_extract_text_from_word_with_non_text_contents(self, file_resources): | ||
assert extract_text_from_word(file_resources["docx_text_and_media"]) == "This document has text!" | ||
|
||
def test_extract_text_from_word_with_special_characters(self, file_resources): | ||
assert extract_text_from_word(file_resources["docx_unicode_sample"]) | ||
|
||
|
||
class TestPDFExtraction: | ||
def test_extract_text_from_pdf_with_only_text(self, file_resources): | ||
assert extract_text_from_pdf(file_resources["pdf_text_only"]) == "This document has text!" | ||
|
||
def test_extract_text_from_pdf_with_empty_file(self, file_resources): | ||
assert extract_text_from_pdf(file_resources["pdf_blank"]) == "" | ||
|
||
def test_extract_text_from_pdf_with_non_text_contents(self, file_resources): | ||
# PyPDF2 will pull the text from charts also, so we cannot use == to compare | ||
assert "This document has text!" in extract_text_from_pdf(file_resources["pdf_text_and_media"]) | ||
|
||
@pytest.mark.slow | ||
def test_extract_text_from_pdf_with_special_characters(self, file_resources): | ||
assert extract_text_from_pdf(file_resources["pdf_unicode_sample"]) |