Spaces:
Sleeping
Sleeping
File size: 8,417 Bytes
78a2475 961cd54 78a2475 961cd54 78a2475 961cd54 78a2475 961cd54 78a2475 961cd54 abcdb15 961cd54 abcdb15 961cd54 abcdb15 961cd54 abcdb15 961cd54 abcdb15 961cd54 abcdb15 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | """Full-dependency smoke checks for the deployed application's Linux target."""
import math
import struct
import wave
from pathlib import Path
from PIL import Image
import pytest
import cv2
from Image_Processing.convert_and_display_grayscale import convert_and_display
from Image_Processing.resize_all_images_in_folder import resize_all_images_in_folder
from pypdf import PdfReader, PdfWriter
def test_poppler_pdf_conversion(tmp_path):
from File_Handling.convert_pdf_to_images import convert_pdf_to_images
source = tmp_path / "source.pdf"
writer = PdfWriter()
writer.add_blank_page(width=100, height=150)
with source.open("wb") as handle:
writer.write(handle)
images = convert_pdf_to_images(str(source))
assert len(images) == 1
assert isinstance(images[0], Image.Image)
assert images[0].width > 0
def test_libreoffice_docx_conversion(tmp_path):
from docx import Document
from File_Handling.convert_word_doc_to_pdf import convert_word_doc_to_pdf
source = tmp_path / "example.docx"
destination = tmp_path / "example.pdf"
document = Document()
document.add_paragraph("Smoke test for Word-to-PDF.")
document.save(source)
convert_word_doc_to_pdf(str(source), str(destination))
assert destination.is_file()
assert len(PdfReader(str(destination)).pages) >= 1
from File_Handling.convert_pdf_to_word import convert_pdf_to_word
restored = tmp_path / "roundtrip.docx"
convert_pdf_to_word(str(destination), str(restored))
assert restored.is_file()
assert restored.stat().st_size > 100
def test_speech_file_output(tmp_path):
from Audio_Speech_Processing.text_to_speech import text_to_speech
destination = tmp_path / "speech.wav"
text_to_speech("Testing speech generation.", output_path=str(destination))
assert destination.is_file()
assert destination.stat().st_size > 44
def test_pitch_analyser_returns_statistics(tmp_path):
from Audio_Speech_Processing.analyse_pitch import analyse_pitch
source = tmp_path / "tone.wav"
sample_rate = 22050
with wave.open(str(source), "wb") as output:
output.setnchannels(1)
output.setsampwidth(2)
output.setframerate(sample_rate)
frames = (
struct.pack("<h", int(10000 * math.sin(2 * math.pi * 220 * index / sample_rate)))
for index in range(sample_rate)
)
output.writeframes(b"".join(frames))
stats = analyse_pitch(str(source))
assert 175 <= stats["median_Hz"] <= 270
assert stats["duration_seconds"] == pytest.approx(1, abs=0.01)
def test_streamlit_all_navigation_pages():
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
assert not app.exception
pages = [
"Audio & Speech Processing",
"Automation & Productivity",
"File Handling",
"Git Utilities",
"Hugging Face Utilities",
"Image Processing",
"Jupyter Notebook Utilities",
"Regex Cheatsheet",
]
for page in pages:
app.sidebar.radio[0].set_value(page).run()
assert not app.exception, page
"""Smoke-check public Streamlit controls on the configured hosted runtime."""
def test_privileged_controls_are_disabled_on_public_dashboard(monkeypatch):
monkeypatch.delenv("ENABLE_LOCAL_OPERATIONS", raising=False)
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
assert not app.exception
protected = {
"Automation & Productivity": (
("website-status", "Check Status"),
("logging-setup", "Run Logging Setup"),
),
"File Handling": (
("disk-usage", "Check Disk Usage"),
("largest-file", "Find Largest File"),
("file-tree", "Generate Tree"),
),
"Git Utilities": (
("git-status", "Check Git Status"),
("github-repos", "Get Repos"),
),
"Hugging Face Utilities": (("hf-delete-folder", "Delete Folder"),),
}
for section, items in protected.items():
app.sidebar.radio[0].set_value(section).run()
assert not app.exception, section
for slug, label in items:
app.selectbox[0].set_value(slug).run()
assert not app.exception, (section, slug)
buttons = [button for button in app.button if button.label == label]
assert len(buttons) == 1, (section, slug, label)
assert buttons[0].disabled, (section, slug, label)
def test_greyscale_conversion_returns_pixels_without_gui(tmp_path):
source = tmp_path / "original.png"
output = tmp_path / "greyscale.png"
Image.new("RGB", (6, 4), (240, 60, 30)).save(source)
pixels = convert_and_display(str(source), str(output))
assert pixels.shape == (4, 6)
assert output.is_file()
saved = cv2.imread(str(output), cv2.IMREAD_GRAYSCALE)
assert saved.shape == pixels.shape
def test_bulk_resize_never_creates_zero_dimensions(tmp_path):
path = tmp_path / "tiny.png"
Image.new("RGB", (1, 1)).save(path)
result = resize_all_images_in_folder(str(tmp_path), 1)
assert str(path) in result
with Image.open(path) as image:
assert image.size == (1, 1)
def test_streamlit_regex_input_and_validation():
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
app.sidebar.radio[0].set_value("Regex Cheatsheet").run()
app.selectbox[0].set_value("validate-email").run()
assert not app.exception
app.text_input[0].set_value("bad@example..com").run()
next(button for button in app.button if button.label == "Validate").click().run()
assert not app.exception
assert len(app.error) == 1
def test_dashboard_home_search_and_tool_navigation():
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
assert not app.exception
assert app.sidebar.radio[0].value == "Overview"
app.text_input[0].set_value("PDF DOCX").run()
assert not app.exception
assert len([button for button in app.button if button.label == "Open tool"]) == 2
app.text_input[0].set_value("nonexistentcategorytool").run()
assert not app.exception
assert len([button for button in app.button if button.label == "Open tool"]) == 0
def test_workspace_selection_and_code_tab_render():
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
app.sidebar.radio[0].set_value("Regex Cheatsheet").run()
app.selectbox[0].set_value("extract-dates").run()
assert not app.exception
assert "extract-dates" == app.session_state["shelf_active_tool"]
def test_open_tool_from_search_and_favourites():
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
app.text_input[0].set_value("normalise spaces").run()
open_button = next(button for button in app.button if button.key == "open_all_remove-spaces")
open_button.click().run()
assert not app.exception
assert app.sidebar.radio[0].value == "Regex Cheatsheet"
assert app.session_state["shelf_active_tool"] == "remove-spaces"
favourite = next(button for button in app.button if button.label == "☆ Favourite")
favourite.click().run()
assert "remove-spaces" in app.session_state["shelf_favourites"]
def test_text_result_persists_after_tool_switch():
from streamlit.testing.v1 import AppTest
app = AppTest.from_file(Path(__file__).resolve().parents[1] / "app.py", default_timeout=45).run()
app.sidebar.radio[0].set_value("Regex Cheatsheet").run()
app.selectbox[0].set_value("upper-case").run()
next(button for button in app.button if button.label == "Capitalise").click().run()
assert not app.exception
saved = app.session_state["shelf_values"]["upper-case"]
assert "IMPORTANT DATES" in saved
app.selectbox[0].set_value("lower-case").run()
app.selectbox[0].set_value("upper-case").run()
assert not app.exception
assert app.session_state["shelf_values"]["upper-case"] == saved
|