Add unittest entry point for python strolet app

With this change, we are able to run the app unit tests via tox command.

This one also adds a simple unit test for StorletSamples.

Change-Id: I24be75dfb10aaae8db7345e7f89ddc36e93a24fa
This commit is contained in:
Kota Tsuyuzaki 2016-12-08 23:15:31 -08:00
parent 1e5bc9afb7
commit e4787c17c8
9 changed files with 85 additions and 1 deletions

View File

View File

@ -20,7 +20,7 @@ from tests.functional import StorletFunctionalTest, PATH_TO_STORLETS
class StorletPythonFunctionalTest(StorletFunctionalTest):
def setUp(self, storlet_dir, storlet_name, storlet_main,
container, storlet_file, dep_names=None, headers=None):
storlet_dir = os.path.join('python', storlet_dir)
storlet_dir = os.path.join('python', 'storlet_samples', storlet_dir)
path_to_bundle = os.path.join(PATH_TO_STORLETS, storlet_dir)
super(StorletPythonFunctionalTest, self).setUp('Python',
path_to_bundle,

View File

View File

@ -0,0 +1,83 @@
# Copyright (c) 2015, 2016 OpenStack Foundation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from unittest import TestCase
from cStringIO import StringIO
from storlet_samples.simple.simple import SimpleStorlet
from tests.unit import FakeLogger
class FakeStorletFile(object):
def __init__(self):
self._call_closed = False
def close(self):
self._call_closed = True
@property
def closed(self):
return self._call_closed
class FakeStorletFileIn(FakeStorletFile):
def __init__(self, input_string, metadata):
super(FakeStorletFileIn, self).__init__()
self._input_string = StringIO(input_string)
self._metadata = metadata
self._pos = 0
def read(self, size=-1):
return self._input_string.read(size)
def get_metadata(self):
return self._metadata
class FakeStorletFileOut(FakeStorletFile):
def __init__(self):
super(FakeStorletFileOut, self).__init__()
self._output_string = []
self._metadata = None
def write(self, data):
self._output_string.append(data)
def set_metadata(self, metadata):
if self._metadata is None:
self._metadata = {}
self._metadata.update(metadata)
def read(self):
return ''.join(self._output_string)
class TestSimpleStorlet(TestCase):
def setUp(self):
self.logger = FakeLogger()
def test_simple_storlet(self):
simple_storlet = SimpleStorlet(self.logger)
input_string = 'abcdefghijklmonp'
store_in = [FakeStorletFileIn(input_string, {})]
store_out = [FakeStorletFileOut()]
params = {}
self.assertIsNone(simple_storlet(store_in, store_out, params))
# SimpleStorlet sets metadata {'test': 'simple'}
self.assertEqual({'test': 'simple'}, store_out[0]._metadata)
self.assertEqual(input_string, store_out[0].read())
self.assertTrue(store_in[0].closed)
self.assertTrue(store_out[0].closed)

View File

@ -8,6 +8,7 @@ usedevelop = True
install_command = pip install -U {opts} {packages}
setenv =
VIRTUAL_ENV={envdir}
PYTHONPATH={toxinidir}/StorletSamples/python:{envdir}
NOSE_WITH_COVERAGE=1
NOSE_COVER_BRANCHES=1
deps =