Skip to content

Commit

Permalink
Handle internal versions matches
Browse files Browse the repository at this point in the history
  • Loading branch information
jacebrowning committed Oct 21, 2016
1 parent 44480b8 commit 6927d92
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
## 0.4 (unreleased)

- Added support for custom version arguments.
- Fixed handling of internal versions matches.

## 0.3 (2016/10/18)

Expand Down
6 changes: 5 additions & 1 deletion verchew/script.py
Expand Up @@ -131,7 +131,7 @@ def check_dependencies(config):
for name, settings in config.items():
show("Checking for {0}...".format(name), head=True)
output = get_version(settings['cli'], settings.get('cli_version_arg'))
if settings['version'] in output:
if match_version(settings['version'], output):
show(_("~") + " MATCHED: {0}".format(settings['version']))
success.append(_("~"))
else:
Expand All @@ -154,6 +154,10 @@ def get_version(program, argument=None):
return output


def match_version(pattern, output):
return output.startswith(pattern) or " " + pattern in output


def call(args):
try:
process = Popen(args, stdout=PIPE, stderr=STDOUT)
Expand Down
23 changes: 21 additions & 2 deletions verchew/tests/test_script.py
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-

# pylint: disable=unused-variable,unused-argument,expression-not-assigned
# pylint: disable=unused-variable,unused-argument,expression-not-assigned,singleton-comparison

from __future__ import unicode_literals

import pytest
from expecter import expect

from verchew.script import find_config, parse_config, get_version, _
from verchew.script import (find_config, parse_config, get_version,
match_version, _)


def describe_find_config():
Expand Down Expand Up @@ -80,6 +81,24 @@ def with_custom_argument():
expect(get_version('python', argument='-V')).contains("Python ")


def describe_match_version():

def when_exact():
expect(match_version("1.2.3", "1.2.3")) == True

def when_partial():
expect(match_version("1.2.", "1.2.3")) == True

def when_mismatch():
expect(match_version("1.", "2.0")) == False

def when_match_inside():
expect(match_version("1.", "Foobar 1.2.3")) == True

def when_mismatch_inside():
expect(match_version("2.", "Foobar 1.2.3")) == False


def describe_format():

def when_utf8():
Expand Down

0 comments on commit 6927d92

Please sign in to comment.