Skip to content

Commit

Permalink
Move test app creation to setUp / tearDown
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Aug 31, 2013
1 parent 8ac08ee commit 2b34aaa
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tests/test_changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

class ChangesTestCase(TestCase):

def setUp(self):
self.tmp_file = 'test_app/__init__.py'
if not os.path.exists('test_app'):
os.mkdir('test_app')

def test_increment(self):
self.assertEquals(
'1.0.0',
Expand All @@ -25,32 +30,29 @@ def test_increment(self):
)

def test_prepend_file(self):
os.mkdir('test_app')
tmp_file = 'test_app/__init__.py'

content = [
'This is the heading\n\n',
'This is the first line\n',
]

with open(tmp_file, 'w') as existing_file:
with open(self.tmp_file, 'w') as existing_file:
existing_file.writelines(content)

write_new_changelog('test_app', tmp_file, 'Now this is')
write_new_changelog('test_app', self.tmp_file, 'Now this is')

self.assertEquals(
''.join(content),
''.join(
open(tmp_file).readlines()
open(self.tmp_file).readlines()
)
)

with open(tmp_file, 'w') as existing_file:
with open(self.tmp_file, 'w') as existing_file:
existing_file.writelines(content)

write_new_changelog(
'test_app',
tmp_file,
self.tmp_file,
'Now this is',
dry_run=False
)
Expand All @@ -62,10 +64,11 @@ def test_prepend_file(self):
self.assertEquals(
''.join(expected_content),
''.join(
open(tmp_file).readlines()
open(self.tmp_file).readlines()
)
)

os.remove(tmp_file)
os.rmdir('test_app')

def tearDown(self):
if os.path.exists(self.tmp_file):
os.remove(self.tmp_file)
os.rmdir('test_app')

0 comments on commit 2b34aaa

Please sign in to comment.