Пример #1
0
 def test_pt_real(self):
     ''' Verifica se a formatação de real em pt_br está correta '''
     fmt = NumberFormatter.format(53.481, {
         "format": 'real',
         "str_locale": 'pt_br'
     })
     self.assertEqual(fmt, "53")
Пример #2
0
 def test_pt_inteiro(self):
     ''' Verifica se a formatação de inteiro em pt_br está correta '''
     fmt = NumberFormatter.format(2019, {
         "format": 'inteiro',
         "str_locale": 'pt_br'
     })
     self.assertEqual(fmt, "2.019")
Пример #3
0
 def test_pt_percentual(self):
     ''' Verifica se a formatação de percentual em pt_br está correta '''
     fmt = NumberFormatter.format(53.481, {
         "format": 'porcentagem',
         "str_locale": 'pt_br'
     })
     self.assertEqual(fmt, "53,5<span>%</span>")
Пример #4
0
 def test_dinheiro_pt_no_precision(self):
     ''' Verifica se a formatação de dinheiro com precisão em pt_br está correta '''
     fmt = NumberFormatter.format(53481.583, {
         "format": 'monetario',
         "str_locale": 'pt_br',
         "precision": 1
     })
     self.assertEqual(fmt, "<span>R$</span>53.481,6")
Пример #5
0
 def test_suffix_collapse_no_tags(self):
     ''' Verifica se retorna os sufixos corretamente - collapsed with no tags'''
     (_valor, suffix_string,
      _order_magnitude) = NumberFormatter.get_value_suffix(
          10000, 'inteiro', {
              "format": 'real',
              "precision": 1,
              "uiTags": False
          }, True)
     self.assertEqual(suffix_string, 'mil')
Пример #6
0
 def get_formatted_value(structure, data_collection):
     ''' Gets the formatted value '''
     if (structure['base_object'] in data_collection
             and data_collection[structure['base_object']] is not None):
         fmt_arg = data_collection[structure['base_object']][
             structure['named_prop']]
         if 'format' in structure:
             fmt_arg = NumberFormatter.format(fmt_arg, structure)
         return fmt_arg
     return "N/D"
Пример #7
0
 def test_pt_collapsed(self):
     ''' Verifica se a formatação de número colapsado em pt_br está correta '''
     fmt = NumberFormatter.format(
         53481, {
             "format": 'real',
             "collapse": {
                 "format": "real"
             },
             "str_locale": 'pt_br'
         })
     self.assertEqual(fmt, "53,5<span>mil</span>")
Пример #8
0
 def test_pt_collapsed_no_tags(self):
     ''' Verifica se a formatação de número colapsado em pt_br está correta '''
     fmt = NumberFormatter.format(
         53481, {
             "format": 'real',
             "collapse": {
                 "format": "real",
                 "uiTags": False
             },
             "str_locale": 'pt_br'
         })
     self.assertEqual(fmt, "53,5mil")
Пример #9
0
 def test_integer_after_collapse_with_collapse(self):
     ''' Verifica se a avaliação de valor inteiro funciona após o collapse '''
     self.assertTrue(
         NumberFormatter.is_integer_after_collapse(
             'real',
             10000,
             10.0,
             1,
             {
                 "format": 'real',
                 "precision": 1,
                 "uiTags": False
             },
         ))
Пример #10
0
    def test_custom_options(self):
        ''' Verifica se retorna os parâmetros customizados corretamente '''
        (precision, multiplier, collapse, str_locale, _n_format,
         ui_tags) = NumberFormatter.load_defaults({
             "precision": 4,
             "multiplier": 5,
             "collapse": True,
             "str_locale": "en",
             "uiTags": False,
             "format": "real"
         })

        self.assertEqual(precision, 4)
        self.assertEqual(multiplier, 5)
        self.assertEqual(collapse, True)
        self.assertEqual(str_locale, "en")
        self.assertEqual(ui_tags, False)
Пример #11
0
    def run_formatters(each_obj_struct, each_obj):
        ''' Runs formatters from config '''
        for each_fmt in each_obj_struct:
            args = {'format': each_fmt['format']}
            if 'precision' in each_fmt:
                args['precision'] = each_fmt['precision']
            if 'multiplier' in each_fmt:
                args['multiplier'] = int(each_fmt['multiplier'])
            else:
                args['multiplier'] = 1
            if 'collapse' in each_fmt:
                args['collapse'] = each_fmt['collapse']
            else:
                args['collapse'] = None
            if 'default' in each_fmt:
                args['default'] = each_fmt['default']

            # Creates formatted column by applying number format method
            # in the declared named_prop
            each_obj['dataset'][each_fmt['prop']] = [
                NumberFormatter.format(row[each_fmt['named_prop']], args)
                for index, row in each_obj['dataset'].iterrows()
            ]
        return each_obj
Пример #12
0
 def test_no_valor_with_no_default(self):
     ''' Verifica se retorna '-' quando não há nem valor nem default '''
     fmt = NumberFormatter.format(None, {})
     self.assertEqual(fmt, "-")
Пример #13
0
 def test_monetario_no_tags(self):
     ''' Verifica se retorna 'R$' no prefixo quando não houver tag '''
     prefix = NumberFormatter.get_unit_prefix('monetario', False)
     self.assertEqual(prefix, 'R$')
Пример #14
0
 def test_multiplying_string(self):
     ''' Verifica se multiplica corretamente quando os parâmetros são strings '''
     fmt = NumberFormatter.apply_multiplier('2', '2')
     self.assertEqual(fmt, 4)
Пример #15
0
 def test_suffix_percent_no_tags(self):
     ''' Verifica se retorna os sufixos corretamente - percentual sem tag '''
     (_valor, suffix_string,
      _order_magnitude) = NumberFormatter.get_value_suffix(
          98.76, 'porcentagem', {}, False)
     self.assertEqual(suffix_string, '%')
Пример #16
0
 def test_valid_int_value_as_string(self):
     ''' Verifica se retorna o valor da string inteira convertido para float '''
     fmt = NumberFormatter.validate("53481")
     self.assertEqual(fmt, 53481.0)
Пример #17
0
 def test_valor_with_no_format(self):
     ''' Verifica se retorna o próprio valor quando não há definição de formato '''
     fmt = NumberFormatter.format(99, {})
     self.assertEqual(fmt, 99)
Пример #18
0
 def test_validate_as_is(self):
     ''' Verifica se retorna o mesmo valor se for algo válido '''
     num = 12.34
     self.assertEqual(NumberFormatter.validate(num), num)
Пример #19
0
 def test_no_valor_with_default(self):
     ''' Verifica se retorna default quando não há valor '''
     fmt = NumberFormatter.format(None, {"default": "N/A"})
     self.assertEqual(fmt, "N/A")