def test_normal_number_0(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [0, -1.234, 55.55]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 3
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == 6

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 2

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 3

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert text_type(col_dp) == (
            "type=REAL_NUMBER, align=right, ascii_width=6, "
            "int_digits=(min=1, max=2), decimal_places=(min=0, max=3), "
            "extra_len=(min=0, max=1)"
        )
    def test_normal_mix_ansi_escape(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [
            colored(0, "red"),
            colored(-1.234, "yellow"),
            colored(55.55, "green"),
            colored("abcdefg", "blue"),
        ]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places == 3
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == 7

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 2

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 3

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert text_type(col_dp) == (
            "type=STRING, align=left, ascii_width=7, "
            "int_digits=(min=1, max=2), decimal_places=(min=0, max=3), "
            "extra_len=(min=0, max=1)"
        )
    def test_normal_number_ansi_escape(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [colored(1, "red"), colored(2.2, "green"), colored(-3, "blue")]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 1
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == 4

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 1

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 1

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert text_type(col_dp) == (
            "type=REAL_NUMBER, align=right, ascii_width=4, "
            "int_digits=1, decimal_places=(min=0, max=1), "
            "extra_len=(min=0, max=1)"
        )
    def test_abnormal_bit_length(self, values, expected):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("dummy"))

        for value in values:
            col_dp.update_body(DataProperty(value))

        assert col_dp.bit_length == expected
    def test_extend_width(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        assert col_dp.ascii_char_width == 3

        col_dp.extend_width(2)

        assert col_dp.ascii_char_width == 5
    def test_normal_typecode_type_class(self, values, expected_typecode, expected_class):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("dummy"))

        for value in values:
            col_dp.update_body(DataProperty(value))

        assert col_dp.typecode == expected_typecode
        assert col_dp.type_class == expected_class
    def test_normal_format(self, values, expected_list):
        col_dp = ColumnDataProperty(format_flags=Format.THOUSAND_SEPARATOR)

        col_dp.update_header(DataProperty("format test"))
        for value in values:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_normal_east_asian_ambiguous_width(self, ambiguous_width, ascii_char_width):
        col_dp = ColumnDataProperty(east_asian_ambiguous_width=ambiguous_width)
        col_dp.update_header(DataProperty("abc"))

        for value in ["ØØØ", "α", "ββ"]:
            col_dp.update_body(DataProperty(value, east_asian_ambiguous_width=ambiguous_width))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places is None
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == ascii_char_width

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0
    def test_normal_number_ansi_escape(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [
                colored(1, "red"),
                colored(2.2, "green"),
                colored(-3, "blue")
        ]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 1
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == 4

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 1

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 1

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert text_type(col_dp) == (
            "type=REAL_NUMBER, align=right, ascii_width=4, "
            "int_digits=1, decimal_places=(min=0, max=1), "
            "extra_len=(min=0, max=1)")
Example #10
0
    def test_normal_multibyte_char(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in ["いろは", "abcde"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert Nan(col_dp.decimal_places).is_type()
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == 6

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert str(col_dp) == (
            "typename=STRING, align=left, ascii_char_width=6, "
            "integer_digits=(min=None, max=None), "
            "decimal_places=(min=None, max=None), "
            "additional_format_len=(min=0, max=0)"
        )
Example #11
0
    def test_normal_inf(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("inf"))

        for value in [inf, None, inf, "inf"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert Nan(col_dp.decimal_places).is_type()
        assert col_dp.typecode == Typecode.INFINITY
        assert col_dp.ascii_char_width == 8

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert str(col_dp) == (
            "typename=INFINITY, align=left, ascii_char_width=8, "
            "integer_digits=(min=None, max=None), "
            "decimal_places=(min=None, max=None), "
            "additional_format_len=(min=0, max=0)")
    def test_min_width(self):
        min_width = 100

        col_dp = ColumnDataProperty(min_width=min_width)
        col_dp.update_header(DataProperty("abc"))

        for value in [0, -1.234, 55.55]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 3
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == min_width

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 2

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 3

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert text_type(col_dp) == (
            "type=REAL_NUMBER, align=right, ascii_width=100, "
            "int_digits=(min=1, max=2), decimal_places=(min=0, max=3), "
            "extra_len=(min=0, max=1)")
Example #13
0
    def test_normal_mix_0(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [0, -1.234, 55.55, "abcdefg"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places == 3
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == 7

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 2

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 3

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert str(col_dp) == (
            "typename=STRING, align=left, ascii_char_width=7, "
            "integer_digits=(min=1, max=2), decimal_places=(min=0, max=3), "
            "additional_format_len=(min=0, max=1)")
Example #14
0
    def test_normal_number_3(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [0.01, 2.2, None]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 2
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == 4

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 1

        assert col_dp.minmax_decimal_places.min_value == 1
        assert col_dp.minmax_decimal_places.max_value == 2

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert str(col_dp) == (
            "typename=REAL_NUMBER, align=right, ascii_char_width=4, "
            "integer_digits=(min=1, max=1), decimal_places=(min=1, max=2), "
            "additional_format_len=(min=0, max=0)")
    def test_normal_mix_ansi_escape(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [
                colored(0, "red"),
                colored(-1.234, "yellow"),
                colored(55.55, "green"),
                colored("abcdefg", "blue"),
        ]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places == 3
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == 7

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 2

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 3

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 1

        assert text_type(col_dp) == (
            "type=STRING, align=left, ascii_width=7, "
            "int_digits=(min=1, max=2), decimal_places=(min=0, max=3), "
            "extra_len=(min=0, max=1)")
    def test_normal_inf(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("inf"))

        for value in [inf, None, inf, "inf"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places is None
        assert col_dp.typecode == Typecode.INFINITY
        assert col_dp.ascii_char_width == 8

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert text_type(col_dp) == ("type=INFINITY, align=left, ascii_width=8")
    def test_normal_multibyte_char(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in ["いろは", "abcde"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places is None
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == 6

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert text_type(col_dp) == ("type=STRING, align=left, ascii_width=6")
    def test_normal_2(self):
        col_dp = ColumnDataProperty()
        values = [1.1, 2.2, 3.33]
        expected_list = ["1.10", "2.20", "3.33"]

        col_dp.update_header(DataProperty("abc"))
        for value in values:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_normal_1(self):
        col_dp = ColumnDataProperty()
        values = [0, 0.1]
        expected_list = ["0", "0.1"]

        col_dp.update_header(DataProperty("abc"))
        for value in ["abcd", "efg"]:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_abnormal_bit_length(self, values, expected):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("dummy"))

        for value in values:
            col_dp.update_body(DataProperty(value))

        assert col_dp.bit_length == expected
Example #21
0
    def test_normal_typecode(self, value_list, expected):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("dummy"))

        for value in value_list:
            col_dp.update_body(DataProperty(value))

        assert col_dp.typecode == expected
    def test_normal_format(self, values, expected_list):
        col_dp = ColumnDataProperty(format_flags=Format.THOUSAND_SEPARATOR)

        col_dp.update_header(DataProperty("format test"))
        for value in values:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_extend_width(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        assert col_dp.ascii_char_width == 3

        col_dp.extend_width(2)

        assert col_dp.ascii_char_width == 5
    def test_normal_number_5(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [1.1, 2.2, 3.33]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 2
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == 4

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 1

        assert col_dp.minmax_decimal_places.min_value == 1
        assert col_dp.minmax_decimal_places.max_value == 2
        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert text_type(col_dp) == (
            "type=REAL_NUMBER, align=right, ascii_width=4, "
            "int_digits=1, decimal_places=(min=1, max=2)"
        )
    def test_normal_typecode_type_class(self, values, expected_typecode,
                                        expected_class):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("dummy"))

        for value in values:
            col_dp.update_body(DataProperty(value))

        assert col_dp.typecode == expected_typecode
        assert col_dp.type_class == expected_class
    def test_normal_0(self):
        col_dp = ColumnDataProperty()
        values = [0.1, 3.4375, 65.5397978633, 189.74439359, 10064.0097539, "abcd"]
        expected_list = ["0.100", "3.437", "65.540", "189.744", "10064.010", "abcd"]

        col_dp.update_header(DataProperty("abc"))
        for value in values:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_normal_1(self):
        col_dp = ColumnDataProperty()
        values = [0, 0.1]
        expected_list = ["0", "0.1"]

        col_dp.update_header(DataProperty("abc"))
        for value in ["abcd", "efg"]:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_normal_2(self):
        col_dp = ColumnDataProperty()
        values = [1.1, 2.2, 3.33]
        expected_list = ["1.10", "2.20", "3.33"]

        col_dp.update_header(DataProperty("abc"))
        for value in values:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_normal_0(self):
        col_dp = ColumnDataProperty()
        values = [
            0.1, 3.4375, 65.5397978633, 189.74439359, 10064.0097539, "abcd"
        ]
        expected_list = [
            "0.100", "3.437", "65.540", "189.744", "10064.010", "abcd"
        ]

        col_dp.update_header(DataProperty("abc"))
        for value in values:
            col_dp.update_body(DataProperty(value))

        for value, expected in zip(values, expected_list):
            assert col_dp.dp_to_str(DataProperty(value)) == expected
    def test_normal_multibyte_char(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in ["いろは", "abcde"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places is None
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == 6

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert text_type(col_dp) == ("type=STRING, align=left, ascii_width=6")
    def test_normal_east_asian_ambiguous_width(self, ambiguous_width,
                                               ascii_char_width):
        col_dp = ColumnDataProperty(east_asian_ambiguous_width=ambiguous_width)
        col_dp.update_header(DataProperty("abc"))

        for value in ["ØØØ", "α", "ββ"]:
            col_dp.update_body(
                DataProperty(value,
                             east_asian_ambiguous_width=ambiguous_width))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places is None
        assert col_dp.typecode == Typecode.STRING
        assert col_dp.ascii_char_width == ascii_char_width

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0
    def test_normal_inf(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("inf"))

        for value in [inf, None, inf, "inf"]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.LEFT
        assert col_dp.decimal_places is None
        assert col_dp.typecode == Typecode.INFINITY
        assert col_dp.ascii_char_width == 8

        assert col_dp.minmax_integer_digits.min_value is None
        assert col_dp.minmax_integer_digits.max_value is None

        assert col_dp.minmax_decimal_places.min_value is None
        assert col_dp.minmax_decimal_places.max_value is None

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert text_type(col_dp) == (
            "type=INFINITY, align=left, ascii_width=8")
    def test_normal_number_1(self):
        col_dp = ColumnDataProperty()
        col_dp.update_header(DataProperty("abc"))

        for value in [0, inf, nan]:
            col_dp.update_body(DataProperty(value))

        assert col_dp.align == Align.RIGHT
        assert col_dp.decimal_places == 0
        assert col_dp.typecode == Typecode.REAL_NUMBER
        assert col_dp.ascii_char_width == 8

        assert col_dp.minmax_integer_digits.min_value == 1
        assert col_dp.minmax_integer_digits.max_value == 1

        assert col_dp.minmax_decimal_places.min_value == 0
        assert col_dp.minmax_decimal_places.max_value == 0

        assert col_dp.minmax_additional_format_len.min_value == 0
        assert col_dp.minmax_additional_format_len.max_value == 0

        assert text_type(col_dp) == (
            "type=REAL_NUMBER, align=right, ascii_width=8, "
            "int_digits=1, decimal_places=0")
Example #34
0
 def _apply_style_to_row_item(self, row_idx: int,
                              col_dp: ColumnDataProperty,
                              value_dp: DataProperty, style: Style) -> str:
     return self._styler.apply_align(self._styler.apply(
         col_dp.dp_to_str(value_dp), style=style),
                                     style=style)
 def test_null(self):
     col_dp = ColumnDataProperty()
     assert col_dp.align == Align.LEFT
     assert col_dp.decimal_places is None
     assert col_dp.typecode == Typecode.NONE
     assert col_dp.ascii_char_width == 0