Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Click tests for CLI commands #132

Merged
merged 20 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5618f12
initial commit, cite test is working
AhmetCanSolak Apr 5, 2022
998b91e
black and flake8 fixes
AhmetCanSolak Apr 5, 2022
a1cfa4a
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak Apr 7, 2022
c0f5148
to keep changes, info command test wip
AhmetCanSolak Apr 7, 2022
0bf6eed
to keep changes
AhmetCanSolak Apr 8, 2022
714c696
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak Apr 8, 2022
353ff02
cli info command test implemented
AhmetCanSolak Apr 8, 2022
f6e2e92
handle files test implemented
AhmetCanSolak Apr 8, 2022
c7f8ffc
black fixes
AhmetCanSolak Apr 8, 2022
d2fe180
test denoise saveload on cli is wip
AhmetCanSolak Apr 8, 2022
4769db2
to keep changes
AhmetCanSolak Apr 8, 2022
7b188f4
Merge remote-tracking branch 'upstream/master' into click-tests
Apr 13, 2022
cec6369
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak Apr 14, 2022
76ce295
Merge branch 'click-tests' of github.com:AhmetCanSolak/aydin into cli…
AhmetCanSolak Apr 14, 2022
80a5a62
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak Apr 15, 2022
7985444
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak Apr 15, 2022
15a4282
to keep changes
AhmetCanSolak Apr 19, 2022
db1ec16
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak Apr 19, 2022
7b49c87
Merge remote-tracking branch 'upstream/master' into click-tests
AhmetCanSolak May 2, 2022
0d985ec
tests passed
AhmetCanSolak May 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 80 additions & 21 deletions aydin/cli/test/test_cli.py
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
8 changes: 7 additions & 1 deletion aydin/util/log/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import time
from contextlib import contextmanager

import click


class Log:
"""
Expand All @@ -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'
Expand All @@ -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 = ""
Expand Down