Skip to content

Commit

Permalink
replaced loops with comprehension
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Aug 30, 2020
1 parent ef43017 commit 3b3a44a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
12 changes: 6 additions & 6 deletions bombard/bombardier.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ def apply_supply_dict(request: dict, supply: dict) -> dict:
"""
Use supply to substitute all {name} in request strings.
"""
for name in request:
for name, value in request.items():
if isinstance(request[name], dict):
request[name] = apply_supply_dict(request[name], supply)
elif isinstance(request[name], str):
elif isinstance(value, str):
request[name] = apply_supply(request[name], supply)
return request

Expand Down Expand Up @@ -93,14 +93,14 @@ def get_headers(request: dict, body_is_json: bool) -> dict:
}
if 'headers' in request and isinstance(request['headers'], str):
# if headers in request description just a string we know this should be some predefined code
for known in predefined:
for known, value in predefined.items():
if request['headers'].lower() == known:
return predefined[known]
return value
result = {}
for name, val in request.get('headers', {}).items():
for known in predefined:
for known, value in predefined.items():
if name.lower() == known:
result.update(predefined[known])
result.update(value)
break
else:
result.update({name: val})
Expand Down
7 changes: 2 additions & 5 deletions bombard/campaign_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,11 @@ def __init__(self, stream):
super(IncludesLoader, self).__init__(stream)

@staticmethod
def wrap_in_yaml_document(msg: str) ->str:
def wrap_in_yaml_document(msg: str) -> str:
"""
Converts multi-line msg to yaml document that we can insert into yaml
"""
result = []
for line in msg.split('\n'):
if SIGNATURE not in line: # skip line that mocks globals
result.append(' '*4 + line)
result = [' '*4 + line for line in msg.split('\n') if SIGNATURE not in line]
return '|\n' + '\n'.join(result)

def include(self, node):
Expand Down
2 changes: 1 addition & 1 deletion bombard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def campaign(args):
campaign_file_name = get_campaign_file_name(args)
if os.path.isdir(campaign_file_name):
show_folder(campaign_file_name)
elif not os.path.isfile(campaign_file_name) and not args.init:
elif not (os.path.isfile(campaign_file_name) or args.init):
print(red(f'\nCannot find campaign file "{args.file_name}"\n'))
else:
start_campaign(args, yaml.load(open(campaign_file_name, 'r')))
Expand Down
2 changes: 1 addition & 1 deletion bombard/weaver_mill.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def process(self):

def stop(self):
""" Stops all threads - send stop signal to queue and lock until they stop """
for _ in range(len(self.threads)):
for _ in self.threads:
self.queue.put(None)
for thread in self.threads:
thread.join()
1 change: 1 addition & 0 deletions tests/test_campaign_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

EMPTY_BOOK = {}


class TestCampaignCheck(unittest.TestCase):
def setUp(self):
setup_logging(logging.DEBUG)
Expand Down

0 comments on commit 3b3a44a

Please sign in to comment.