-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLI: Click tests for CLI commands (#132)
* initial commit, cite test is working * black and flake8 fixes * to keep changes, info command test wip * to keep changes * cli info command test implemented * handle files test implemented * black fixes * test denoise saveload on cli is wip * to keep changes * to keep changes * tests passed Co-authored-by: acs-ws <asolak@ku.edu.tr>
- Loading branch information
1 parent
06b8826
commit 7c2ae4c
Showing
2 changed files
with
87 additions
and
22 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 |
---|---|---|
@@ -1,21 +1,80 @@ | ||
# from click.testing import CliRunner | ||
# | ||
# from aydin.cli.cli import update | ||
# | ||
# | ||
# def test_update(): | ||
# runner = CliRunner() | ||
# result = runner.invoke(update) | ||
# assert result.exit_code == 0 | ||
|
||
|
||
# def test_noise2self(): | ||
# runner = CliRunner() | ||
# result = runner.invoke(noise2self, []) | ||
# assert result.exit_code == 1 | ||
# | ||
# | ||
# def test_info(): | ||
# runner = CliRunner() | ||
# result = runner.invoke(info, []) | ||
# assert result.exit_code == 1 | ||
from click.testing import CliRunner | ||
|
||
from aydin.cli.cli import cli, handle_files | ||
from aydin.io.datasets import examples_single | ||
from aydin.util.log.log import Log | ||
|
||
|
||
def test_info(): | ||
Log.override_test_exclusion = True | ||
Log.force_click_echo = True | ||
|
||
image_path = examples_single.generic_lizard.get_path() | ||
|
||
runner = CliRunner() | ||
result = runner.invoke(cli, ['info', image_path]) | ||
|
||
assert result.exit_code == 0 | ||
assert "Reading" in result.output | ||
assert "Metadata" in result.output | ||
assert "batch" in result.output | ||
|
||
|
||
def test_cite(): | ||
runner = CliRunner() | ||
result = runner.invoke(cli, ['cite']) | ||
|
||
assert result.exit_code == 0 | ||
assert "10.5281/zenodo.5654826" in result.output | ||
|
||
|
||
def test_handle_files(): | ||
file_list = [ | ||
examples_single.generic_lizard.get_path(), | ||
examples_single.noisy_fountain.get_path(), | ||
] | ||
filepaths, image_arrays, metadatas = handle_files(file_list, slicing="") | ||
|
||
assert filepaths == file_list | ||
|
||
assert image_arrays[0].shape == examples_single.generic_lizard.get_array().shape | ||
assert image_arrays[0].dtype == examples_single.generic_lizard.get_array().dtype | ||
assert image_arrays[1].shape == examples_single.noisy_fountain.get_array().shape | ||
assert image_arrays[1].dtype == examples_single.noisy_fountain.get_array().dtype | ||
|
||
assert metadatas[0].shape == examples_single.generic_lizard.get_array().shape | ||
assert metadatas[0].dtype == examples_single.generic_lizard.get_array().dtype | ||
assert metadatas[1].shape == examples_single.noisy_fountain.get_array().shape | ||
assert metadatas[1].dtype == examples_single.noisy_fountain.get_array().dtype | ||
|
||
|
||
def test_denoise(): | ||
image_path = examples_single.noisy_fountain.get_path() | ||
|
||
# Denoise | ||
runner = CliRunner() | ||
result = runner.invoke(cli, ['denoise', image_path]) | ||
assert result.exit_code == 0 | ||
|
||
# TODO: turn this into a saveload testcase | ||
# Denoise with the pre-trained model | ||
# result = runner.invoke(cli, ['denoise', '--model-path=', '--use-model', image_path]) | ||
# assert result.exit_code == 0 | ||
|
||
# denoised = denoised.clip(0, 1) | ||
# | ||
# psnr_noisy = psnr(noisy, image) | ||
# ssim_noisy = ssim(noisy, image) | ||
# print("noisy", psnr_noisy, ssim_noisy) | ||
# | ||
# psnr_denoised = psnr(denoised, image) | ||
# ssim_denoised = ssim(denoised, image) | ||
# print("denoised", psnr_denoised, ssim_denoised) | ||
# | ||
# assert psnr_denoised > psnr_noisy and ssim_denoised > ssim_noisy | ||
# assert psnr_denoised > psnr_noisy and ssim_denoised > ssim_noisy | ||
# | ||
# # if the line below fails, then the parameters of the image the lgbm regressohave been broken. | ||
# # do not change the number below, but instead, fix the problem -- most likely a parameter. | ||
# | ||
# assert psnr_denoised > min_psnr and ssim_denoised > min_ssim |
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