Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Added unitests for nagetive cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Oct 23, 2018
1 parent 5ff82f3 commit 5b23033
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/python/unittest/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import tempfile
import unittest

from builtins import bytearray

from nose.tools import raises

def _get_data(url, dirname):
Expand Down Expand Up @@ -92,6 +94,26 @@ def test_imdecode(self):
cv_image = cv2.imread(img)
assert_almost_equal(image.asnumpy(), cv_image)

def test_imdecode_bytearray(self):
try:
import cv2
except ImportError:
return
for img in TestImage.IMAGES:
with open(img, 'rb') as fp:
str_image = bytearray(fp.read())
image = mx.image.imdecode(str_image, to_rgb=0)
cv_image = cv2.imread(img)
assert_almost_equal(image.asnumpy(), cv_image)

@raises(ValueError)
def test_imdecode_empty_buffer(self):
try:
import cv2
except ImportError:
raise ValueError("cv2 is not installed")
mx.image.imdecode(b'', to_rgb=0)

def test_scale_down(self):
assert mx.image.scale_down((640, 480), (720, 120)) == (640, 106)
assert mx.image.scale_down((360, 1000), (480, 500)) == (360, 375)
Expand Down

0 comments on commit 5b23033

Please sign in to comment.