Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
elmotec committed May 31, 2021
2 parents febeaf4 + 727d097 commit ae82a74
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 21 deletions.
5 changes: 4 additions & 1 deletion CONTRIBUTING.rst
Expand Up @@ -119,9 +119,12 @@ A reminder for the maintainers on how to deploy.
Make sure all your changes are committed (including an entry in HISTORY.rst).
Then run::

$ python setup.py test # there should be no errors.
$ tox -p # there should be no errors.
$ vim HISTORY.rst
$ bump2version patch # possible: major / minor / patch.
$ vim setup.cfg # bump2version does not update all references.
$ git push
$ git tag vx.y.z
$ git push --tags
$ python setup.py sdist # will generate new .tar.gz in dist folder.
$ twine check dist/<dist>.tar.gz # status should be Passed
Expand Down
4 changes: 4 additions & 0 deletions HISTORY.rst
Expand Up @@ -2,6 +2,10 @@
History
=======

0.11.4 (2021-05-31)
--------------------
* Now handles errors generated by git show (e.g. attempt to retrieve content for deleted file).

0.11.3 (2021-01-30)
--------------------
* Added cm.get_log function for concistency with the rest of the interface.
Expand Down
2 changes: 1 addition & 1 deletion codemetrics/__init__.py
Expand Up @@ -7,7 +7,7 @@
# noinspection SpellCheckingInspection
__author__ = """Elmotec"""
__email__ = "elmotec@gmx.com"
__version__ = "0.11.3"
__version__ = "0.11.4"

from .cloc import get_cloc
from .core import (
Expand Down
5 changes: 4 additions & 1 deletion codemetrics/scm.py
Expand Up @@ -355,7 +355,10 @@ def download(self, revision: str, path: str = None) -> DownloadResult:
), f"expected a string, got {type(path)}"
if path is None:
path = "."
dr = self._download(revision, path)
try:
dr = self._download(revision, path)
except ValueError as ex:
return DownloadResult(revision, path, str(ex))
return dr

@abc.abstractmethod
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
@@ -1,12 +1,12 @@
[bumpversion]
current_version = 0.11.3
current_version = 0.11.4
commit = False
tag = False

[metadata]
name = codemetrics
summary = SCM mining utility classes
version = 0.11.3
version = 0.11.4
author = elmotec
author_email = elmotec@gmx.com
description-file =
Expand Down
33 changes: 17 additions & 16 deletions tests/test_core.py
Expand Up @@ -413,6 +413,19 @@ def setUp(self):
)
)
)
self.expected = pd.read_csv(
io.StringIO(
textwrap.dedent(
"""\
revision,path,function,cyclomatic_complexity,nloc,token_count,name,long_name,start_line,end_line,top_nesting_level,length,fan_in,fan_out,general_fan_out,file_tokens,file_nloc
r1,f.py,0,2,4,16,test,test( ),1,4,0,4,0,0,0,17,4
r2,f.py,0,1,2,8,test,test( ),1,2,0,2,0,0,0,18,4
r2,f.py,1,1,2,8,other,other( ),4,5,0,2,0,0,0,18,4
"""
)
),
dtype={"name": "string", "long_name": "string"},
).set_index(["revision", "path", "function"])

def get_complexity(self):
"""Factor retrieval of complexity"""
Expand Down Expand Up @@ -472,7 +485,8 @@ def test_analysis_empty_input_return_empty_output(self, _):
"""Empty input returns and empty dataframe."""
self.log = self.log.iloc[:0]
actual = cm.get_complexity(self.log, utils.FakeProject())
self.assertTrue(actual.empty)
self.assertEqual(list(actual.columns), list(self.expected.columns))
self.assertEqual(len(actual), 0)

def test_use_default_download(self):
"""When the context.downlad_funcc is defined, use it."""
Expand All @@ -485,22 +499,9 @@ def test_use_default_download(self):

def test_analysis_with_groupby_svn_download(self):
"""Check interface with svn."""
expected = pd.read_csv(
io.StringIO(
textwrap.dedent(
"""\
revision,path,function,cyclomatic_complexity,nloc,token_count,name,long_name,start_line,end_line,top_nesting_level,length,fan_in,fan_out,general_fan_out,file_tokens,file_nloc
r1,f.py,0,2,4,16,test,test( ),1,4,0,4,0,0,0,17,4
r2,f.py,0,1,2,8,test,test( ),1,2,0,2,0,0,0,18,4
r2,f.py,1,1,2,8,other,other( ),4,5,0,2,0,0,0,18,4
"""
)
),
dtype={"name": "string", "long_name": "string"},
).set_index(["revision", "path", "function"])
# Limit to the expected columns for resilience to new columns.
actual = self.get_complexity()[expected.columns]
self.assertEqual(expected.T, actual.T)
actual = self.get_complexity()[self.expected.columns]
self.assertEqual(self.expected.T, actual.T)

def test_complexity_name_dtype(self):
"""Check the dtypes of the get_complexity return value does not contain object dtype."""
Expand Down
22 changes: 22 additions & 0 deletions tests/test_git.py
Expand Up @@ -286,6 +286,28 @@ def test_multiple_revision_download_return_multiple_downloads(self, _run):
]
self.assertEqual(expected, actual)

@mock.patch(
"codemetrics.internals.run",
autospec=True,
side_effect=[
content1,
ValueError("failed to execute git show ..."),
],
)
def test_download_deleted_file(self, _run):
"""Retrieval of multiple revisions returns multiple downloads."""
sublog = pd.DataFrame(data={"revision": ["r1", "r2"], "path": ["file.py"] * 2})
actual = sublog.apply(self.git_project.download, axis=1).tolist()
expected = [
cm.scm.DownloadResult("r1", "file.py", self.content1),
cm.scm.DownloadResult(
"r2",
"file.py",
"failed to execute git show ...",
),
]
self.assertEqual(expected, actual)

@mock.patch("codemetrics.internals.check_run_in_root", autospec=True)
@mock.patch("codemetrics.internals.run", autospec=True)
def test_get_log_with_path(self, run, check_run_in_root) -> None:
Expand Down

0 comments on commit ae82a74

Please sign in to comment.