Newer
Older
# coding=utf-8
from unittest import TestCase
from earthdiagnostics.cdftools import CDFTools
import mock
class TestCDFTools(TestCase):
def setUp(self):
self.cdftools = CDFTools('')
mock.patch('os.path.join')
def test_run(self):
with mock.patch('os.path.exists') as exists_mock:
def mock_exists(path):
"""
Function for os.path.exists mock
:param path: path to check
:type path: str
:return: true if path does not start with 'bad'
:rtype: bool
"""
return not path.startswith('bad')
exists_mock.side_effect = mock_exists
with mock.patch('earthdiagnostics.utils.Utils.execute_shell_command') as execute_mock:
execute_mock.return_value = ['Command output']
with self.assertRaises(ValueError):
self.cdftools.run('badcommand', input='input_file', output='output_file')
with self.assertRaises(ValueError):
self.cdftools.run('command', input='badinput_file', output='output_file')
with self.assertRaises(ValueError):
self.cdftools.run('command', input=['input_file', 'badinput_file'], output='output_file')
with self.assertRaises(ValueError):
self.cdftools.run('command', input='input_file', output='input_file')
with self.assertRaises(Exception):
self.cdftools.run('command', input='input_file', output='badoutput_file')
self.cdftools.run('command', input='input_file', output='output_file')
self.cdftools.run('command', input='input_file')
self.cdftools.run('command', input=None)
self.cdftools.run('command', input=['input_file', 'input_file2'])
self.cdftools.run('command', input='input_file', options='-o -p')
self.cdftools.run('command', input='input_file', options=('-o', '-p'))