Skip to content

Commit

Permalink
Adding support for boolean args via params.
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Mervine committed Dec 4, 2014
1 parent f53f6d0 commit 6d60b81
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ Passing variables and key-values to httperf
# arguments, key-value arguments
perf = Httperf('hog', 'ssl', path='/path/to/httperf',
server='www.example.com'...)

# or only key-value arguments
perf = Httperf(hog=True, ssl=True, path='/path/to/httperf',
server='www.example.com'...)
...


Expand Down
18 changes: 17 additions & 1 deletion httperfpy/httperfpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,25 @@ def __cmd(self):
for key in self.params.keys():
val = str(self.params[key])
key = key.replace('_', '-')
args.append('--%s="%s"' % (key, val))
if key in self.__boolean_params():
args.append('--%s' % key)
else:
args.append('--%s="%s"' % (key, val))

return ' '.join(args)

def __boolean_params(self):
return [
"hog",
"no_host_hdr",
"retry_on_failure",
"session_cookies",
"ssl",
"ssl_no_reuse",
"verbose",
"version"
]

def __params(self):
return {
"add_header": None,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='httperfpy',
version='0.0.4',
version='0.0.5',
author='Joshua P. Mervine',
author_email='[email protected]',
packages=['httperfpy'],
Expand Down
33 changes: 27 additions & 6 deletions unit/httperf_unit.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import unit_helper
import unittest
import re, os, sys
import re

# import everything unit_helper does
from unit_helper import *


class HttperfTestCase(unittest.TestCase):

def testHttperfDisplayParams(self):
Expand All @@ -27,16 +28,36 @@ def testInitWithPathSetsPath(self):
self.assertEqual(httperf1.path, unit_helper.httperf_path)

def testInitWithArgsCreatesArg(self):
httperf = Httperf(server="localhost", port=8080, num_conns=100)
# arg method
httperf = Httperf('hog', server="localhost", port=8080, num_conns=100)
self.assertEqual(httperf.params["server"], "localhost")
self.assertEqual(('--hog' in httperf.args), True)

res_str = httperf.run()
m = re.search('--hog', res_str)
self.assertNotEqual(m, None)

m = re.search('--hog=', res_str)
self.assertEqual(m, None)

# param method
httperf = Httperf(hog=True, server="localhost", port=8080, num_conns=100)
self.assertEqual(httperf.params["hog"], True)

res_str = httperf.run()
m = re.search('--hog', res_str)
self.assertNotEqual(m, None)

m = re.search('--hog=', res_str)
self.assertEqual(m, None)

def testInitWithBadKwArg(self):
with self.assertRaises(Exception):
httperf = Httperf(bad="localhost")
Httperf(bad="localhost")

def testInitWithBadArg(self):
with self.assertRaises(Exception):
httperf = Httperf('bad')
Httperf('bad')

def testUpdateOptionAlreadyCreated(self):
httperf = Httperf(server="localhost")
Expand All @@ -52,13 +73,14 @@ def testRun(self):
httperf = Httperf()
global res_string
res_string = httperf.run()

self.assertNotEqual(res_string, None)

def testRunResultsNotEmpty(self):
self.assertNotEqual(res_string, "")

def testRunResultsContainsHttperfResults(self):
m = re.search('httperf --client=0/1 --server=localhost' , res_string)
m = re.search('httperf --client=0/1 --server=localhost', res_string)
self.assertNotEqual(m, None)

def testRunResultsWithParser(self):
Expand All @@ -76,4 +98,3 @@ def testSluggedCmdArgs(self):

if __name__ == "__main__":
unittest.main()

0 comments on commit 6d60b81

Please sign in to comment.