Skip to content

Commit

Permalink
Cleanup and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Oct 16, 2013
1 parent 7e31de7 commit 4c9b7f5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 86 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ Options:
--test-command=<cmd> Command to use to test the newly installed package
--debug Debug output.
The commands do the following:
changelog Generates an automatic changelog from your commit messages
version Increments the __version__ attribute of your module's __init__
test Runs your tests with nosetests
install Attempts to install the sdist
tag Tags your git repo with the new version number
upload Uploads your project with setup.py clean sdist upload
pypi Attempts to install your package from pypi
release Runs all the previous commands
changelog Generates an automatic changelog from your commit messages
bump_version Increments the __version__ attribute of your module's __init__
test Runs your tests with nosetests
install Attempts to install the sdist
tag Tags your git repo with the new version number
upload Uploads your project with setup.py clean sdist upload
pypi Attempts to install your package from pypi
release Runs all the previous commands
```

The default workflow is to run the `changelog` command to autogenerate
Expand Down
5 changes: 3 additions & 2 deletions changes/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def replace_attribute(app_name, attribute_name, new_value, dry_run=True):


def has_attribute(app_name, attribute_name):
init_file = '%s/__init__.py' % app_name
init_file = '%s/__init__.py' % app_name
return any(
[attribute_name in init_line for init_line in open(init_file).readlines()]
[attribute_name in init_line for
init_line in open(init_file).readlines()]
)
26 changes: 12 additions & 14 deletions changes/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,18 @@
--debug Debug output.
The commands do the following:
changelog Generates an automatic changelog from your commit messages
version Increments the __version__ attribute of your module's __init__
test Runs your tests with nosetests
install Attempts to install the sdist
tag Tags your git repo with the new version number
upload Uploads your project with setup.py clean sdist upload
pypi Attempts to install your package from pypi
release Runs all the previous commands
changelog Generates an automatic changelog from your commit messages
bump_version Increments the __version__ attribute of your module's __init__
test Runs your tests with nosetests
install Attempts to install the sdist
tag Tags your git repo with the new version number
upload Uploads your project with setup.py clean sdist upload
pypi Attempts to install your package from pypi
release Runs all the previous commands
"""

import ast
from os.path import exists
import re
import subprocess

import tempfile

from docopt import docopt
Expand All @@ -52,7 +50,7 @@
import virtualenv

import changes
from changes import attributes, probe, shell, util, version
from changes import attributes, probe, shell, version


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -166,8 +164,8 @@ def bump_version():
def commit_version_change():
app_name, dry_run, new_version = common_arguments()

commands = 'git commit -m %s %s/__init__.py %s' % (
new_version, app_name, CHANGELOG
command = 'git commit -m %s %s/__init__.py %s' % (
new_version, app_name, CHANGELOG
)

if not (shell.execute(command, dry_run=dry_run) and
Expand Down
6 changes: 0 additions & 6 deletions changes/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import semantic_version


def extract(dictionary, keys):
"""
Extract only the specified keys from a dict
Expand All @@ -12,6 +9,3 @@ def extract(dictionary, keys):
return dict(
(k, dictionary[k]) for k in keys if k in dictionary
)



2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import sphinx_bootstrap_theme

import changes
import changes

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
28 changes: 28 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import shutil

from unittest2 import TestCase


class BaseTestCase(TestCase):
module_name = 'test_app'
tmp_file = '%s/__init__.py' % module_name

def setUp(self):
if not os.path.exists(self.module_name):
os.mkdir(self.module_name)

self.initial_init_content = [
'"""A test app"""',
'',
"__version__ = '0.0.1'",
"__url__ = 'https://github.com/someuser/%s'" % self.module_name,
"__author__ = 'Some User'",
"__email__ = 'someuser@gmail.com'"
]
with open(self.tmp_file, 'w') as init_file:
init_file.write('\n'.join(self.initial_init_content))

def tearDown(self):
if os.path.exists(self.tmp_file):
shutil.rmtree(self.module_name)
4 changes: 2 additions & 2 deletions tests/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

class AttributeTestCase(BaseTestCase):


def test_extract_attribute(self):
self.assertEquals(
'0.0.1',
Expand Down Expand Up @@ -34,4 +33,5 @@ def test_has_attribute(self):
attributes.has_attribute(
self.module_name,
'__version__'
))
)
)
58 changes: 5 additions & 53 deletions tests/test_changes.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,8 @@
from unittest2 import TestCase
from changes import cli as changes
import os
from changes import cli
from . import BaseTestCase


class ChangesTestCase(TestCase):

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(self):
self.assertEquals(
{'a': 1, 'b': 2},
changes.extract(
{'a': 1, 'b': 2, 'c': 3},
['a', 'b']
)
)



def test_increment(self):
self.assertEquals(
'1.0.0',
changes.increment('0.0.1', major=True)
)

self.assertEquals(
'0.1.0',
changes.increment('0.0.1', minor=True)
)

self.assertEquals(
'1.0.1',
changes.increment('1.0.0', patch=True)
)
class CliTestCase(BaseTestCase):

def test_write_new_changelog(self):
content = [
Expand All @@ -56,7 +13,7 @@ def test_write_new_changelog(self):
with open(self.tmp_file, 'w') as existing_file:
existing_file.writelines(content)

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

self.assertEquals(
''.join(content),
Expand All @@ -68,7 +25,7 @@ def test_write_new_changelog(self):
with open(self.tmp_file, 'w') as existing_file:
existing_file.writelines(content)

changes.write_new_changelog(
cli.write_new_changelog(
'test_app',
self.tmp_file,
'Now this is',
Expand All @@ -85,8 +42,3 @@ def test_write_new_changelog(self):
open(self.tmp_file).readlines()
)
)

def tearDown(self):
if os.path.exists(self.tmp_file):
os.remove(self.tmp_file)
os.rmdir('test_app')
14 changes: 14 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from unittest2 import TestCase
from changes import util


class UtilTestCase(TestCase):

def test_extract(self):
self.assertEquals(
{'a': 1, 'b': 2},
util.extract(
{'a': 1, 'b': 2, 'c': 3},
['a', 'b']
)
)

0 comments on commit 4c9b7f5

Please sign in to comment.