Skip to content

Commit 197c2fc

Browse files
committed
Add pyproject.toml for pytest configuration and update background image references
- Introduced a new pyproject.toml file to configure pytest with specified options. - Changed background image references from JPEG to PNG format in the debloat_apply_background and debloat_download_scripts modules. - Removed deprecated background.jpg and spinner.gif files, replacing them with background.png. - Added new test files for configuration and download scripts to ensure functionality.
1 parent ad94a00 commit 197c2fc

9 files changed

Lines changed: 99 additions & 11 deletions

File tree

debloat_components/debloat_apply_background.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def main():
3838
components_dir = os.path.dirname(os.path.abspath(__file__))
3939
base_path = os.path.dirname(components_dir)
4040
media_dir = os.path.join(base_path, 'media')
41-
temp_wallpaper = os.path.join(tempfile.gettempdir(), "basilisk", "media", "background.jpg")
41+
temp_wallpaper = os.path.join(tempfile.gettempdir(), "basilisk", "media", "background.png")
4242
if os.path.exists(temp_wallpaper):
4343
wallpaper_path = temp_wallpaper
4444
else:
45-
wallpaper_path = get_resource_path('media/background.jpg')
45+
wallpaper_path = get_resource_path('media/background.png')
4646
logger.info(f"Setting desktop background: {wallpaper_path}")
4747
if not os.path.exists(wallpaper_path):
4848
msg = f"Wallpaper file not found: {wallpaper_path}"

debloat_components/debloat_download_scripts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
GITHUB_RAW_URL = f"https://raw.githubusercontent.com/ctrlcat0x/basilisk/master/scripts/"
1818

1919
MEDIA_FILES = [
20-
"background.jpg",
20+
"background.png",
2121
]
2222
MEDIA_DIR = os.path.join(tempfile.gettempdir(), 'basilisk', 'media')
2323
GITHUB_MEDIA_URL = "https://raw.githubusercontent.com/ctrlcat0x/basilisk/master/media/"

media/background.jpg

-499 KB
Binary file not shown.

media/background.png

8.4 MB
Loading

media/spinner.gif

-2.31 MB
Binary file not shown.

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[tool.pytest.ini_options]
2+
minversion = "7.0"
3+
addopts = "-q"
4+
testpaths = [
5+
"tests",
6+
]
7+
pythonpath = [
8+
".",
9+
"src",
10+
]
11+
12+

screens/screen_installing.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ def main():
5656
status_label.raise_()
5757
status_label.show()
5858
StatusResizer(overlay, status_label, bottom_margin=title_label._top_margin)
59-
spinner = QLabel(overlay)
60-
spinner.setAlignment(Qt.AlignmentFlag.AlignCenter)
61-
spinner.setStyleSheet("background: transparent;")
62-
spinner.setGeometry(overlay.width()//2 - 32, overlay.height()//2 + 100, 64, 64)
63-
movie = QMovie(os.path.join(os.path.dirname(__file__), '../media/spinner.gif'))
64-
spinner.setMovie(movie)
65-
movie.start()
66-
spinner.show()
6759
base.show()
6860

6961
def update_status(msg: str):

tests/test_config.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import json
2+
import os
3+
4+
5+
def test_default_config_exists_and_has_expected_keys():
6+
root = os.path.dirname(__file__)
7+
project_root = os.path.abspath(os.path.join(root, '..'))
8+
cfg_path = os.path.join(project_root, 'configs', 'default.json')
9+
assert os.path.exists(cfg_path), 'configs/default.json must exist'
10+
11+
# Use utf-8-sig to gracefully handle BOM if present
12+
with open(cfg_path, 'r', encoding='utf-8-sig') as f:
13+
data = json.load(f)
14+
15+
assert 'WPFFeature' in data and isinstance(data['WPFFeature'], list)
16+
assert 'WPFTweaks' in data and isinstance(data['WPFTweaks'], list)
17+
# minimal sanity: no duplicates
18+
assert len(set(data['WPFTweaks'])) == len(data['WPFTweaks'])
19+
20+

tests/test_downloads.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import tempfile
3+
import types
4+
import importlib
5+
import builtins
6+
7+
8+
def test_download_scripts_invokes_download(monkeypatch, tmp_path):
9+
module = importlib.import_module('debloat_components.debloat_download_scripts')
10+
11+
downloaded = {}
12+
13+
def fake_download(url, dest_name=None, dest_dir=None, retries=3):
14+
nonlocal downloaded
15+
downloaded[(url, dest_name, dest_dir)] = True
16+
# simulate writing a file
17+
if dest_dir and dest_name:
18+
os.makedirs(dest_dir, exist_ok=True)
19+
with open(os.path.join(dest_dir, dest_name), 'wb') as f:
20+
f.write(b'OK')
21+
return True
22+
23+
# ensure scripts do not exist so path goes to download
24+
monkeypatch.setattr(module, 'SCRIPTS_DIR', tmp_path.as_posix())
25+
monkeypatch.setattr(module, 'MEDIA_DIR', tmp_path.joinpath('media').as_posix())
26+
27+
# monkeypatch the function where it is used (module namespace) to avoid network
28+
monkeypatch.setattr(module, 'download_file', fake_download)
29+
# avoid opening error dialogs and exiting during tests
30+
monkeypatch.setattr(module, 'show_error_popup', lambda *a, **k: True)
31+
32+
# prevent sys.exit on failure paths
33+
monkeypatch.setattr(module, 'sys', types.SimpleNamespace(exit=lambda code: (_ for _ in ()).throw(AssertionError("sys.exit called"))))
34+
35+
module.main()
36+
37+
# Verify that at least one script and one media file were attempted
38+
assert any('scripts' in u for (u, _, _) in downloaded.keys())
39+
assert any('media' in u for (u, _, _) in downloaded.keys())
40+
41+
42+
def test_downloads_to_temp_basilisk_dir(monkeypatch, tmp_path):
43+
module = importlib.import_module('debloat_components.debloat_download_scripts')
44+
monkeypatch.setenv('TEMP', tmp_path.as_posix())
45+
46+
created_paths = []
47+
48+
def fake_download(url, dest_name=None, dest_dir=None, retries=3):
49+
created_paths.append(dest_dir)
50+
return True
51+
52+
monkeypatch.setattr(module, 'download_file', fake_download)
53+
monkeypatch.setattr(module, 'show_error_popup', lambda *a, **k: True)
54+
# Point both script and media dirs to a clean, test-specific location
55+
scripts_dir = tmp_path.joinpath('basilisk').as_posix()
56+
media_dir = tmp_path.joinpath('basilisk', 'media').as_posix()
57+
monkeypatch.setattr(module, 'SCRIPTS_DIR', scripts_dir)
58+
monkeypatch.setattr(module, 'MEDIA_DIR', media_dir)
59+
module.main()
60+
61+
assert scripts_dir in created_paths
62+
assert media_dir in created_paths
63+
64+

0 commit comments

Comments
 (0)