Skip to content

Commit

Permalink
Adds tests for extract_attribute and replace_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Sep 7, 2013
1 parent a396425 commit aaf07cc
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions tests/test_changes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest2 import TestCase
from changes.cli import increment, write_new_changelog
from changes.cli import (extract_attribute, increment, replace_attribute,
write_new_changelog)
import os


Expand All @@ -9,6 +10,34 @@ def setUp(self):
self.tmp_file = 'test_app/__init__.py'
if not os.path.exists('test_app'):
os.mkdir('test_app')
self.initial_init_content = [
'"""A test app"""',
'',
"__version__ = '0.0.1'",
"__url__ = 'https://github.com/michaeljoseph/testapp'",
"__author__ = 'Michael Joseph'",
"__email__ = 'michaeljoseph@gmail.com'"
]
with open(self.tmp_file, 'w') as init_file:
init_file.write('\n'.join(self.initial_init_content))

def test_extract_attribute(self):
self.assertEquals(
'0.0.1',
extract_attribute('test_app', '__version__')
)

def test_replace_attribute(self):
replace_attribute('test_app', '__version__', '1.0.0', dry_run=False)

expected_content = list(self.initial_init_content)
expected_content[2] = "__version__ = '1.0.0'"
self.assertEquals(
'\n'.join(expected_content),
''.join(
open(self.tmp_file).readlines()
)
)

def test_increment(self):
self.assertEquals(
Expand All @@ -26,7 +55,7 @@ def test_increment(self):
increment('1.0.0', patch=True)
)

def test_prepend_file(self):
def test_write_new_changelog(self):
content = [
'This is the heading\n\n',
'This is the first line\n',
Expand All @@ -41,7 +70,7 @@ def test_prepend_file(self):
''.join(content),
''.join(
open(self.tmp_file).readlines()
)
)
)

with open(self.tmp_file, 'w') as existing_file:
Expand Down

0 comments on commit aaf07cc

Please sign in to comment.