Esempio n. 1
0
    def test_format_number(self):
        cases = [
            ((1000, 'C'), '1000'),
            ((1000, US_LOCALE), '1,000'),
        ]
        for (num, loc), expected in cases:
            with self.subTest(num=num, loc=loc):
                with utils.changing_locale(loc):
                    actual = utils.format_number(num)

                self.assertEqual(actual, expected)
Esempio n. 2
0
    def test_format_number__locale_de_DE(self):
        """
        Test a locale where the thousands separator is a period.

        This doesn't work on Mac OS X for some reason.  More generally,
        it's only guaranteed to work in our Docker container because we're
        able to configure that environment correctly by installing the
        needed locale.
        """
        num, loc, expected = 1000, 'de_DE.UTF-8', '1.000'

        with utils.changing_locale(loc):
            actual = utils.format_number(num)

        self.assertEqual(actual, expected)
def format_choice_totals(choice_totals):
    new_rows = []
    for row in choice_totals:
        iterator = iter(row)
        new_row = [next(iterator)]
        while True:
            try:
                total = next(iterator)
            except StopIteration:
                break

            total = utils.format_number(total)
            new_row.append(total)

            percent = next(iterator)
            percent = utils.format_percent(percent)
            new_row.append(percent)

        new_rows.append(new_row)

    return new_rows
Esempio n. 4
0
    def detail_rows(self, choice_stat_idlist, reporting_groups=None):
        """
        Yield rows of vote stat and choice values for the given reporting
        groups.

        Args:
          reporting_groups: an iterable of ReportingGroup objects.  Defaults
            to all of the contest's reporting groups.
        """
        if reporting_groups is None:
            reporting_groups = self.reporting_groups

        self.load_results_details()

        results_mapping = self.results_mapping
        indices = results_mapping.get_indexes_by_id_list(choice_stat_idlist)

        results = self.results
        for rg in reporting_groups:
            results_row = results[rg.index]
            row = [rg.display()]
            row.extend(utils.format_number(results_row[i]) for i in indices)

            yield row