-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from sqoshi/tests
Manual tests
- Loading branch information
Showing
17 changed files
with
116 additions
and
4 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
54 changes: 54 additions & 0 deletions
54
tests/integration/test_command_line/test_command_line_usage.py
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,54 @@ | ||
import os | ||
import shutil | ||
import sys | ||
from pathlib import Path | ||
from typing import List | ||
from unittest import TestCase | ||
from unittest.mock import patch | ||
|
||
import cv2 | ||
|
||
import run | ||
|
||
|
||
def sorted_by_fn(directory) -> List[str]: | ||
return sorted( | ||
[os.path.join(directory, f) for f in os.listdir(directory)], | ||
key=lambda x: Path(x).name | ||
) | ||
|
||
|
||
class CommandLineUsageTestCase(TestCase): | ||
"""Requires installed mask-imposer as package and shape predictor model.""" | ||
|
||
def setUp(self) -> None: | ||
self.test_dir = Path(os.path.abspath(__file__)).parent | ||
self.expected_dir = os.path.join(f"{self.test_dir}", "..", "data", "expected") | ||
|
||
def test_should_impose_masks_on_all_images_from_directory_by_cmd_call(self) -> None: | ||
results_dir = os.path.join(f"{self.test_dir}", "actual") | ||
|
||
testargs = [ | ||
"", | ||
os.path.join(f"{self.test_dir}", "..", "data", "input"), | ||
"--output-dir", | ||
results_dir | ||
] | ||
|
||
with patch.object(sys, 'argv', testargs): | ||
run.main() | ||
|
||
actual_paths = sorted_by_fn(results_dir) | ||
expected_paths = sorted_by_fn(self.expected_dir) | ||
|
||
for ap, ep in zip(actual_paths, expected_paths): | ||
cv2.imshow("Actual", cv2.imread(ap)) | ||
cv2.imshow("Expected", cv2.imread(ep)) | ||
cv2.waitKey(0) | ||
|
||
# assert all( | ||
# compareHist(cv2.imread(h1), cv2.imread(h2), cv2.HISTCMP_CORREL) for h1, h2 in | ||
# zip(actual_paths, expected_paths) | ||
# ) | ||
|
||
shutil.rmtree(results_dir) |
Empty file.
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,58 @@ | ||
import os | ||
from pathlib import Path | ||
from typing import List | ||
from unittest import TestCase | ||
|
||
import cv2 | ||
|
||
import mask_imposer | ||
|
||
|
||
def sorted_by_fn(directory) -> List[str]: | ||
return sorted( | ||
[os.path.join(directory, f) for f in os.listdir(directory)], | ||
key=lambda x: Path(x).name | ||
) | ||
|
||
|
||
class PythonPackageTestCase(TestCase): | ||
"""Requires installed mask-imposer as package and shape predictor model.""" | ||
|
||
def setUp(self) -> None: | ||
self.test_dir = Path(os.path.abspath(__file__)).parent | ||
self.input_dir = os.path.join(f"{self.test_dir}", "..", "data", "input") | ||
self.test_img_path = os.path.join(self.input_dir, "sample2.jpeg") | ||
self.mask_path = os.path.join( | ||
self.test_dir.parent.parent.parent, | ||
"mask_imposer", | ||
"bundled", | ||
"set_01", | ||
"mask_image.png" | ||
) | ||
self.imp = mask_imposer.MaskImposer() | ||
|
||
def test_should_impose_mask_on_image_from_path(self) -> None: | ||
# mask_img = cv2.cvtColor(cv2.imread(self.mask_path), cv2.COLOR_BGR2GRAY) | ||
# masked_img = cv2.cvtColor( | ||
# self.imp.impose_mask(self.test_img_path, show=False), cv2.COLOR_BGR2GRAY | ||
# ) | ||
self.imp.impose_mask(self.test_img_path, show=True) | ||
|
||
# heat_map = cv2.matchTemplate(masked_img, mask_img, cv2.TM_CCOEFF_NORMED) | ||
# heat_map = cv2.matchTemplate(masked_img, mask_img, cv2.TM_CCOEFF_NORMED) | ||
|
||
# h, w = masked_img.shape | ||
# print(masked_img.shape) | ||
# print(heat_map.shape) | ||
# y, x = np.unravel_index(np.argmax(heat_map), heat_map.shape) | ||
# cv2.rectangle(masked_img, (x, y), (x + w, y + h), (0, 0, 255), 5) | ||
# cv2.imshow("Match", masked_img) | ||
# cv2.waitKey(0) | ||
|
||
def test_should_impose_mask_on_image_from_numpy_array(self) -> None: | ||
self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=True) | ||
|
||
def test_should_imposing_results_be_same_for_path_and_numpy_array_way(self): | ||
m1 = self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=False) | ||
m2 = self.imp.impose_mask(self.test_img_path, show=False) | ||
assert (m1 == m2).all() |
Empty file.
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