Skip to content

Commit

Permalink
test init
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Apr 17, 2019
1 parent 5ebd8ca commit 66948f3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tests/stdout_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ def __enter__(self):
@property
def stdout(self):
if self.capture:
return self.out.getvalue().strip()
return self.out.getvalue()
else:
return ''

@property
def stderr(self):
if self.capture:
return self.err.getvalue().strip()
return self.err.getvalue()
else:
return ''

@property
def output(self):
return self.stdout + self.stderr
return '\n'.join([self.stdout, self.stderr])

def __exit__(self, *args):
if self.capture:
Expand Down
43 changes: 43 additions & 0 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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, 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 TestInit(unittest.TestCase):
def setUp(self):
clean_campaign_file()

def tearDown(self):
clean_campaign_file()

def testInitDefault(self):
with CaptureOutput() as captured:
campaign(FakeArgs(init=True))

self.maxDiff = 1024
with open(f'bombard/examples/{INIT_EXAMPLE}') as ex, open(f'{CAMPAIGN_FILE_NAME}', 'r') as init:
self.assertEqual(
ex.read(),
init.read()
)

def testInitSimpleton(self):
with CaptureOutput() as captured:
campaign(FakeArgs(example='simpleton', init=True))

self.maxDiff = 1024
with open(f'bombard/examples/simpleton.yaml') as desc, open(f'{CAMPAIGN_FILE_NAME}', 'r') as init:
self.assertIn(
desc.read(),
init.read()
)
14 changes: 1 addition & 13 deletions tests/test_show_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,7 @@
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))
Expand All @@ -28,5 +16,5 @@ def testShowFolder(self):
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'
captured.output
)

0 comments on commit 66948f3

Please sign in to comment.