def test_metric_formatter_with_negative_ci_flip_color(self):
     expected = LINE_BREAK.join((
         '<div class="ci-display-good-change ci-display-cell"><div>1.2000',
         '<span class="ci-display-ratio">-1.1000</span>',
         '<span class="ci-display-ci-range">[-1.0200, -1.1800]</span></div>'
         '</div>'))
     actual = confidence_interval_display.MetricFormatter(
         if_flip_color=True)((1.2, -1.1, -1.02, -1.18))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_positive_ci(self):
     expected = LINE_BREAK.join((
         '<div class="ci-display-good-change ci-display-cell"><div>1.2000',
         '<span class="ci-display-ratio">1.1000</span>',
         '<span class="ci-display-ci-range">[1.0200, 1.1800]</span></div></div>'
     ))
     actual = confidence_interval_display.MetricFormatter()(
         (1.2, 1.1, 1.02, 1.18))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_na_cis(self):
     expected = LINE_BREAK.join((
         '<div class="ci-display-cell"><div>24.44%',
         '<span class="ci-display-ratio">1.2000</span>',
         '<span class="ci-display-ci-range">[N/A, N/A]</span></div></div>'))
     formats = {'Ratio': 'absolute', 'Value': 'percent'}
     actual = confidence_interval_display.MetricFormatter(formats)(
         (0.24444, 1.2, None, None))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_custom_formatting(self):
     expected = LINE_BREAK.join((
         '<div class="ci-display-good-change ci-display-cell"><div>constant',
         '<span class="ci-display-ratio">1</span>',
         '<span class="ci-display-ci-range">[1, 1]</span></div></div>'))
     formats = {'Ratio': '{:.0f}', 'Value': 'constant'}
     actual = confidence_interval_display.MetricFormatter(formats)(
         (0.24444, 1.2, 1, 1.4))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_no_value(self):
     expected = LINE_BREAK.join(
         ('<div class="ci-display-good-change ci-display-cell"><div>'
          '<div>-</div>', '<span class="ci-display-ratio">1.2000</span>',
          '<span class="ci-display-ci-range">[1.0000, 1.4000]</span></div>'
          '</div>'))
     actual = confidence_interval_display.MetricFormatter()(
         (None, 1.2, 1, 1.4))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_percentage_value_and_pp_ratio(self):
     expected = LINE_BREAK.join((
         '<div class="ci-display-good-change ci-display-cell"><div>24.44%',
         '<span class="ci-display-ratio">1.20pp</span>',
         '<span class="ci-display-ci-range">[1.00, 1.40] pp</span></div></div>'
     ))
     formats = {'Ratio': 'pp', 'Value': 'percent'}
     actual = confidence_interval_display.MetricFormatter(formats)(
         (0.24444, 1.2, 1, 1.4))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_percentage_value_and_absolute_ratio(self):
     expected = (
         '<div class="ci-display-good-change ci-display-cell"><div>'
         '24.44%' + LINE_BREAK +
         '<span class="ci-display-ratio">1.2000</span>' + LINE_BREAK +
         '<span class="ci-display-ci-range">[1.0000, 1.4000]</span>' +
         '</div></div>')
     formats = {'Ratio': 'absolute', 'Value': 'percent'}
     actual = confidence_interval_display.MetricFormatter(formats)(
         (0.24444, 1.2, 1, 1.4))
     self.assertEqual(expected, actual)
 def test_metric_formatter_with_no_ratio(self):
     expected = '<div class="ci-display-cell">1.2000</div>'
     actual = confidence_interval_display.MetricFormatter()(
         (1.2, None, None, None))
     self.assertEqual(expected, actual)