Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions numba/testing/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,18 @@ def _getParentArgParser(self):
parser.add_argument('-j', '--slice', dest='useslice', nargs='?',
type=str, const="None",
help='Slice the test sequence')
parser.add_argument('-g', '--gitdiff', dest='gitdiff',
action='store_true',

def git_diff_str(x):
if x != 'ancestor':
raise ValueError("invalid option for --gitdiff")
return x

parser.add_argument('-g', '--gitdiff', dest='gitdiff', type=git_diff_str,
default=False, nargs='?',
help=('Run tests from changes made against '
'origin/master as identified by `git diff`'))
'origin/master as identified by `git diff`. '
'If set to "ancestor", the diff compares '
'against the common ancestor.'))
return parser

def _handle_tags(self, argv, tagstr):
Expand Down Expand Up @@ -266,8 +274,11 @@ def parseArgs(self, argv):
self.test = _choose_random_tests(self.test, self.random_select,
self.random_seed)

if self.gitdiff:
self.test = _choose_gitdiff_tests(self.test)
if self.gitdiff is not False:
self.test = _choose_gitdiff_tests(
self.test,
use_common_ancestor=(self.gitdiff == 'ancestor'),
)

if self.verbosity <= 0:
# We aren't interested in informational messages / warnings when
Expand Down Expand Up @@ -379,14 +390,18 @@ def key(x):
return tests


def _choose_gitdiff_tests(tests):
def _choose_gitdiff_tests(tests, *, use_common_ancestor=False):
try:
from git import Repo
except ImportError:
raise ValueError("gitpython needed for git functionality")
repo = Repo('.')
path = os.path.join('numba', 'tests')
>
if use_common_ancestor:
print(f"Git diff by common ancestor")
>
else:
>
gdiff_paths = repo.git.diff(target, path, name_only=True).split()
# normalise the paths as they are unix style from repo.git.diff
gdiff_paths = [os.path.normpath(x) for x in gdiff_paths]
Expand Down
17 changes: 17 additions & 0 deletions numba/tests/test_runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,23 @@ def filter_test(xs):
# The tests must be equivalent
self.assertEqual(sorted(full), sorted(sliced))

def test_gitdiff(self):
# Check for git
try:
subprocess.call("git", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
except FileNotFoundError as e:
self.skipTest("no git available")

# default
outs = self.get_testsuite_listing(['-g'])
self.assertNotIn("Git diff by common ancestor", outs)
# using ancestor
outs = self.get_testsuite_listing(['-g=ancestor'])
self.assertIn("Git diff by common ancestor", outs)
# misspelled ancestor
with self.assertRaises(subprocess.CalledProcessError):
self.get_testsuite_listing(['-g=ancest'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds noise to the test output as the error streams aren't captured/redirected?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i'll sink it to devnull



if __name__ == '__main__':
unittest.main()