Skip to content

Commit

Permalink
Add unit tests for scripts
Browse files Browse the repository at this point in the history
This requires adding a new tox environment with a modified PYTHONPATH,
and making the git hook machinery use that environment.
  • Loading branch information
Noah Lavine committed Mar 14, 2016
1 parent 7c66c11 commit e36320f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion hooks/lib/check-unittest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fi
# Unit test failures can't easily be mapped to specific input files.
# Always run all tests, and report a failure via nonzero exit code if
# any test fails.
if ! tox -e py27 >&2; then
if ! tox -e py27,scripttests >&2; then
>&2 echo "*** tox failed. Note: If dependencies have changed, try "\
"running 'tox -r' to update the tox environment"
exit 1
Expand Down
3 changes: 3 additions & 0 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ mock>=1.0.1
nose>=1.3
flake8>=2.1.0
psutil==3.0.0
gcs-oauth2-boto-plugin
azure

45 changes: 45 additions & 0 deletions script-tests/object_storage_worker_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2016 PerfKitBenchmarker Authors. All rights reserved.
#
# 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.

"""Tests for the object_storage_service benchmark worker process."""

import itertools
import unittest

import object_storage_api_tests


class TestSizeDistributionIterator(unittest.TestCase):
def testPointDistribution(self):
dist = {}
dist[10] = 100.0

iter = object_storage_api_tests.SizeDistributionIterator(dist)

lst = list(itertools.islice(iter, 5))

self.assertEqual(lst, [10, 10, 10, 10, 10])


class TestMaxSizeInDistribution(unittest.TestCase):
def testPointDistribution(self):
dist = {}
dist[10] = 100.0

self.assertEqual(object_storage_api_tests.MaxSizeInDistribution(dist),
10)


if __name__ == '__main__':
unittest.main()
9 changes: 7 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# and then run "tox" from this directory.

[tox]
envlist = py27,flake8
envlist = py27,flake8,scripttests

[testenv]
usedevelop = True
Expand All @@ -14,10 +14,15 @@ passenv = HOME
deps =
-rrequirements-testing.txt

[testenv:scripttests]
commands = nosetests {toxinidir}/script-tests []
setenv =
PYTHONPATH = {toxinidir}/perfkitbenchmarker/scripts:{env:PYTHONPATH}

[testenv:flake8]
skip_install = True
usedevelop = True
commands = flake8 perfkitbenchmarker tests pkb.py
commands = flake8 perfkitbenchmarker tests script-tests pkb.py
deps =
flake8==2.4.1
pep8==1.5.7
Expand Down

0 comments on commit e36320f

Please sign in to comment.