Skip to content

Commit

Permalink
#91 sd-50 test_figure: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akorosov committed Jan 26, 2018
1 parent c7b90c5 commit 9c50014
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nansat/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Figure(object):

_cmapName = 'jet'

# instance attributes
array = None
def __init__(self, nparray, **kwargs):
''' Set attributes
Expand Down
31 changes: 31 additions & 0 deletions nansat/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@
# under the terms of GNU General Public License, v.3
# http://www.gnu.org/licenses/gpl-3.0.html
#------------------------------------------------------------------------------
from __future__ import absolute_import, unicode_literals

import unittest
import warnings
import os
import sys
import glob
import datetime
if sys.version_info.major == 2:
from mock import patch, PropertyMock, Mock, MagicMock, DEFAULT
else:
from unittest.mock import patch, PropertyMock, Mock, MagicMock, DEFAULT
try:
import Image
import ImageDraw
import ImageFont
except:
from PIL import Image, ImageDraw, ImageFont

import gdal
import numpy as np
Expand Down Expand Up @@ -123,5 +135,24 @@ def test_get_tick_index_from_grid(self):
n.logger.error(str(lonTicksIdx))
n.logger.error(str(latTicksIdx))

@patch.object(Figure, '__init__', return_value=None)
def test_apply_logarithm(self, mock1):
f = Figure()
f.array = np.ones((1,2,2))*0.1
f.apply_logarithm()
self.assertTrue(np.allclose(np.ones((1,2,2))*0.31622777, f.array))

@patch.object(Figure, '__init__', return_value=None)
def test_make_transparent_color(self, mock1):
f = Figure()

img_array = np.array([[1.,2.],[3.,4.]])
f.pilImg = Image.fromarray(img_array)
f.reprojMask = np.zeros((2,2)) == 1
f.transparency = [1,1,1]
f._make_transparent_color()
self.assertTrue((np.array(f.pilImg)[:,:,3] == np.array([[0,255],[255,255]])).all())


if __name__ == "__main__":
unittest.main()
1 change: 0 additions & 1 deletion nansat/tests/test_vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# under the terms of GNU General Public License, v.3
# http://www.gnu.org/licenses/gpl-3.0.html
# ------------------------------------------------------------------------------

from __future__ import absolute_import, unicode_literals
import unittest
import logging
Expand Down

0 comments on commit 9c50014

Please sign in to comment.