Skip to content

Commit

Permalink
Make DruidDatasource.version_higher support funky version strings (#706)
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Jul 1, 2016
1 parent 1a952a4 commit 917bc98
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,31 @@ def get_metric_obj(self, metric_name):
if m.metric_name == metric_name
][0]

def version_higher(self, v1, v2):
v1nums = [int(n) for n in v1.split('.')]
v2nums = [int(n) for n in v2.split('.')]
@staticmethod
def version_higher(v1, v2):
"""is v1 higher than v2
>>> DruidDatasource.version_higher('0.8.2', '0.9.1')
False
>>> DruidDatasource.version_higher('0.8.2', '0.6.1')
True
>>> DruidDatasource.version_higher('0.8.2', '0.8.2')
False
>>> DruidDatasource.version_higher('0.8.2', '0.9.BETA')
False
>>> DruidDatasource.version_higher('0.8.2', '0.9')
False
"""
def int_or_0(v):
try:
v = int(v)
except Exception as e:
v = 0
return v
v1nums = [int_or_0(n) for n in v1.split('.')]
v2nums = [int_or_0(n) for n in v2.split('.')]
v1nums = (v1nums + [0, 0, 0])[:3]
v2nums = (v2nums + [0, 0, 0])[:3]
return v1nums[0] > v2nums[0] or \
(v1nums[0] == v2nums[0] and v1nums[1] > v2nums[1]) or \
(v1nums[0] == v2nums[0] and v1nums[1] == v2nums[1] and v1nums[2] > v2nums[2])
Expand Down
2 changes: 1 addition & 1 deletion tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_dashboard(self):
assert escape(title) in self.client.get(url).data.decode('utf-8')

def test_doctests(self):
modules = [utils]
modules = [utils, models]
for mod in modules:
failed, tests = doctest.testmod(mod)
if failed:
Expand Down

0 comments on commit 917bc98

Please sign in to comment.