Skip to content

Commit aeeee97

Browse files
committed
Fix pytest
1 parent 43c040e commit aeeee97

6 files changed

Lines changed: 45 additions & 43 deletions

File tree

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ FROM python:3.9-slim
33
ENV PYTHONDONTWRITEBYTECODE=1
44
ENV PYTHONUNBUFFERED=1
55
ENV PYTHONPATH="${PYTHONPATH}:/app"
6-
76
WORKDIR /app
87

98
COPY requirements.txt .
@@ -21,5 +20,7 @@ COPY . .
2120

2221
EXPOSE 8501
2322

24-
CMD ["pytest", "-v", "app/tests/test_http.py", "app/tests/test_file.py", "app/tests/test_file_ext.py"]
23+
#RUN "pytest -v app/tests/test_http.py app/tests/test_file.py app/tests/test_file_ext.py" > logs.log
24+
25+
2526
CMD ["streamlit", "run", "app/main.py", "--server.port=8501", "--server.address=0.0.0.0"]

app/main.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Main giga kox file
22
import streamlit as st
3-
from tests import test_http, test_file, test_file_ext
43
import time
54
from src import FileProcessor, Summarizer
65
from config.settings import settings
@@ -10,9 +9,9 @@ def main():
109
st.session_state.tests_run = False
1110

1211
if not st.session_state.tests_run:
13-
test_http.test_port()
14-
test_file_ext.test_file_ext("manu.txt")
15-
test_file_ext.test_file_ext("manu.pdf")
12+
# test_http.test_port()
13+
# test_file_ext.test_file_ext("manu.txt")
14+
# test_file_ext.test_file_ext("manu.pdf")
1615
st.session_state.tests_run = True
1716

1817
st.title("Kaka - AI powered document summary")
@@ -25,7 +24,7 @@ def main():
2524
st.session_state.submitted = False
2625

2726
if file is not None and not st.session_state.submitted:
28-
test_file.test_file_name(file)
27+
# test_file.test_file_name(file)
2928
if st.button("Summarize"):
3029
st.session_state.submitted = True
3130
st.rerun()

app/src/file_processor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import streamlit as st
33
import os
44
from typing import Optional
5-
from tests import test_file_ext
5+
#from tests import test_file_ext
66

77
class FileProcessor:
88
def __init__(self):

app/tests/test_file.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from log import Logger
2+
import pytest
3+
#from ../main import main
4+
from ..src import FileProcessor, Summarizer
25

36
logger = Logger(__name__).get_logger()
47

5-
def test_file_name(file):
6-
try:
7-
if file is not None:
8-
logger.info(f"File name is: {file.name}")
9-
else:
10-
logger.error("There is an error in retrieving name")
11-
except Exception as e:
12-
logger.error(f"An error occurred: {e}")
8+
def test_file_name():
9+
file_procesor = FileProcessor()
10+
file_procesor.file = "manu.txt"
11+
#file_procesor.upload_file()
12+
ret = file_procesor.getFile()
13+
assert ret != None
14+

app/tests/test_file_ext.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
from log import Logger
22
import pytest
33
import os
4+
from src import FileProcessor
45

56
logger = Logger(__name__).get_logger()
67

7-
def test_file_ext(file_name: str) -> bool:
8-
supported_extensions = {".txt"}
8+
# def test_file_ext(file_name: str) -> bool:
9+
# supported_extensions = {".txt"}
910

10-
_, ext = os.path.splitext(file_name)
11+
# _, ext = os.path.splitext(file_name)
1112

12-
if any(file_name.endswith(ext) for ext in supported_extensions):
13-
logger.info(f"Type {ext} is supported")
14-
return True
15-
else:
16-
logger.error(f"Type {ext} isn't supported")
17-
return False
13+
# if any(file_name.endswith(ext) for ext in supported_extensions):
14+
# logger.info(f"Type {ext} is supported")
15+
# return True
16+
# else:
17+
# logger.error(f"Type {ext} isn't supported")
18+
# return False
1819

1920
@pytest.mark.parametrize("file_name, expected", [
20-
("image.jpeg", False),
21-
("document.pdf", False),
22-
("archive.zip", False),
23-
("notes.txt", True),
24-
("image.png", False),
21+
(".jpeg", False),
22+
(".pdf", False),
23+
(".zip", False),
24+
(".txt", True),
25+
(".png", False),
2526
])
2627

2728
def test_is_supported_file(file_name, expected):
2829
logger.info(f"Testing file: {file_name}")
29-
assert test_file_ext(file_name) == expected
30+
file_processor = FileProcessor()
31+
supp_files = file_processor.supported_types.keys()
32+
supp_files = list(supp_files)
33+
ret = file_name in supp_files
34+
assert ret == expected

app/tests/test_http.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import socket
22
from log import Logger
3+
import pytest
34

45
logger = Logger(__name__).get_logger()
56

67
def test_port():
78
logger.info("Testing socket")
8-
try:
9-
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
10-
s.settimeout(2)
11-
result = s.connect_ex(('127.0.0.1', 8501))
12-
if result == 0:
13-
logger.info("8501 is open")
14-
else:
15-
logger.error("8501 is closed")
16-
assert result == 0, "8501 is not available"
17-
except Exception as e:
18-
logger.exception(f"An error occured during the test {e}")
19-
raise
9+
s =socket.socket(socket.AF_INET, socket.SOCK_STREAM)
10+
s.settimeout(2)
11+
result = s.connect_ex(('127.0.0.1', 8501))
12+
13+
assert result == 0, "8501 is not available"
14+
logger.info("Socket test passed")

0 commit comments

Comments
 (0)