-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for
App.install_files
.
- Loading branch information
1 parent
fd66c05
commit b1212a1
Showing
5 changed files
with
208 additions
and
0 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,75 @@ | ||
from pathlib import Path | ||
|
||
from _pytest.monkeypatch import MonkeyPatch | ||
|
||
from antares_web_installer.app import App | ||
|
||
|
||
class TestApp: | ||
def test_run(self) -> None: | ||
assert False | ||
|
||
def test_kill_running_server(self) -> None: | ||
# 1. Lancer un serveur | ||
# 2. Appeler la méthode kill_running_server | ||
# 3. Vérifier que le serveur a bien été tué | ||
assert False | ||
|
||
def test_install_files__from_scratch(self, tmp_path: Path) -> None: | ||
""" | ||
Case where the target directory does not exist. | ||
""" | ||
# Prepare the test resources | ||
source_dir = tmp_path / "source" | ||
source_dir.mkdir() | ||
target_dir = tmp_path / "target" | ||
|
||
# Say we have dummy files in the source directory | ||
expected_files = ["dummy.txt", "folder/dummy2.txt"] | ||
for name in expected_files: | ||
dummy_file = source_dir / name | ||
dummy_file.parent.mkdir(parents=True, exist_ok=True) | ||
dummy_file.touch() | ||
|
||
# Run the test | ||
app = App(source_dir=source_dir, target_dir=target_dir) | ||
app.install_files() | ||
|
||
# Check the results | ||
for name in expected_files: | ||
assert (target_dir / name).exists(), f"File {name} must be copied" | ||
|
||
def test_install_files__update_config(self, datadir: Path, monkeypatch: MonkeyPatch) -> None: | ||
# Replace the original `check_version` method with a mock | ||
monkeypatch.setattr(App, "check_version", lambda _: "2.14") | ||
|
||
# Prepare the test resources | ||
source_dir = datadir.joinpath("install_files/source_files") | ||
target_dir = datadir.joinpath("install_files/target_files") | ||
old_config = (target_dir / "config.yaml").read_text() | ||
|
||
app = App(source_dir=source_dir, target_dir=target_dir) | ||
app.install_files() | ||
|
||
# Check that `dummy.txt` has been copied | ||
assert (target_dir / "dummy.txt").exists() | ||
|
||
# Check that the config file has been updated | ||
new_config = (target_dir / "config.yaml").read_text() | ||
assert old_config != new_config | ||
|
||
def test_copy_files(self) -> None: | ||
assert False | ||
|
||
def test_check_version(self, tmp_path: Path) -> None: | ||
# 3 cas à tester : | ||
# 1. Le programme exécutable n'existe pas => InstallError | ||
# 2. Le programme exécutable existe, mais le programme plante => InstallError | ||
# 3. Le programme exécutable existe et fonctionne => pas d'erreur | ||
assert False | ||
|
||
def test_create_icons(self) -> None: | ||
assert False | ||
|
||
def test_start_server(self) -> None: | ||
assert False |
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,6 @@ | ||
This directory contains the resources for the `test_app` test. | ||
|
||
This directory contains one folder for each test case: | ||
|
||
- `install_files`: Contains the files that are used for source_dir and target_dir | ||
... |
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,66 @@ | ||
security: | ||
disabled: false | ||
jwt: | ||
key: super-secret | ||
login: | ||
admin: | ||
pwd: admin | ||
|
||
db: | ||
url: "sqlite:////home/john/antares_data/database.db" | ||
|
||
storage: | ||
tmp_dir: /tmp | ||
matrixstore: /home/john/antares_data/matrices | ||
archive_dir: /home/john/antares_data/archives | ||
allow_deletion: false | ||
workspaces: | ||
default: | ||
path: /home/john/antares_data/internal_studies/ | ||
studies: | ||
path: /home/john/antares_data/studies/ | ||
|
||
launcher: | ||
default: slurm | ||
local: | ||
binaries: | ||
850: /home/john/opt/antares-8.5.0-Ubuntu-20.04/antares-solver | ||
860: /home/john/opt/antares-8.6.0-Ubuntu-20.04/antares-8.6-solver | ||
enable_nb_cores_detection: True | ||
|
||
slurm: | ||
local_workspace: /home/john/antares_data/slurm_workspace | ||
|
||
username: antares | ||
hostname: slurm-prod-01 | ||
|
||
port: 22 | ||
private_key_file: /home/john/.ssh/id_rsa | ||
key_password: | ||
default_wait_time: 900 | ||
default_time_limit: 172800 | ||
enable_nb_cores_detection: False | ||
nb_cores: | ||
min: 1 | ||
default: 20 | ||
max: 24 | ||
default_json_db_name: launcher_db.json | ||
slurm_script_path: /applis/antares/launchAntares.sh | ||
db_primary_key: name | ||
antares_versions_on_remote_server: | ||
- '850' # 8.5.1/antares-8.5-solver | ||
- '860' # 8.6.2/antares-8.6-solver | ||
- '870' # 8.7.0/antares-8.7-solver | ||
|
||
debug: false | ||
|
||
root_path: "" | ||
|
||
server: | ||
worker_threadpool_size: 12 | ||
services: | ||
- watcher | ||
- matrix_gc | ||
|
||
logging: | ||
level: INFO |
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,61 @@ | ||
security: | ||
disabled: false | ||
jwt: | ||
key: super-secret | ||
login: | ||
admin: | ||
pwd: admin | ||
|
||
db: | ||
url: "sqlite:////home/john/antares_data/database.db" | ||
|
||
storage: | ||
tmp_dir: /tmp | ||
matrixstore: /home/john/antares_data/matrices | ||
archive_dir: /home/john/antares_data/archives | ||
allow_deletion: false | ||
workspaces: | ||
default: | ||
path: /home/john/antares_data/internal_studies/ | ||
studies: | ||
path: /home/john/antares_data/studies/ | ||
|
||
launcher: | ||
default: slurm | ||
local: | ||
binaries: | ||
850: /home/john/opt/antares-8.5.0-Ubuntu-20.04/antares-solver | ||
860: /home/john/opt/antares-8.6.0-Ubuntu-20.04/antares-8.6-solver | ||
|
||
slurm: | ||
local_workspace: /home/john/antares_data/slurm_workspace | ||
|
||
username: antares | ||
hostname: slurm-prod-01 | ||
|
||
port: 22 | ||
private_key_file: /home/john/.ssh/id_rsa | ||
key_password: | ||
default_wait_time: 900 | ||
default_time_limit: 172800 | ||
default_n_cpu: 12 | ||
default_json_db_name: launcher_db.json | ||
slurm_script_path: /applis/antares/launchAntares.sh | ||
db_primary_key: name | ||
antares_versions_on_remote_server: | ||
- '850' # 8.5.1/antares-8.5-solver | ||
- '860' # 8.6.2/antares-8.6-solver | ||
- '870' # 8.7.0/antares-8.7-solver | ||
|
||
debug: false | ||
|
||
root_path: "" | ||
|
||
server: | ||
worker_threadpool_size: 12 | ||
services: | ||
- watcher | ||
- matrix_gc | ||
|
||
logging: | ||
level: INFO |