Skip to content

Commit

Permalink
pep8 formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Mar 13, 2020
1 parent 2439b02 commit efaa9ca
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 25 deletions.
7 changes: 3 additions & 4 deletions bombard/args.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""
Parse bombard command line args.
"""
import sys
import os.path
from bombard.terminal_colours import red, BROWN, OFF
import argparse
import bombard

from bombard.show_descr import markdown_for_terminal
from bombard.terminal_colours import BROWN, OFF

# from pkg_resources import resource_string


Expand Down
31 changes: 16 additions & 15 deletions bombard/bombardier.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from bombard.terminal_colours import red, dark_red, green, gray, GRAY, OFF
from bombard.attr_dict import AttrDict
from urllib.parse import urlparse
import json
import logging
from bombard.weaver_mill import WeaverMill
from bombard.report import Reporter
from typing import Mapping
from urllib.parse import urlparse

from bombard import request_logging
from bombard.attr_dict import AttrDict
from bombard.http_request import http_request, EXCEPTION_STATUS
from bombard.pretty_ns import time_ns
from bombard.pretty_sz import pretty_sz
from bombard.report import Reporter
from bombard.show_descr import markdown_for_terminal
from bombard.http_request import http_request, EXCEPTION_STATUS
from bombard import request_logging
from typing import Mapping

from bombard.terminal_colours import red, dark_red, green
from bombard.weaver_mill import WeaverMill

log = logging.getLogger()

Expand All @@ -22,7 +22,7 @@


def apply_supply(s: str, supply: dict) -> str:
#todo: add args
# todo: add args
if not isinstance(s, str):
return s
try:
Expand All @@ -48,7 +48,8 @@ class Bombardier(WeaverMill):
"""
Use horde of threads to make HTTP-requests
"""
def __init__(self, supply: dict=None, args=None, campaign_book: dict=None, ok_statuses=None,

def __init__(self, supply: dict = None, args=None, campaign_book: dict = None, ok_statuses=None,
overload_statuses=None):
self.supply = supply if supply is not None else {}
self.supply['args'] = args
Expand Down Expand Up @@ -201,8 +202,8 @@ def worker(self, thread_id, ammo):
if self.resp_count in self.show_response:
print(f'{self.show_response[self.resp_count].format(id=self.resp_count):>15}\r', end='')
log.info(self.status_coloured(status) + f' ({pretty_sz(len(resp))}) ' + pretty_url
+ ' ' + (red(resp) if status == EXCEPTION_STATUS else '')
)
+ ' ' + (red(resp) if status == EXCEPTION_STATUS else '')
)
except Exception as e:
log.info(pretty_url + ' ' + red(str(e)), exc_info=True)
finally:
Expand Down Expand Up @@ -245,9 +246,9 @@ def reload(self, requests, repeat=None, prepare=False, **kwargs):
def report(self):
log.warning(
'\n'
+ '='*100
+ '=' * 100
+ '\n'
+ markdown_for_terminal(self.reporter.report())
+ '='*100
+ '=' * 100
+ '\n'
)
7 changes: 4 additions & 3 deletions bombard/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def init(args):
print(f'Cannot init from {src}:\n{RED}File {CAMPAIGN_FILE_NAME} already exists.{OFF}')
return
copyfile(src, CAMPAIGN_FILE_NAME)
#todo copy external python scripts if it is included into the example (create yaml CopyLoader)
# todo copy external python scripts if it is included into the example (create yaml CopyLoader)


def start_campaign(args, campaign_book):
log.debug(f'Starting bombard campaign with args\n' + ' '*4 + f'{args.__dict__}')
log.debug(f'Starting bombard campaign with args\n' + ' ' * 4 + f'{args.__dict__}')
log.debug(f'Loaded bombard campaign from "{args.file_name}": {len(campaign_book.get("ammo", {}))} ammo.')
if PREPARE not in campaign_book and AMMO not in campaign_book:
print(f'You should have at least one of "{PREPARE}" and "{AMMO}" '
Expand All @@ -100,6 +100,7 @@ def start_campaign(args, campaign_book):
bombardier.stop()
bombardier.report()


def campaign(args):
if args.version:
print(bombard.__name__, bombard.version())
Expand Down Expand Up @@ -134,4 +135,4 @@ def main():


if __name__ == '__main__':
main()
main()
3 changes: 2 additions & 1 deletion bombard/mock_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"""
from bombard.campaign_yaml import yaml
from bombard.expand_file_name import expand_relative_file_name
import os.path # we use it to simplify import lines in examples
import os.path # do not remove. we use it to simplify import lines in examples #NOSONAR


resp = {}


def reload(requests, repeat=None, **kwargs):
pass

Expand Down
6 changes: 5 additions & 1 deletion bombard/pretty_ns.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"""

time_ns = None # for Python3.7+ this is function from system library time


# for earlier Python versions this is emulation of the Python3.7 time_ns


Expand Down Expand Up @@ -68,13 +70,15 @@ def pretty(self):


import time

try:
time_ns = time.time_ns
except AttributeError:
from time import perf_counter
time_ns = emul_time_ns

time_ns = emul_time_ns

if __name__ == "__main__":
import doctest

doctest.testmod()
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ CYAN='\033[1;36m'
NC='\033[0m' # No Color
NL=$'\n'

python -m unittest discover --start-directory tests --verbose $@
python3 -m unittest --verbose $@

if [ $? -eq 0 ]; then
echo
Expand Down

0 comments on commit efaa9ca

Please sign in to comment.