From 5618f120abada65d739442dc657a281f14c07396 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Tue, 5 Apr 2022 09:50:36 -0700 Subject: [PATCH 01/11] initial commit, cite test is working --- aydin/cli/test/test_cli.py | 53 +++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 6fe5689e..790a74b0 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -1,21 +1,32 @@ -# 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 + + +def test_info(): + runner = CliRunner() + result = runner.invoke(cli, ['info']) + assert result.exit_code == 0 + + +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(): + runner = CliRunner() + result = runner.invoke(cli, ['handle_files']) + assert result.exit_code == 0 + + +def test_denoise(): + runner = CliRunner() + result = runner.invoke(cli, ['denoise']) + assert result.exit_code == 1 + + + From 998b91ea588365cca0821412287bd97d7874077a Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Tue, 5 Apr 2022 10:06:45 -0700 Subject: [PATCH 02/11] black and flake8 fixes --- aydin/cli/test/test_cli.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 790a74b0..4e912f46 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -27,6 +27,3 @@ def test_denoise(): runner = CliRunner() result = runner.invoke(cli, ['denoise']) assert result.exit_code == 1 - - - From c0f5148398ee3c8f4f384dc71a0b108b75b81f4c Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Thu, 7 Apr 2022 08:54:20 -0700 Subject: [PATCH 03/11] to keep changes, info command test wip --- aydin/cli/test/test_cli.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 4e912f46..16c9f3ef 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -1,13 +1,18 @@ from click.testing import CliRunner - from aydin.cli.cli import cli +from aydin.io.datasets import examples_single def test_info(): + image_path = examples_single.generic_lizard.get_path() + print(image_path) + runner = CliRunner() - result = runner.invoke(cli, ['info']) + result = runner.invoke(cli, ['info', image_path]) + print(result.output) assert result.exit_code == 0 + assert "batch" in result.output def test_cite(): From 0bf6eed664e7a499e45c20e2d364d0098c941ae0 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Fri, 8 Apr 2022 08:00:16 -0700 Subject: [PATCH 04/11] to keep changes --- aydin/cli/test/test_cli.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 16c9f3ef..9d778187 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -2,22 +2,28 @@ from aydin.cli.cli import cli from aydin.io.datasets import examples_single +from aydin.util.log.log import Log def test_info(): + Log.override_test_exclusion = True image_path = examples_single.generic_lizard.get_path() - print(image_path) runner = CliRunner() result = runner.invoke(cli, ['info', image_path]) print(result.output) + print(result.stdout_bytes) + assert result.exit_code == 0 - assert "batch" in result.output + assert "Reading" in result.stdout_bytes + print(result.output) + assert "Metadata" in result.stdout def test_cite(): runner = CliRunner() result = runner.invoke(cli, ['cite']) + print(result.output) assert result.exit_code == 0 assert "10.5281/zenodo.5654826" in result.output From 353ff02a484b4bc559a3c5de2fc0b12014f5e33b Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Fri, 8 Apr 2022 10:30:41 -0700 Subject: [PATCH 05/11] cli info command test implemented --- aydin/cli/test/test_cli.py | 10 +++++----- aydin/util/log/log.py | 8 +++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 9d778187..8ed3db45 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -7,17 +7,17 @@ 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]) - print(result.output) - print(result.stdout_bytes) assert result.exit_code == 0 - assert "Reading" in result.stdout_bytes - print(result.output) - assert "Metadata" in result.stdout + assert "Reading" in result.output + assert "Metadata" in result.output + assert "batch" in result.output def test_cite(): 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 = "" From f6e2e92664df448523be0a4bd4046d53c063c075 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Fri, 8 Apr 2022 11:49:50 -0700 Subject: [PATCH 06/11] handle files test implemented --- aydin/cli/test/test_cli.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 8ed3db45..abe98168 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -1,6 +1,6 @@ from click.testing import CliRunner -from aydin.cli.cli import cli +from aydin.cli.cli import cli, handle_files from aydin.io.datasets import examples_single from aydin.util.log.log import Log @@ -29,9 +29,23 @@ def test_cite(): def test_handle_files(): - runner = CliRunner() - result = runner.invoke(cli, ['handle_files']) - assert result.exit_code == 0 + file_list = [ + examples_single.generic_lizard.get_path(), + examples_single.fountain.get_path() + ] + filepaths, image_arrays, metadatas = handle_files(file_list, "") + + 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.fountain.get_array().shape + assert image_arrays[1].dtype == examples_single.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.fountain.get_array().shape + assert metadatas[1].dtype == examples_single.fountain.get_array().dtype def test_denoise(): From c7f8ffce8569b6584017a3281c38147049618b82 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Fri, 8 Apr 2022 11:52:51 -0700 Subject: [PATCH 07/11] black fixes --- aydin/cli/test/test_cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index abe98168..bcef9881 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -23,7 +23,7 @@ def test_info(): def test_cite(): runner = CliRunner() result = runner.invoke(cli, ['cite']) - print(result.output) + assert result.exit_code == 0 assert "10.5281/zenodo.5654826" in result.output @@ -31,9 +31,9 @@ def test_cite(): def test_handle_files(): file_list = [ examples_single.generic_lizard.get_path(), - examples_single.fountain.get_path() + examples_single.fountain.get_path(), ] - filepaths, image_arrays, metadatas = handle_files(file_list, "") + filepaths, image_arrays, metadatas = handle_files(file_list, slicing="") assert filepaths == file_list @@ -48,7 +48,7 @@ def test_handle_files(): assert metadatas[1].dtype == examples_single.fountain.get_array().dtype -def test_denoise(): +def test_denoise_saveload(): runner = CliRunner() result = runner.invoke(cli, ['denoise']) assert result.exit_code == 1 From d2fe1803f40522fb6b8996f43fa8ec1568262ea9 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Fri, 8 Apr 2022 12:00:24 -0700 Subject: [PATCH 08/11] test denoise saveload on cli is wip --- aydin/cli/test/test_cli.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index bcef9881..6e6a9c25 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -49,6 +49,32 @@ def test_handle_files(): def test_denoise_saveload(): + image_path = examples_single.gauss_noisy.get_path() + + # Denoise runner = CliRunner() - result = runner.invoke(cli, ['denoise']) - assert result.exit_code == 1 + result = runner.invoke(cli, ['denoise', image_path]) + + assert result.exit_code == 0 + + # Denoise with the pre-trained model + result = runner.invoke(cli, ['denoise', 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 From 4769db29df1f416dadf72df11cdc80d1133d9a61 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Fri, 8 Apr 2022 16:46:22 -0700 Subject: [PATCH 09/11] to keep changes --- aydin/cli/test/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 6e6a9c25..16e87142 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -50,15 +50,15 @@ def test_handle_files(): def test_denoise_saveload(): image_path = examples_single.gauss_noisy.get_path() + print(image_path) # Denoise runner = CliRunner() result = runner.invoke(cli, ['denoise', image_path]) - assert result.exit_code == 0 # Denoise with the pre-trained model - result = runner.invoke(cli, ['denoise', image_path]) + result = runner.invoke(cli, ['denoise', '--model-path=', '--use-model', image_path]) assert result.exit_code == 0 # denoised = denoised.clip(0, 1) From 15a4282f759b010232ef441b274632e755597606 Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Tue, 19 Apr 2022 10:46:58 -0700 Subject: [PATCH 10/11] to keep changes --- aydin/cli/test/test_cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index 16e87142..d9d1f5bd 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -49,7 +49,7 @@ def test_handle_files(): def test_denoise_saveload(): - image_path = examples_single.gauss_noisy.get_path() + image_path = examples_single.fountain.get_path() print(image_path) # Denoise @@ -58,8 +58,8 @@ def test_denoise_saveload(): assert result.exit_code == 0 # Denoise with the pre-trained model - result = runner.invoke(cli, ['denoise', '--model-path=', '--use-model', image_path]) - assert result.exit_code == 0 + # result = runner.invoke(cli, ['denoise', '--model-path=', '--use-model', image_path]) + # assert result.exit_code == 0 # denoised = denoised.clip(0, 1) # From 0d985ec6a947f9ef4a574ce58ae3a00f7ea69f1c Mon Sep 17 00:00:00 2001 From: AhmetCanSolak Date: Mon, 2 May 2022 13:53:11 -0700 Subject: [PATCH 11/11] tests passed --- aydin/cli/test/test_cli.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/aydin/cli/test/test_cli.py b/aydin/cli/test/test_cli.py index d9d1f5bd..f5b8de39 100644 --- a/aydin/cli/test/test_cli.py +++ b/aydin/cli/test/test_cli.py @@ -31,7 +31,7 @@ def test_cite(): def test_handle_files(): file_list = [ examples_single.generic_lizard.get_path(), - examples_single.fountain.get_path(), + examples_single.noisy_fountain.get_path(), ] filepaths, image_arrays, metadatas = handle_files(file_list, slicing="") @@ -39,24 +39,24 @@ def test_handle_files(): 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.fountain.get_array().shape - assert image_arrays[1].dtype == examples_single.fountain.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.fountain.get_array().shape - assert metadatas[1].dtype == examples_single.fountain.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_saveload(): - image_path = examples_single.fountain.get_path() - print(image_path) +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