diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 6fe5689e..f5b8de39 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -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 diff --git a/aydin/util/log/log.py b/aydin/util/log/log.py index 2b78a764..f470cdb4 100644 --- a/aydin/util/log/log.py +++ b/aydin/util/log/log.py @@ -4,6 +4,8 @@ import time from contextlib import contextmanager +import click + class Log: """ @@ -19,6 +21,7 @@ class Log: max_depth = math.inf log_elapsed_time = True override_test_exclusion = False + force_click_echo = False # Define special characters: __vl__ = '│' # 'Vertical Line' @@ -44,7 +47,10 @@ def __init__(self): @staticmethod def native_print(*args, sep=' ', end='\n', file=sys.__stdout__): if Log.enable_output: - print(*args, sep=sep, end=end, file=file) + if Log.force_click_echo: + click.echo(*args) + else: + print(*args, sep=sep, end=end, file=file) if Log.guiEnabled and Log.gui_callback is not None: result = ""