Esempio n. 1
0
    def test_count_cnab_lines(self):
        fields = [Field(end=240), Field(end=100), Field(end=240), Field(end=123)]

        expected_value = 2
        result = count_cnab_lines(fields)

        self.assertEqual(expected_value, result)
Esempio n. 2
0
    def test_check_start_and_end_end_eq_240(self):
        fields = [
            Field(start=1, end=240),
            Field(start=1, end=3),
            Field(start=4, end=100),
        ]

        check_start_and_end(fields)
Esempio n. 3
0
    def test_check_size_of_input_data_more_than_one_field(self):
        fields = [
            Field(identifier="a", length=1, num_decimals=""),
            Field(identifier="b", length=1, num_decimals="2"),
        ]

        data = {"b": ["xyzw"]}

        with self.assertRaises(ValueError):
            check_size_of_input_data(fields, data)
Esempio n. 4
0
    def test_check_overwriting_data(self):
        fields = [
            Field(identifier="a", reasonable_default="123"),
            Field(identifier="b"),
        ]

        data = {"a": ["1"]}

        with self.assertRaises(ValueError):
            check_overwriting_data(fields, data)
Esempio n. 5
0
    def test_index_to_insert(self):

        fields = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
        ]
        expected_value = 3
        result = index_to_insert(fields, "c")
        self.assertEqual(expected_value, result)
Esempio n. 6
0
    def test_build_pieces_of_value_to_cnab(self):
        fields = [
            Field(value_to_cnab="A", end=10),
            Field(value_to_cnab="B", end=240),
            Field(value_to_cnab="C", end=1),
        ]

        expected_value = ["A", "B\n", "C"]
        result = build_pieces_of_value_to_cnab(fields)

        self.assertEqual(expected_value, result)
Esempio n. 7
0
    def test_count_cnab_lines_1_and_E_type(self):

        fields = [
            Field(start=8, end=8, default="1"),
            Field(start=9, end=9, value="E"),
            # another fields that must not be counted
            Field(start=8, end=8, default="2"),
            Field(start=9, end=9, value="T"),
        ]

        expected_value = 2
        result = count_cnab_lines_1_E(fields)

        self.assertEqual(expected_value, result)
Esempio n. 8
0
    def test_check_size_of_input_data_minimal(self):
        fields = [Field(identifier="a", length=1)]

        data = {"a": ["longer"]}

        with self.assertRaises(ValueError):
            check_size_of_input_data(fields, data)
Esempio n. 9
0
    def test_check_size_of_input_data_num_decimals(self):
        fields = [Field(identifier="a", length=1, num_decimals="2")]

        data = {"a": ["xyzw"]}

        with self.assertRaises(ValueError):
            check_size_of_input_data(fields, data)
Esempio n. 10
0
    def test_default_decimals_2(self):

        field = Field(num_decimals="2/5")

        expected_value = 2
        result = default_decimals(field)

        self.assertEqual(expected_value, result)
Esempio n. 11
0
    def test_default_decimals_empty(self):

        field = Field(num_decimals="")

        expected_value = 0
        result = default_decimals(field)

        self.assertEqual(expected_value, result)
Esempio n. 12
0
    def test_check_missing_given_data_identifiers(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b", default=0),
            Field(identifier="c", default="Brancos"),
            Field(identifier="d", reasonable_default="Calculavél"),
            Field(identifier="e", reasonable_default="Vazio"),
            Field(identifier="f", reasonable_default=1600),
            Field(identifier="g", default=123,
                  reasonable_default="Calculavél"),
            Field(identifier="h", default=""),
            Field(identifier="i"),
        ]

        # se fields tiver com todos os reasonable_default não precisa do patterns
        patterns = ("a", "b", "c", "d", "e", "f", "g")
        data = {"b": 1}

        with self.assertRaises(ValueError):
            check_missing_given_data_identifiers(fields, patterns, data)
Esempio n. 13
0
    def test_extract_identifiers_that_have_default_or_reasonable_default(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b", default=0),
            Field(identifier="c", default="Brancos"),
            Field(identifier="d", reasonable_default="Calculavél"),
            Field(identifier="e", reasonable_default="Vazio"),
            Field(identifier="f", reasonable_default=1600),
            Field(identifier="g", default=123,
                  reasonable_default="Calculavél"),
            Field(identifier="h"),
        ]

        expected = set(["b", "c", "d", "e", "f", "g"])

        result = extract_identifiers_default(fields)
        self.assertEqual(expected, result)
Esempio n. 14
0
    def test_insert_segments_only_two(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c")
        ]

        patterns = "b"

        expected = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="b"),
            Field(identifier="b"),
            Field(identifier="c"),
        ]

        set_insert_segments(fields, 3, "b", patterns)
        self.assertEqual(expected, fields)
Esempio n. 15
0
    def test_count_cnab_lines_1_2_3_4_5(self):
        # Note: if default=0 or default=9 it must not be counted
        fields = [
            Field(start=8, end=8, default=1),
            Field(start=8, end=8, default=2),
            Field(start=8, end=8, default=3),
            Field(start=8, end=8, default=4),
            Field(start=8, end=8, default=5),
            Field(start=8, end=8, default=0),
            Field(start=8, end=8, default=9),
        ]

        expected_value = 5
        result = count_cnab_lines_1_2_3_4_5(fields)

        self.assertEqual(expected_value, result)
Esempio n. 16
0
    def test_count_cnab_lines_1(self):

        fields = [
            Field(start=8, end=8, default="1"),
            # another fields that must not be counted
            Field(start=8, end=8, default="0"),
            Field(start=8, end=8, value="2"),
            Field(start=8, end=8, value="3"),
            Field(start=8, end=8, value="4"),
            Field(start=8, end=8, value="5"),
            Field(start=8, end=8, value="9"),
        ]

        expected_value = 1
        result = count_cnab_lines_1(fields)

        self.assertEqual(expected_value, result)
Esempio n. 17
0
    def test_count_cnab_lines_0_1_3_5_9(self):
        fields = [
            Field(start=8, end=8),
            Field(start=8, end=8),
            Field(start=8, end=8),
            Field(start=8, end=8),
            Field(start=8, end=5),
            Field(start=4, end=8),
        ]

        expected_value = 4
        result = count_cnab_lines_0_1_3_5_9(fields)

        self.assertEqual(expected_value, result)
Esempio n. 18
0
    def test_insert_segments_no_change(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c")
        ]

        expected = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c")
        ]

        set_insert_segments(fields, 1, "b", None)

        self.assertEqual(expected, fields)
Esempio n. 19
0
 def test_check_given_data_identifiers(self):
     fields = [Field(identifier="a")]
     patterns = ("a",)
     data = {"b": ["1"]}
     with self.assertRaises(ValueError):
         check_given_data_identifiers(fields, patterns, data)
Esempio n. 20
0
 def test_check_start_and_end_raises(self):
     fields = [Field(start=1, end=3), Field(start=5, end=10)]
     with self.assertRaises(ValueError):
         check_start_and_end(fields)
Esempio n. 21
0
    def test_check_start_and_end_not_raises(self):
        fields = [Field(start=1, end=3), Field(start=4, end=10)]

        check_start_and_end(fields)
Esempio n. 22
0
    def test_extract_identifiers_default_or_reasonable_default_empty(self):
        """
        Note: quando se lê de um arquivo .csv se o valor do campo não existir
              não vem com None, mas sim com ''. Como a criação da dataclass
              força que caso não seja passado um valor para um do atributos
              este será None, e não ''.
        """
        fields = [
            Field(identifier="a"),
            Field(identifier="b", default=""),
            Field(identifier="c", default=0),
            Field(identifier="d", default="Brancos"),
            Field(identifier="e", reasonable_default=""),
            Field(identifier="f", reasonable_default="Calculavél"),
            Field(identifier="g", reasonable_default="Vazio"),
            Field(identifier="h", reasonable_default=1600),
            Field(identifier="i", default=123,
                  reasonable_default="Calculavél"),
            Field(identifier="j", default="", reasonable_default=""),
            Field(identifier="l"),
        ]

        expected = set(["c", "d", "f", "g", "i", "h"])

        result = extract_identifiers_default(fields)
        self.assertEqual(expected, result)
Esempio n. 23
0
    def test_set_data_to_fields(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="b"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="c"),
            Field(identifier="c"),
            Field(identifier="d"),
        ]

        data = {"b": ["1", "2", "3"], "c": ["X", "Y", "Z"]}

        expected = [
            Field(identifier="a"),
            Field(identifier="b", value=1),
            Field(identifier="b", value=2),
            Field(identifier="b", value=3),
            Field(identifier="c", value="X"),
            Field(identifier="c", value="Y"),
            Field(identifier="c", value="Z"),
            Field(identifier="d"),
        ]

        for index, field in enumerate(fields):
            with self.subTest(index):
                expec = expected[index]

                set_data_to_fields([field], data)
                self.assertEqual(
                    [expec],
                    [field],
                    msg=f"O valor esperado é diferente! "
                    f"{type(expec.value)}({expec.value}) != "
                    f"{type(field.value)}({field.value})",
                )
Esempio n. 24
0
 def test_check_none_value(self):
     fields = [Field()]
     with self.assertRaises(ValueError):
         check_none_value(fields)
Esempio n. 25
0
    def test_insert_segments_more_than_one_pattern(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="e"),
            Field(identifier="f"),
        ]

        patterns = ("b", "c")

        expected = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="e"),
            Field(identifier="f"),
        ]

        set_insert_segments(fields, 2, "d", patterns)
        self.assertEqual(expected, fields)
Esempio n. 26
0
    def test_insert_segments_realistic(self):
        fields = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="e"),
            Field(identifier="f"),
        ]

        patterns = ("b", "c", "d")

        expected = [
            Field(identifier="a"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="b"),
            Field(identifier="c"),
            Field(identifier="d"),
            Field(identifier="e"),
            Field(identifier="f"),
        ]

        set_insert_segments(fields, 4, "d", patterns)
        self.assertEqual(expected, fields)