Skip to content

Commit

Permalink
Add options --version to 3 fluidimage apps
Browse files Browse the repository at this point in the history
  • Loading branch information
paugier committed Apr 19, 2024
1 parent 16580e2 commit 936cdd5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 30 deletions.
13 changes: 12 additions & 1 deletion src/fluidimage/gui/imviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import matplotlib.pyplot as plt

import fluidimage
from fluiddyn.io.image import imread
from fluiddyn.util import time_as_str
from fluiddyn.util.serieofarrays import SerieOfArraysFromFiles
Expand Down Expand Up @@ -62,7 +63,12 @@ def parse_args():
"-cm", "--colormap", help="colormap", type=str, default=""
)
parser.add_argument("-v", "--verbose", help="verbose mode", action="count")

parser.add_argument(
"-V",
"--version",
help="Print fluidimage version and exit",
action="count",
)
return parser.parse_args()


Expand Down Expand Up @@ -309,4 +315,9 @@ def onclick(self, event):

def main():
args = parse_args()

if args.version:
print(f"fluidimage {fluidimage.__version__}")
return

ImageViewer(args)
13 changes: 12 additions & 1 deletion src/fluidimage/gui/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Tree,
)

import fluidimage
from fluidimage import ParamContainer


Expand Down Expand Up @@ -98,7 +99,12 @@ def parse_args(cls):
parser.add_argument(
"-v", "--verbose", help="verbose mode", action="count"
)

parser.add_argument(
"-V",
"--version",
help="Print fluidimage version and exit",
action="count",
)
return parser.parse_args()

def __init__(self, args):
Expand Down Expand Up @@ -270,5 +276,10 @@ def on_tree_node_selected(self, event):
def main():
"""Main function for fluidimage-monitor"""
args = MonitorApp.parse_args()

if args.version:
print(f"fluidimage {fluidimage.__version__}")
return

app = MonitorApp(args)
app.run()
13 changes: 12 additions & 1 deletion src/fluidimage/gui/piv_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import h5py
import matplotlib.pyplot as plt

import fluidimage
from fluiddyn.util.serieofarrays import SerieOfArraysFromFiles
from fluidimage.gui.base_matplotlib import AppMatplotlibWidgets

Expand Down Expand Up @@ -84,7 +85,12 @@ def parse_args(cls):
parser.add_argument(
"-v", "--verbose", help="verbose mode", action="count"
)

parser.add_argument(
"-V",
"--version",
help="Print fluidimage version and exit",
action="count",
)
return parser.parse_args()

def __init__(self, args):
Expand Down Expand Up @@ -208,4 +214,9 @@ def _update_fig(self):

def main():
args = VectorFieldsViewer.parse_args()

if args.version:
print(f"fluidimage {fluidimage.__version__}")
return

return VectorFieldsViewer(args)
58 changes: 31 additions & 27 deletions src/fluidimage/gui/test_imviewer.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import sys
import unittest

from fluiddyn.io import stdout_redirected
from fluidimage import get_path_image_samples
from fluidimage.gui.imviewer import ImageViewer, parse_args
from fluidimage.gui.imviewer import ImageViewer, main, parse_args

path_image_samples = get_path_image_samples()


class TestImageViewer(unittest.TestCase):
def test_main(self):
with stdout_redirected():
command = "fluidimviewer"
args = command.split()
args.append(str(path_image_samples / "Karman/Images"))
sys.argv = args
args = parse_args()
ImageViewer(args)
def test_fluidimviewer_version(monkeypatch):
command = "fluidimviewer --version"
with monkeypatch.context() as ctx:
ctx.setattr(sys, "argv", command.split())
main()

args = command.split()
args.append(str(path_image_samples / "Karman/Images/*"))
sys.argv = args

args = parse_args()
self = ImageViewer(args)
def test_main(monkeypatch):

self.set_autoclim(None)
words = ["fluidimviewer", str(path_image_samples / "Karman/Images")]
with monkeypatch.context() as ctx:
ctx.setattr(sys, "argv", words)
args = parse_args()

self._switch()
self._switch()
ImageViewer(args)

self._increase_ifile()
self._decrease_ifile()
words = ["fluidimviewer", str(path_image_samples / "Karman/Images/*")]
with monkeypatch.context() as ctx:
ctx.setattr(sys, "argv", words)
args = parse_args()

self._submit_n("2")
viewer = ImageViewer(args)

self._increase_ifile_n()
self._decrease_ifile_n()
viewer.set_autoclim(None)

self._change_cmin("1")
self._change_cmax("2")
viewer._switch()
viewer._switch()

viewer._increase_ifile()
viewer._decrease_ifile()

viewer._submit_n("2")

viewer._increase_ifile_n()
viewer._decrease_ifile_n()

viewer._change_cmin("1")
viewer._change_cmax("2")
8 changes: 8 additions & 0 deletions src/fluidimage/gui/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_monitor_help(monkeypatch):
raise RuntimeError


def test_monitor_version(monkeypatch):
command = "fluidimage-monitor --version"

with monkeypatch.context() as ctx:
ctx.setattr(sys, "argv", command.split())
main()


def test_monitor_bad_paths(monkeypatch, tmp_path):

command = "fluidimage-monitor __dir_does_not_exist__"
Expand Down
7 changes: 7 additions & 0 deletions src/fluidimage/gui/test_piv_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
from fluidimage.gui.piv_viewer import main


def test_fluidpivviewer_version(monkeypatch):
command = "fluidpivviewer --version"
with monkeypatch.context() as ctx:
ctx.setattr(sys, "argv", command.split())
main()


def test_main(monkeypatch):

path_image_samples = get_path_image_samples()
Expand Down

0 comments on commit 936cdd5

Please sign in to comment.