-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
257 additions
and
313 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Name: nansat_test_base.py | ||
# Purpose: Basic class for Nansat tests | ||
# | ||
# Author: Anton Korosov | ||
# | ||
# Created: 20.03.2018 | ||
# Copyright: (c) NERSC | ||
# Licence: This file is part of NANSAT. You can redistribute it or modify | ||
# under the terms of GNU General Public License, v.3 | ||
# http://www.gnu.org/licenses/gpl-3.0.html | ||
# ------------------------------------------------------------------------------ | ||
from __future__ import print_function, absolute_import, division | ||
import os | ||
import sys | ||
import unittest | ||
import tempfile | ||
import pythesint | ||
|
||
if sys.version_info.major == 2: | ||
from mock import patch, PropertyMock, Mock, MagicMock, DEFAULT | ||
else: | ||
from unittest.mock import patch, PropertyMock, Mock, MagicMock, DEFAULT | ||
|
||
from nansat.tests import nansat_test_data as ntd | ||
|
||
class NansatTestBase(unittest.TestCase): | ||
def setUp(self): | ||
self.test_file_gcps = os.path.join(ntd.test_data_path, 'gcps.tif') | ||
self.test_file_stere = os.path.join(ntd.test_data_path, 'stere.tif') | ||
self.test_file_complex = os.path.join(ntd.test_data_path, 'complex.nc') | ||
self.test_file_arctic = os.path.join(ntd.test_data_path, 'arctic.nc') | ||
self.tmp_data_path = ntd.tmp_data_path | ||
self.default_mapper = 'generic' | ||
fd, self.tmpfilename = tempfile.mkstemp(suffix='.nc', dir=ntd.tmp_data_path) | ||
os.close(fd) | ||
|
||
if not os.path.exists(self.test_file_gcps): | ||
raise ValueError('No test data available') | ||
# Mock several Pythesint functions to avoid network connection | ||
self.patcher = patch.multiple(pythesint, get_wkv_variable=DEFAULT, | ||
get_gcmd_instrument=DEFAULT, | ||
get_gcmd_platform=DEFAULT) | ||
self.mock_pti = self.patcher.start() | ||
self.mock_pti['get_gcmd_instrument'].return_value=dict(short_name='MODIS') | ||
self.mock_pti['get_gcmd_platform'].return_value=dict(short_name='AQUA') | ||
self.mock_pti['get_wkv_variable'].return_value=dict(short_name='swathmask') | ||
|
||
def tearDown(self): | ||
self.patcher.stop() | ||
try: | ||
os.unlink(self.tmpfilename) | ||
except OSError: | ||
pass |
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
Oops, something went wrong.