-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flowty CLI level test, Shuffle functional tests around
- Loading branch information
Showing
17 changed files
with
136 additions
and
104 deletions.
There are no files selected for viewing
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
|
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
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from flowty.videoio import FlowImageWriter | ||
|
||
|
||
class TestFlowImageWriter: | ||
def test_saving_single_flow_image(self, tmp_path): | ||
image_writer = self.get_flow_writer(tmp_path) | ||
flow = np.random.randint(low=0, high=255, size=(5, 5, 2), dtype=np.uint8) | ||
|
||
image_writer.write(flow) | ||
|
||
for axis in ['u', 'v']: | ||
assert (Path(tmp_path) / axis / '00001.jpg').exists() | ||
|
||
def test_throws_error_if_flow_not_uint8(self, tmp_path): | ||
image_writer = self.get_flow_writer(tmp_path) | ||
flow = np.random.randint(low=0, high=255, size=(5, 5, 2), dtype=np.int32) | ||
|
||
with pytest.raises(ValueError): | ||
image_writer.write(flow) | ||
|
||
def test_throws_error_if_flow_not_2_channels(self, tmp_path): | ||
image_writer = self.get_flow_writer(tmp_path) | ||
flow = np.random.randint(low=0, high=255, size=(5, 5, 3), dtype=np.uint8) | ||
|
||
with pytest.raises(ValueError): | ||
image_writer.write(flow) | ||
|
||
def test_throws_error_if_flow_not_3_dimensional(self, tmp_path): | ||
image_writer = self.get_flow_writer(tmp_path) | ||
flow = np.random.randint(low=0, high=255, size=(5, 5), dtype=np.uint8) | ||
|
||
with pytest.raises(ValueError): | ||
image_writer.write(flow) | ||
|
||
def get_flow_writer(self, tmp_path): | ||
filename_template = tmp_path / '{axis}/{index:05d}.jpg' | ||
return FlowImageWriter(str(filename_template)) |
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,47 +1,25 @@ | ||
import sys | ||
from io import StringIO | ||
|
||
from unittest.mock import Mock | ||
|
||
from flowty.flowty import main, command_parsers | ||
|
||
|
||
class IOCapture: | ||
def __init__(self): | ||
self._original_stdout = sys.stdout | ||
self._original_stderr = sys.stderr | ||
self._stdout = StringIO() | ||
self._stderr = StringIO() | ||
|
||
def __enter__(self): | ||
sys.stdout = self._stdout | ||
sys.stderr = self._stderr | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
sys.stdout = self._original_stdout | ||
sys.stderr = self._original_stderr | ||
|
||
@property | ||
def stdout(self): | ||
return self._stdout.getvalue() | ||
|
||
@property | ||
def stderr(self): | ||
return self._stderr.getvalue() | ||
|
||
|
||
class TestFlowtyCli: | ||
def test_prints_help_when_no_command_is_provided(self): | ||
with IOCapture() as capture: | ||
main([]) | ||
assert 'usage: flowty' in capture.stdout | ||
|
||
def test_invokes_registered_command(self): | ||
tvl1_parser = command_parsers.add_parser('tvl1') | ||
tvl1_command = Mock() | ||
tvl1_parser.set_defaults(command=tvl1_command) | ||
|
||
main(['tvl1']) | ||
|
||
tvl1_command.assert_called_once() | ||
from pathlib import Path | ||
import numpy as np | ||
from imageio import imread | ||
|
||
from flowty import flowty | ||
from tests.resources import RUBBER_WHALE | ||
|
||
|
||
class TestFlowty: | ||
def test_tvl1_flow_from_mp4_to_uv_images(self, tmpdir): | ||
src = RUBBER_WHALE['media_path']['png'] | ||
output_dir = tmpdir / 'flow' | ||
dest = output_dir / '{axis}' / 'frame{index:02d}.png' | ||
stride = 2 | ||
|
||
flowty.main(["dis", "--video-stride", str(stride), str(src), str(dest)]) | ||
|
||
for axis in ['u', 'v']: | ||
for i in range(1, RUBBER_WHALE['frame_count'] // stride): | ||
flow_frame_path = Path(output_dir / axis / 'frame{:02d}.png'.format(i)) | ||
assert flow_frame_path.exists() | ||
flow_frame = imread(flow_frame_path) | ||
assert flow_frame.shape == RUBBER_WHALE['resolution'] | ||
assert flow_frame.dtype == np.uint8 | ||
assert not Path(output_dir / axis / 'frame{:02d}.png'.format( RUBBER_WHALE['frame_count'])).exists() |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
|
||
|
||
MEDIA_ROOT = Path(__file__).parent.parent / 'media' | ||
VIDEO_PATHS = { | ||
'mp4': str(MEDIA_ROOT / 'mr-bubz.mp4'), | ||
'webm': str(MEDIA_ROOT / 'mr-bubz.webm'), | ||
'avi': str(MEDIA_ROOT / 'mr-bubz.avi'), | ||
'jpeg': str(MEDIA_ROOT / 'mr-bubz' / 'frame_%05d.jpg'), | ||
} | ||
RUBBER_WHALE = { | ||
'media_path': { | ||
'mp4': str(MEDIA_ROOT / 'rubber-whale.mp4'), | ||
'png': str(MEDIA_ROOT / 'rubber-whale' / 'frame%02d.png'), | ||
}, | ||
'resolution': (388, 584), | ||
'frame_count': 8, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import sys | ||
from io import StringIO | ||
|
||
from unittest.mock import Mock | ||
|
||
from flowty.flowty import main, command_parsers | ||
|
||
|
||
class IOCapture: | ||
def __init__(self): | ||
self._original_stdout = sys.stdout | ||
self._original_stderr = sys.stderr | ||
self._stdout = StringIO() | ||
self._stderr = StringIO() | ||
|
||
def __enter__(self): | ||
sys.stdout = self._stdout | ||
sys.stderr = self._stderr | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
sys.stdout = self._original_stdout | ||
sys.stderr = self._original_stderr | ||
|
||
@property | ||
def stdout(self): | ||
return self._stdout.getvalue() | ||
|
||
@property | ||
def stderr(self): | ||
return self._stderr.getvalue() | ||
|
||
|
||
class TestFlowtyCli: | ||
def test_prints_help_when_no_command_is_provided(self): | ||
with IOCapture() as capture: | ||
main([]) | ||
assert 'usage: flowty' in capture.stdout | ||
|
||
def test_invokes_registered_command(self): | ||
tvl1_parser = command_parsers.add_parser('tvl1') | ||
tvl1_command = Mock() | ||
tvl1_parser.set_defaults(command=tvl1_command) | ||
|
||
main(['tvl1']) | ||
|
||
tvl1_command.assert_called_once() |