diff --git a/docs/processmetrics.rst b/docs/processmetrics.rst index 2ca44cca..c4213fc5 100644 --- a/docs/processmetrics.rst +++ b/docs/processmetrics.rst @@ -7,6 +7,8 @@ Process Metrics Process metrics capture aspects of the development process rather than aspects about the code itself. From release 1.11 PyDriller can calculate ``change_set``, ``code churn``, ``commits count``, ``contributors count``, ``contributors experience``, ``history complexity``, ``hunks count``, ``lines count`` and ``minor contributors``. Everything in just one line! +The metrics can be run between two commits (setting up the parameters ``from_commit`` and ``to_commit``) or between two dates (setting up the parameters ``since`` and ``to``) + Below an example of how call the metrics. @@ -37,6 +39,22 @@ will print the maximum and average number of files committed together in the evo **Note:** differently from the other metrics below, the scope of this metrics is the evolution period rather than the single files. +It is possible to specify the dates as follows:: + + from datetime import datetime + from pydriller.metrics.process.change_set import ChangeSet + metric = ChangeSet(path_to_repo='path/to/the/repo', + since=datetime(2019, 1, 1), + to=datetime(2019, 12, 31)) + + maximum = metric.max() + average = metric.avg() + print('Maximum number of files committed together: {}'.format(maximum)) + print('Average number of files committed together: {}'.format(average)) + +The code above will print the maximum and average number of files committed together between the ``1st January 2019`` and ``31st December 2019``. + + Code Churn ========== diff --git a/pydriller/metrics/process/change_set.py b/pydriller/metrics/process/change_set.py index a3ab87e1..b502bf29 100644 --- a/pydriller/metrics/process/change_set.py +++ b/pydriller/metrics/process/change_set.py @@ -15,9 +15,12 @@ class ChangeSet(ProcessMetric): """ def __init__(self, path_to_repo: str, - from_commit: str, - to_commit: str): - super().__init__(path_to_repo, from_commit, to_commit) + since = None, + to = None, + from_commit: str = None, + to_commit: str = None): + + super().__init__(path_to_repo, since=since, to=to, from_commit=from_commit, to_commit=to_commit) self._initialize() def _initialize(self): diff --git a/pydriller/metrics/process/code_churn.py b/pydriller/metrics/process/code_churn.py index c46ac49c..3740eee5 100644 --- a/pydriller/metrics/process/code_churn.py +++ b/pydriller/metrics/process/code_churn.py @@ -19,9 +19,12 @@ class CodeChurn(ProcessMetric): """ def __init__(self, path_to_repo: str, - from_commit: str, - to_commit: str): - super().__init__(path_to_repo, from_commit, to_commit) + since = None, + to = None, + from_commit: str = None, + to_commit: str = None): + + super().__init__(path_to_repo, since=since, to=to, from_commit=from_commit, to_commit=to_commit) self._initialize() def _initialize(self): diff --git a/pydriller/metrics/process/contributors_count.py b/pydriller/metrics/process/contributors_count.py index e55b4dc0..ee43aecb 100644 --- a/pydriller/metrics/process/contributors_count.py +++ b/pydriller/metrics/process/contributors_count.py @@ -20,9 +20,12 @@ class ContributorsCount(ProcessMetric): """ def __init__(self, path_to_repo: str, - from_commit: str, - to_commit: str): - super().__init__(path_to_repo, from_commit, to_commit) + since = None, + to = None, + from_commit: str = None, + to_commit: str = None): + + super().__init__(path_to_repo, since=since, to=to, from_commit=from_commit, to_commit=to_commit) self._initialize() def _initialize(self): diff --git a/pydriller/metrics/process/lines_count.py b/pydriller/metrics/process/lines_count.py index 77c59a7e..13dd0aa3 100644 --- a/pydriller/metrics/process/lines_count.py +++ b/pydriller/metrics/process/lines_count.py @@ -34,9 +34,12 @@ class LinesCount(ProcessMetric): """ def __init__(self, path_to_repo: str, - from_commit: str, - to_commit: str): - super().__init__(path_to_repo, from_commit, to_commit) + since = None, + to = None, + from_commit: str = None, + to_commit: str = None): + + super().__init__(path_to_repo, since=since, to=to, from_commit=from_commit, to_commit=to_commit) self._initialize() def _initialize(self): diff --git a/pydriller/metrics/process/process_metric.py b/pydriller/metrics/process/process_metric.py index d35ec402..c38af6f0 100644 --- a/pydriller/metrics/process/process_metric.py +++ b/pydriller/metrics/process/process_metric.py @@ -2,6 +2,7 @@ This module contains the abstract class to implement process metrics. """ +from datetime import datetime from pydriller import RepositoryMining class ProcessMetric: @@ -10,22 +11,35 @@ class ProcessMetric: """ def __init__(self, path_to_repo: str, - from_commit: str, - to_commit: str): + since: datetime = None, + to: datetime = None, + from_commit: str = None, + to_commit: str = None): """ :path_to_repo: path to a single repo - :to_commit: the SHA of the commit to stop counting. If None, the - analysis starts from the latest commit - :from_commit: the SHA of the commit to start counting. If None, the - analysis ends to the first commit + + :param datetime since: starting date + + :param datetime to: ending date + + :param str from_commit: starting commit (only if `since` is None) + + :param str to_commit: ending commit (only if `to` is None) """ - if not from_commit or not to_commit: - raise TypeError - self.repo_miner = RepositoryMining(path_to_repo, single=from_commit) + if not since and not from_commit: + raise TypeError('You must pass one between since and from_commit') + + if not to and not to_commit: + raise TypeError('You must pass one between to and to_commit') + + if from_commit and to_commit and from_commit == to_commit: # Use 'single' param to avoid Warning + self.repo_miner = RepositoryMining(path_to_repo, single=from_commit) - if from_commit != to_commit: + else: self.repo_miner = RepositoryMining(path_to_repo=path_to_repo, + since=since, + to=to, from_commit=from_commit, to_commit=to_commit, order='reverse') diff --git a/tests/metrics/process/test_change_set.py b/tests/metrics/process/test_change_set.py index dbe51e82..9ea893aa 100644 --- a/tests/metrics/process/test_change_set.py +++ b/tests/metrics/process/test_change_set.py @@ -1,4 +1,5 @@ import pytest +from datetime import datetime from pydriller.metrics.process.change_set import ChangeSet TEST_DATA = [ @@ -6,7 +7,7 @@ ] @pytest.mark.parametrize('path_to_repo, from_commit, to_commit, expected_max, expected_avg', TEST_DATA) -def test(path_to_repo, from_commit, to_commit, expected_max, expected_avg): +def test_with_commits(path_to_repo, from_commit, to_commit, expected_max, expected_avg): metric = ChangeSet(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -16,3 +17,20 @@ def test(path_to_repo, from_commit, to_commit, expected_max, expected_avg): assert actual_max == expected_max assert actual_avg == expected_avg + + +TEST_DATA = [ + ('test-repos/pydriller', datetime(2018, 3, 21), datetime(2018, 3, 27), 13, 8) +] + +@pytest.mark.parametrize('path_to_repo, since, to, expected_max, expected_avg', TEST_DATA) +def test_with_dates(path_to_repo, since, to, expected_max, expected_avg): + metric = ChangeSet(path_to_repo=path_to_repo, + since=since, + to=to) + + actual_max = metric.max() + actual_avg = metric.avg() + + assert actual_max == expected_max + assert actual_avg == expected_avg diff --git a/tests/metrics/process/test_code_churn.py b/tests/metrics/process/test_code_churn.py index 9010c787..2eb2782e 100644 --- a/tests/metrics/process/test_code_churn.py +++ b/tests/metrics/process/test_code_churn.py @@ -1,5 +1,8 @@ -import pytest from pathlib import Path +from datetime import datetime + +import pytest + from pydriller.metrics.process.code_churn import CodeChurn TEST_DATA = [ @@ -7,7 +10,7 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg): metric = CodeChurn(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -21,3 +24,25 @@ def test(path_to_repo, filepath, from_commit, to_commit, expected_count, expecte assert actual_count[filepath] == expected_count assert actual_max[filepath] == expected_max assert actual_avg[filepath] == expected_avg + + +TEST_DATA = [ + ('test-repos/pydriller', 'domain/commit.py', datetime(2018, 3, 21), datetime(2018, 3, 27), 47, 34, 16) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg): + metric = CodeChurn(path_to_repo=path_to_repo, + since=since, + to=to) + + actual_count = metric.count() + actual_max = metric.max() + actual_avg = metric.avg() + + filepath = str(Path(filepath)) + + assert actual_count[filepath] == expected_count + assert actual_max[filepath] == expected_max + assert actual_avg[filepath] == expected_avg + diff --git a/tests/metrics/process/test_commits_count.py b/tests/metrics/process/test_commits_count.py index 55feb42b..c30f88da 100644 --- a/tests/metrics/process/test_commits_count.py +++ b/tests/metrics/process/test_commits_count.py @@ -1,4 +1,5 @@ from pathlib import Path +from datetime import datetime import pytest @@ -9,13 +10,26 @@ ('test-repos/pydriller', 'domain/developer.py', 'ab36bf45859a210b0eae14e17683f31d19eea041', 'fdf671856b260aca058e6595a96a7a0fba05454b', 2) ] - @pytest.mark.parametrize('path_to_repo, filepath, from_commit, ' 'to_commit, expected', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected): metric = CommitsCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) count = metric.count() filepath = str(Path(filepath)) assert count[filepath] == expected + + +TEST_DATA = [ + ('test-repos/pydriller', 'domain/developer.py', datetime(2018, 3, 21), datetime(2018, 3, 23), 2) +] +@pytest.mark.parametrize('path_to_repo, filepath, since, ' + 'to, expected', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected): + metric = CommitsCount(path_to_repo=path_to_repo, + since=since, + to=to) + count = metric.count() + filepath = str(Path(filepath)) + assert count[filepath] == expected diff --git a/tests/metrics/process/test_contributors_count.py b/tests/metrics/process/test_contributors_count.py index ad43bd52..1f722616 100644 --- a/tests/metrics/process/test_contributors_count.py +++ b/tests/metrics/process/test_contributors_count.py @@ -1,4 +1,5 @@ from pathlib import Path +from datetime import datetime import pytest @@ -10,7 +11,7 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected): metric = ContributorsCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -18,3 +19,18 @@ def test(path_to_repo, filepath, from_commit, to_commit, expected): count = metric.count() filepath = str(Path(filepath)) assert count[filepath] == expected + +TEST_DATA = [ + ('test-repos/pydriller', 'pydriller/git_repository.py', datetime(2019, 12, 17), datetime(2019, 12, 24), 2), + ('test-repos/pydriller', 'domain/modification.py', datetime(2018, 3, 21), datetime(2018, 3, 27), 1) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected): + metric = ContributorsCount(path_to_repo=path_to_repo, + since=since, + to=to) + + count = metric.count() + filepath = str(Path(filepath)) + assert count[filepath] == expected diff --git a/tests/metrics/process/test_contributors_experience_count.py b/tests/metrics/process/test_contributors_experience_count.py index f343cdf9..a74d1e91 100644 --- a/tests/metrics/process/test_contributors_experience_count.py +++ b/tests/metrics/process/test_contributors_experience_count.py @@ -1,4 +1,5 @@ from pathlib import Path +from datetime import datetime import pytest @@ -12,10 +13,26 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected): metric = ContributorsExperience(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) count = metric.count() filepath = str(Path(filepath)) + assert count[filepath] == expected + + +TEST_DATA = [ + ('test-repos/pydriller', 'domain/modification.py', datetime(2018, 3, 21), datetime(2018, 3, 23), 100.0), + ('test-repos/pydriller', 'pydriller/git_repository.py', datetime(2018, 8, 1), datetime(2018, 8, 2), 100.0), + ('test-repos/pydriller', 'pydriller/git_repository.py', datetime(2018, 7, 23), datetime(2018, 8, 2), round(100*28/30, 2)) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected): + metric = ContributorsExperience(path_to_repo=path_to_repo, + since=since, + to=to) + count = metric.count() + filepath = str(Path(filepath)) assert count[filepath] == expected \ No newline at end of file diff --git a/tests/metrics/process/test_history_complexity_count.py b/tests/metrics/process/test_history_complexity_count.py index bd579988..b0ac1b3d 100644 --- a/tests/metrics/process/test_history_complexity_count.py +++ b/tests/metrics/process/test_history_complexity_count.py @@ -1,7 +1,7 @@ from pathlib import Path +from datetime import datetime import pytest - from pydriller.metrics.process.history_complexity import HistoryComplexity TEST_DATA = [ @@ -11,7 +11,7 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected): metric = HistoryComplexity(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -19,3 +19,19 @@ def test(path_to_repo, filepath, from_commit, to_commit, expected): count = metric.count() filepath = str(Path(filepath)) assert count[filepath] == expected + + +TEST_DATA = [ + ('test-repos/pydriller', 'scm/git_repository.py', datetime(2018, 3, 22, 11, 30), datetime(2018, 3, 23), 40.49), + ('test-repos/pydriller', 'scm/git_repository.py', datetime(2018, 3, 22, 11, 30), datetime(2018, 3, 27), 47.05), +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected): + metric = HistoryComplexity(path_to_repo=path_to_repo, + since=since, + to=to) + + count = metric.count() + filepath = str(Path(filepath)) + assert count[filepath] == expected diff --git a/tests/metrics/process/test_hunks_count.py b/tests/metrics/process/test_hunks_count.py index 44319b46..d8f6175b 100644 --- a/tests/metrics/process/test_hunks_count.py +++ b/tests/metrics/process/test_hunks_count.py @@ -1,4 +1,5 @@ from pathlib import Path +from datetime import datetime import pytest @@ -11,11 +12,27 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected): metric = HunksCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) - + count = metric.count() filepath = str(Path(filepath)) assert count[filepath] == expected + +TEST_DATA = [ + ('test-repos/pydriller', 'scm/git_repository.py', datetime(2018, 3, 26), datetime(2018, 3, 27), 8), + ('test-repos/pydriller', 'scm/git_repository.py', datetime(2018, 3, 21), datetime(2018, 3, 27), 3), + ('test-repos/pydriller', 'domain/modification.py', datetime(2018, 3, 21), datetime(2018, 3, 22, 23), 1) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected): + metric = HunksCount(path_to_repo=path_to_repo, + since=since, + to=to) + + count = metric.count() + filepath = str(Path(filepath)) + assert count[filepath] == expected \ No newline at end of file diff --git a/tests/metrics/process/test_lines_added.py b/tests/metrics/process/test_lines_added.py index 3a283075..19c69b04 100644 --- a/tests/metrics/process/test_lines_added.py +++ b/tests/metrics/process/test_lines_added.py @@ -1,5 +1,8 @@ -import pytest from pathlib import Path +from datetime import datetime + +import pytest + from pydriller.metrics.process.lines_count import LinesCount TEST_DATA = [ @@ -8,7 +11,7 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg): metric = LinesCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -22,3 +25,24 @@ def test(path_to_repo, filepath, from_commit, to_commit, expected_count, expecte assert actual_count[filepath] == expected_count assert actual_max[filepath] == expected_max assert actual_avg[filepath] == expected_avg + +TEST_DATA = [ + ('test-repos/pydriller', '.gitignore', datetime(2018, 3, 21), datetime(2018, 3, 22), 197, 197, 197), + ('test-repos/pydriller', 'domain/modification.py', datetime(2018, 3, 21), datetime(2018, 3, 27), 61, 48, 20) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg): + metric = LinesCount(path_to_repo=path_to_repo, + since=since, + to=to) + + actual_count = metric.count_added() + actual_max = metric.max_added() + actual_avg = metric.avg_added() + + filepath = str(Path(filepath)) + + assert actual_count[filepath] == expected_count + assert actual_max[filepath] == expected_max + assert actual_avg[filepath] == expected_avg diff --git a/tests/metrics/process/test_lines_count.py b/tests/metrics/process/test_lines_count.py index 8abdf50b..5b27e874 100644 --- a/tests/metrics/process/test_lines_count.py +++ b/tests/metrics/process/test_lines_count.py @@ -1,5 +1,8 @@ -import pytest from pathlib import Path +from datetime import datetime + +import pytest + from pydriller.metrics.process.lines_count import LinesCount TEST_DATA = [ @@ -8,7 +11,7 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected_count', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected_count): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected_count): metric = LinesCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -17,3 +20,19 @@ def test(path_to_repo, filepath, from_commit, to_commit, expected_count): filepath = str(Path(filepath)) assert actual_count[filepath] == expected_count + +TEST_DATA = [ + ('test-repos/pydriller', '.gitignore', datetime(2018, 3, 21), datetime(2018, 3, 22), 197), + ('test-repos/pydriller', 'domain/modification.py', datetime(2018, 3, 21), datetime(2018, 3, 27), 65) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected_count', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected_count): + metric = LinesCount(path_to_repo=path_to_repo, + since=since, + to=to) + + actual_count = metric.count() + filepath = str(Path(filepath)) + + assert actual_count[filepath] == expected_count \ No newline at end of file diff --git a/tests/metrics/process/test_lines_removed.py b/tests/metrics/process/test_lines_removed.py index e11cdc1b..216a47f4 100644 --- a/tests/metrics/process/test_lines_removed.py +++ b/tests/metrics/process/test_lines_removed.py @@ -1,5 +1,8 @@ -import pytest from pathlib import Path +from datetime import datetime + +import pytest + from pydriller.metrics.process.lines_count import LinesCount TEST_DATA = [ @@ -8,7 +11,7 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected_count, expected_max, expected_avg): metric = LinesCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) @@ -22,3 +25,24 @@ def test(path_to_repo, filepath, from_commit, to_commit, expected_count, expecte assert actual_count[filepath] == expected_count assert actual_max[filepath] == expected_max assert actual_avg[filepath] == expected_avg + +TEST_DATA = [ + ('test-repos/pydriller', '.gitignore', datetime(2018, 3, 21), datetime(2018, 3, 22), 0, 0, 0), + ('test-repos/pydriller', 'domain/modification.py', datetime(2018, 3, 21), datetime(2018, 3, 27), 4, 3, 1) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected_count, expected_max, expected_avg): + metric = LinesCount(path_to_repo=path_to_repo, + since=since, + to=to) + + actual_count = metric.count_removed() + actual_max = metric.max_removed() + actual_avg = metric.avg_removed() + + filepath = str(Path(filepath)) + + assert actual_count[filepath] == expected_count + assert actual_max[filepath] == expected_max + assert actual_avg[filepath] == expected_avg \ No newline at end of file diff --git a/tests/metrics/process/test_minor_contributors_count.py b/tests/metrics/process/test_minor_contributors_count.py index 65d40fae..32912e30 100644 --- a/tests/metrics/process/test_minor_contributors_count.py +++ b/tests/metrics/process/test_minor_contributors_count.py @@ -1,4 +1,5 @@ from pathlib import Path +from datetime import datetime import pytest @@ -11,10 +12,28 @@ ] @pytest.mark.parametrize('path_to_repo, filepath, from_commit, to_commit, expected', TEST_DATA) -def test(path_to_repo, filepath, from_commit, to_commit, expected): +def test_with_commits(path_to_repo, filepath, from_commit, to_commit, expected): metric = ContributorsCount(path_to_repo=path_to_repo, from_commit=from_commit, to_commit=to_commit) + + count = metric.count_minor() + filepath = str(Path(filepath)) + assert count[filepath] == expected + + +TEST_DATA = [ + ('test-repos/pydriller', 'pydriller/git_repository.py', datetime(2018, 8, 1), datetime(2018, 8, 2), 0), + ('test-repos/pydriller', 'pydriller/git_repository.py', datetime(2018, 3, 21), datetime(2018, 8, 2), 1), + ('test-repos/pydriller', 'pydriller/git_repository.py', datetime(2018, 3, 21), datetime(2019, 1, 14, 10), 2) +] + +@pytest.mark.parametrize('path_to_repo, filepath, since, to, expected', TEST_DATA) +def test_with_dates(path_to_repo, filepath, since, to, expected): + metric = ContributorsCount(path_to_repo=path_to_repo, + since=since, + to=to) + count = metric.count_minor() filepath = str(Path(filepath)) assert count[filepath] == expected diff --git a/tests/metrics/process/test_process_metric.py b/tests/metrics/process/test_process_metric.py new file mode 100644 index 00000000..fd928dbf --- /dev/null +++ b/tests/metrics/process/test_process_metric.py @@ -0,0 +1,22 @@ +import pytest + +from datetime import datetime +from pydriller.metrics.process.process_metric import ProcessMetric + +dt1 = datetime(2016, 10, 8, 17, 0, 0) +dt2 = datetime(2016, 10, 8, 17, 59, 0) + +TEST_DATA = [ + ('test-repos/pydriller', None, dt2, None, '81ddf7e78d92f3aaa212d5924d1ae0ed1fd980e6'), # Test (if not since and not from_commit) + ('test-repos/pydriller', dt1, None, 'ab36bf45859a210b0eae14e17683f31d19eea041', None) # Test (if not to and not to_commit) +] + +@pytest.mark.parametrize('path_to_repo, since, to, from_commit, to_commit', TEST_DATA) +def test_type_error(path_to_repo, since, to, from_commit, to_commit): + + with pytest.raises(TypeError): + ProcessMetric(path_to_repo=path_to_repo, + since=since, + to=to, + from_commit=from_commit, + to_commit=to_commit)