This repository has been archived by the owner on Dec 10, 2020. It is now read-only.
forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up junit xml report file location logic.
This introduces a backport of itertools.accumulate and then uses it to make the logic of scanning from more specific nested class report files to less specific (containing class) ones a bit more coherent. Testing Done: Locally green: ``` ./pants test \ tests/python/pants_test/util:iterators \ tests/python/pants_test/backend/jvm/tasks:junit_run \ tests/python/pants_test/backend/jvm/tasks:junit_run_integration \ tests/python/pants_test/backend/jvm/tasks:junit_tests_concurrency_integration \ tests/python/pants_test/backend/jvm/tasks:junit_tests_integration ``` CI went green here: https://travis-ci.org/pantsbuild/pants/builds/158514392 Bugs closed: 3837, 3844 Reviewed at https://rbcommons.com/s/twitter/r/4211/
- Loading branch information
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# coding=utf-8 | ||
# Copyright 2016 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
|
||
try: | ||
from itertools import accumulate # Present in python3 stdlib. | ||
except ImportError: | ||
import operator | ||
|
||
|
||
def accumulate(items, func=operator.add): | ||
"""Reduce items yielding the initial item and then each reduced value after that. | ||
:param items: A possibly empty iterable. | ||
:param func: A binary operator that can combine items. | ||
:returns: An iterator over the first item if any and subsequent applications of `func` to the | ||
running "total". | ||
""" | ||
iterator = iter(items) | ||
try: | ||
total = next(iterator) | ||
except StopIteration: | ||
return # The items iterable is empty.` | ||
yield total | ||
for item in iterator: | ||
total = func(total, item) | ||
yield total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# coding=utf-8 | ||
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import (absolute_import, division, generators, nested_scopes, print_function, | ||
unicode_literals, with_statement) | ||
|
||
import unittest | ||
|
||
from pants.util.iterators import accumulate | ||
|
||
|
||
class AccumulateTest(unittest.TestCase): | ||
def test_empty(self): | ||
self.assertEqual([], list(accumulate(()))) | ||
|
||
def test_single(self): | ||
self.assertEqual([42], list(accumulate((42,)))) | ||
|
||
def test_nominal(self): | ||
self.assertEqual([1, 2, 3], list(accumulate((1, 1, 1)))) | ||
|
||
def test_heterogeneous(self): | ||
self.assertEqual([1, '11', '111'], list(accumulate((1, 1, 1), | ||
func=lambda x, y: str(x) + str(y)))) |