Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove formatter function from percentage diff evaluation #1347

Merged
merged 2 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion esrally/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ def _safe_divide(n, d):
color_neutral = console.format.neutral

if as_percentage:
diff = formatter(_safe_divide(contender - baseline, baseline) * 100.0)
diff = _safe_divide(contender - baseline, baseline) * 100.0
precision = 2
suffix = "%"
else:
Expand Down
21 changes: 19 additions & 2 deletions tests/reporter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# pylint: disable=protected-access
Copy link
Contributor Author

Choose a reason for hiding this comment

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

saw this elsewhere, adopted here rather than making _diff() public


from unittest import TestCase
from unittest import TestCase, mock

from esrally import reporter
from esrally import config, reporter
from esrally.utils import convert


class FormatterTests(TestCase):
Expand Down Expand Up @@ -50,3 +52,18 @@ def test_formats_as_csv(self):
formatted = reporter.format_as_csv(self.metrics_header, self.metrics_data)
# 1 header line, no separation line + 3 data lines
self.assertEqual(1 + 3, len(formatted.splitlines()))


class ComparisonReporterTests(TestCase):
def setUp(self):
config_mock = mock.Mock(config.Config)
config_mock.opts.return_value = True
self.reporter = reporter.ComparisonReporter(config_mock)

def test_diff_percent_divide_by_zero(self):
formatted = self.reporter._diff(0, 0, False, as_percentage=True)
self.assertEqual("0.00%", formatted)

def test_diff_percent_ignore_formatter(self):
formatted = self.reporter._diff(1, 0, False, formatter=convert.factor(100.0), as_percentage=True)
self.assertEqual("-100.00%", formatted)