Skip to content

Commit

Permalink
issue #73 - begin implementation of property to tell if installed via…
Browse files Browse the repository at this point in the history
… git
  • Loading branch information
jantman committed Nov 26, 2015
1 parent 347b061 commit edda4cf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 28 deletions.
72 changes: 53 additions & 19 deletions awslimitchecker/tests/test_versioncheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,10 @@ def test_find_package_version_git_notag(self):
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = True
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'git+https://foo',
Expand All @@ -513,6 +516,7 @@ def test_find_package_version_git_notag(self):
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_git_notag_dirty(self):
cls = AGPLVersionChecker()
Expand All @@ -537,7 +541,10 @@ def test_find_package_version_git_notag_dirty(self):
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = True
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'git+https://foo',
Expand All @@ -548,6 +555,7 @@ def test_find_package_version_git_notag_dirty(self):
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_git_tag(self):
cls = AGPLVersionChecker()
Expand All @@ -572,7 +580,10 @@ def test_find_package_version_git_tag(self):
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = True
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'git+https://foo',
Expand All @@ -583,6 +594,7 @@ def test_find_package_version_git_tag(self):
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_git_tag_dirty(self):
cls = AGPLVersionChecker()
Expand All @@ -607,7 +619,10 @@ def test_find_package_version_git_tag_dirty(self):
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = True
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'git+https://foo',
Expand All @@ -618,6 +633,7 @@ def test_find_package_version_git_tag_dirty(self):
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_pkg_res_exception(self):
cls = AGPLVersionChecker()
Expand All @@ -643,17 +659,21 @@ def se_exception():
'url': 'http://my.package.url/pip'
}
mocks['_find_pkg_info'].side_effect = se_exception
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = False
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'git+https://foo',
'tag': None,
'commit': '12345678',
'dirty': False,
}
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_git_info'].mock_calls == []
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_pip_exception(self):
cls = AGPLVersionChecker()
Expand All @@ -679,7 +699,10 @@ def se_exception():
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = False
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'git+https://foo',
Expand All @@ -690,6 +713,7 @@ def se_exception():
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_no_git(self):
cls = AGPLVersionChecker()
Expand All @@ -715,16 +739,20 @@ def test_find_package_version_no_git(self):
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = False
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'http://my.package.url/pip',
'tag': None,
'commit': None,
}
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_git_info'].mock_calls == []
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_no_git_no_pip(self):
cls = AGPLVersionChecker()
Expand All @@ -750,16 +778,20 @@ def se_exception():
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources'
}
res = cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = False
res = cls.find_package_version()
assert res == {
'version': '1.2.3',
'url': 'http://my.package.url/pkg_resources',
'tag': None,
'commit': None,
}
assert mocks['_find_git_info'].mock_calls == [call(cls)]
assert mocks['_find_git_info'].mock_calls == []
assert mocks['_find_pip_info'].mock_calls == [call(cls)]
assert mocks['_find_pkg_info'].mock_calls == [call(cls)]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_debug(self):
mock_pip_logger = Mock(spec_set=logging.Logger)
Expand Down Expand Up @@ -792,13 +824,13 @@ def test_find_package_version_debug(self):
with patch('%s.logger' % self.mpb,
spec_set=logging.Logger) as mock_mod_logger:
mock_logging.getLogger.return_value = mock_pip_logger
cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = False
cls.find_package_version()
assert mock_logging.mock_calls == []
assert mock_pip_logger.mock_calls == []
assert mock_mod_logger.mock_calls == [
call.debug('Git info: %s',
{'url': None, 'commit': None, 'tag': None,
'dirty': None}),
call.debug('pip info: %s', {'url': 'http://my.package.url/pip',
'version': '1.2.3'}),
call.debug('pkg_resources info: %s',
Expand All @@ -808,6 +840,7 @@ def test_find_package_version_debug(self):
{'url': 'http://my.package.url/pip', 'commit': None,
'version': '1.2.3', 'tag': None})
]
assert mock_is_git.mock_calls == [call()]

def test_find_package_version_no_debug(self):
mock_pip_logger = Mock()
Expand Down Expand Up @@ -841,7 +874,10 @@ def test_find_package_version_no_debug(self):
}
with patch('%s.logger' % self.mpb,
spec_set=logging.Logger) as mock_mod_logger:
cls.find_package_version()
with patch('%s._is_git_clone' % self.pb,
new_callable=PropertyMock) as mock_is_git:
mock_is_git.return_value = False
cls.find_package_version()
assert mock_logging.mock_calls == [
call.getLogger("pip"),
call.getLogger().setLevel(mock_logging.WARNING)
Expand All @@ -851,9 +887,6 @@ def test_find_package_version_no_debug(self):
]
assert mock_mod_logger.mock_calls == [
call.setLevel(mock_logging.WARNING),
call.debug('Git info: %s',
{'url': None, 'commit': None, 'tag': None,
'dirty': None}),
call.debug('pip info: %s', {'url': 'http://my.package.url/pip',
'version': '1.2.3'}),
call.debug('pkg_resources info: %s',
Expand All @@ -863,6 +896,7 @@ def test_find_package_version_no_debug(self):
{'url': 'http://my.package.url/pip', 'commit': None,
'version': '1.2.3', 'tag': None})
]
assert mock_is_git.mock_calls == [call()]


class Test_VersionCheck_Funcs(object):
Expand Down
31 changes: 22 additions & 9 deletions awslimitchecker/versioncheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,18 @@ def find_package_version(self):
'tag': None,
'commit': None
}
git_info = self._find_git_info()
logger.debug("Git info: %s", git_info)
for k, v in git_info.items():
if v is not None:
res[k] = v
if git_info['dirty'] and res['tag'] is not None:
res['tag'] += '*'
if git_info['dirty'] and res['commit'] is not None:
res['commit'] += '*'
if self._is_git_clone:
git_info = self._find_git_info()
logger.debug("Git info: %s", git_info)
for k, v in git_info.items():
if v is not None:
res[k] = v
if git_info['dirty'] and res['tag'] is not None:
res['tag'] += '*'
if git_info['dirty'] and res['commit'] is not None:
res['commit'] += '*'
else:
logger.debug("Install does not appear to be a git clone")
try:
pip_info = self._find_pip_info()
except Exception:
Expand All @@ -135,6 +138,16 @@ def find_package_version(self):
logger.debug("Final package info: %s", res)
return res

@property
def is_git_clone(self):
"""
Attempt to determine whether this package is installed via git or not.
:rtype: bool
:returns: True if installed via git, False otherwise
"""
return True

def _find_pkg_info(self):
"""
Find information about the installed awslimitchecker from pkg_resources.
Expand Down

0 comments on commit edda4cf

Please sign in to comment.