Skip to content

Commit

Permalink
Move and generalise extract_version_arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljoseph committed Oct 18, 2013
1 parent 3243197 commit ea1454e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
9 changes: 9 additions & 0 deletions changes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,12 @@ def extract(dictionary, keys):
return dict(
(k, dictionary[k]) for k in keys if k in dictionary
)

def extract_arguments(arguments, long_keys, key_prefix='--'):
long_arguments = extract(
arguments,
long_keys,
)
return dict([
(key.replace(key_prefix, ''), value) for key, value in long_arguments.items()
])
9 changes: 1 addition & 8 deletions changes/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_new_version(app_name, current_version,
'What is the release version for "%s" '
'[Default: %s]: ' % (
app_name, proposed_new_version
**util.extract_arguments(
)
)
if not new_version:
Expand All @@ -33,14 +34,6 @@ def get_new_version(app_name, current_version,
return new_version.strip()


def extract_version_arguments(arguments):
long_arguments = util.extract(
arguments,
['--major', '--minor', '--patch'],
)
return dict([
(key[2:], value) for key, value in long_arguments.items()
])


def increment(version, major=False, minor=False, patch=True):
Expand Down
17 changes: 17 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ def test_extract(self):
['a', 'b']
)
)

def test_extract_arguments(self):
self.assertEquals(
{
'major': True,
'minor': False,
'patch': False,
},
util.extract_arguments(
{
'--major': True,
'--minor': False,
'--patch': False,
},
['--major', '--minor', '--patch']
),
)
14 changes: 0 additions & 14 deletions tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@ def test_increment(self):
version.increment('1.0.0', patch=True)
)

def test_extract_version_arguments(self):
self.assertEquals(
{
'major': True,
'minor': False,
'patch': False,
},
version.extract_version_arguments({
'--major': True,
'--minor': False,
'--patch': False,
})
)


class VersionApplicationTestCase(BaseTestCase):

Expand Down

0 comments on commit ea1454e

Please sign in to comment.