-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
110 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
""" | ||
Unbelievable but we need that file for unittest discover to work. | ||
Even python3 does not need that. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
Fake args that we can pass to bombard to test it. | ||
This is AttrDict so you can use something like that | ||
>>> args = FakeArgs(init=True) | ||
>>> args.init | ||
True | ||
""" | ||
from bombard.attr_dict import AttrDict | ||
from bombard.args import CAMPAIGN_FILE_NAME, THRESHOLD, TIMEOUT, THREADS_NUM | ||
|
||
|
||
class FakeArgs(AttrDict): | ||
threads = THREADS_NUM | ||
timeout = TIMEOUT | ||
ms = False | ||
threshold = THRESHOLD | ||
quiet = False | ||
dry = False | ||
verbose = False | ||
quiet = False | ||
log = None | ||
example = None | ||
init = False | ||
examples = False | ||
file_name = CAMPAIGN_FILE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Capture stdout and stderr. | ||
Since Python 3.4 they have (redirect_stdout, redirect_stderr) in contextlib | ||
but my context manager is simpler to use. | ||
Usage: | ||
>>> with CaptureOutput() as captured: | ||
... print('3') | ||
>>> captured.output | ||
'3' | ||
""" | ||
import sys | ||
from io import StringIO | ||
|
||
|
||
class CaptureOutput: | ||
def __init__(self, capture=True): | ||
""" To see output you can set capture to False""" | ||
self.capture = capture | ||
|
||
def __enter__(self): | ||
self.old_out, self.old_err = sys.stdout, sys.stderr | ||
if self.capture: | ||
sys.stdout = self.out = StringIO() | ||
sys.stderr = self.err = StringIO() | ||
return self | ||
|
||
@property | ||
def stdout(self): | ||
if self.capture: | ||
return self.out.getvalue().strip() | ||
else: | ||
return '' | ||
|
||
@property | ||
def stderr(self): | ||
if self.capture: | ||
return self.err.getvalue().strip() | ||
else: | ||
return '' | ||
|
||
@property | ||
def output(self): | ||
return self.stdout + self.stderr | ||
|
||
def __exit__(self, *args): | ||
if self.capture: | ||
sys.stdout, sys.stderr = self.old_out, self.old_err |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from tests.stdout_capture import CaptureOutput | ||
import unittest | ||
from bombard.main import campaign | ||
from tests.fake_args import FakeArgs | ||
from bombard.args import INIT_EXAMPLE, DIR_DESC_FILE_NAME, CAMPAIGN_FILE_NAME | ||
import os.path | ||
from bombard.show_descr import markdown_for_terminal | ||
|
||
|
||
def clean_campaign_file(): | ||
""" Removes default campaign from folder root """ | ||
if os.path.isfile(CAMPAIGN_FILE_NAME): | ||
os.remove(CAMPAIGN_FILE_NAME) | ||
|
||
|
||
class TestShowFolder(unittest.TestCase): | ||
def setUp(self): | ||
clean_campaign_file() | ||
|
||
def tearDown(self): | ||
clean_campaign_file() | ||
|
||
def testShowFolder(self): | ||
with CaptureOutput() as captured: | ||
campaign(FakeArgs(examples=True)) | ||
|
||
self.maxDiff = 1024 | ||
with open(f'bombard/examples/{DIR_DESC_FILE_NAME}') as desc: | ||
self.assertIn( # do not check 1st line of output with the folder name | ||
markdown_for_terminal(desc.read()), | ||
captured.output + '\n' | ||
) |
File renamed without changes.