diff --git a/README.txt b/README.txt index d9841b2..7899d18 100644 --- a/README.txt +++ b/README.txt @@ -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'...) ... diff --git a/httperfpy/httperfpy.py b/httperfpy/httperfpy.py index a42801d..b543172 100644 --- a/httperfpy/httperfpy.py +++ b/httperfpy/httperfpy.py @@ -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, diff --git a/setup.py b/setup.py index ea26bc5..1983c58 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='httperfpy', - version='0.0.4', + version='0.0.5', author='Joshua P. Mervine', author_email='joshua@mervine.net', packages=['httperfpy'], diff --git a/unit/httperf_unit.py b/unit/httperf_unit.py index df6657f..52f39df 100644 --- a/unit/httperf_unit.py +++ b/unit/httperf_unit.py @@ -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): @@ -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") @@ -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): @@ -76,4 +98,3 @@ def testSluggedCmdArgs(self): if __name__ == "__main__": unittest.main() -