Example #1
0
    def setup_method(self, method):
        """Creates empty DictGrid"""

        self.dict_grid = DictGrid((100, 100, 100))
Example #2
0
class TestStringGeneratorMixin(object):
    """Unit tests for StringGeneratorMixin"""

    def setup_method(self, method):
        """Creates empty DictGrid"""

        self.dict_grid = DictGrid((100, 100, 100))

    def test_grid_to_strings(self):
        """Unit test for grid_to_strings"""

        self.dict_grid[(3, 2, 1)] = "42"
        grid_string_list = list(self.dict_grid.grid_to_strings())

        expected_res = [
            "[shape]\n",
            "100\t100\t100\n",
            "[grid]\n",
            '3\t2\t1\t42\n',
        ]
        assert grid_string_list == expected_res

    def test_attributes_to_strings(self):
        """Unit test for attributes_to_strings"""

        line = "[]\t[]\t[]\t[]\t[(3, 4)]\t0\t'borderwidth_bottom'\t42"
        self.dict_grid.parse_to_attribute(line)

        attr_string_list = list(self.dict_grid.attributes_to_strings())

        expected_res = [
            "[attributes]\n",
            "[]\t[]\t[]\t[]\t[(3, 4)]\t0\t'borderwidth_bottom'\t42\n",
        ]

        assert attr_string_list == expected_res

    def test_heights_to_strings(self):
        """Unit test for heights_to_strings"""

        self.dict_grid.row_heights[(2, 0)] = 77

        expected_res = [
            "[row_heights]\n",
            "2\t0\t77\n",
        ]

        height_string_list = list(self.dict_grid.heights_to_strings())

        assert height_string_list == expected_res

    def test_widths_to_strings(self):
        """Unit test for widths_to_strings"""

        self.dict_grid.col_widths[(2, 0)] = 77

        expected_res = [
            "[col_widths]\n",
            "2\t0\t77\n",
        ]

        width_string_list = list(self.dict_grid.widths_to_strings())

        assert width_string_list == expected_res

    def test_macros_to_strings(self):
        """Unit test for macros_to_strings"""

        self.dict_grid.macros = "Test"

        expected_res = [
            "[macros]\n",
            "Test\n",
        ]

        macros_string_list = list(self.dict_grid.macros_to_strings())

        assert macros_string_list == expected_res
Example #3
0
    def setup_method(self, method):
        """Creates empty DictGrid"""

        self.dict_grid = DictGrid((100, 100, 100))
Example #4
0
class TestParserMixin(object):
    """Unit tests for ParserMixin"""

    def setup_method(self, method):
        """Creates empty DictGrid"""

        self.dict_grid = DictGrid((10, 10, 10))

    def test_parse_to_shape(self):
        """Unit test for parse_to_shape"""

        line = "12\t12\t32"

        self.dict_grid.parse_to_shape(line)

        assert self.dict_grid.shape == (12, 12, 32)

    def test_parse_to_grid(self):
        """Unit test for parse_to_grid"""

        line = "1\t2\t3\t123"

        self.dict_grid.parse_to_grid(line)

        assert self.dict_grid[(1, 2, 3)] == "123"

    def test_parse_to_attribute(self):
        """Unit test for parse_to_attribute"""

        line = "[]\t[]\t[]\t[]\t[(3, 4)]\t0\t'borderwidth_bottom'\t42"

        self.dict_grid.parse_to_attribute(line)

        attrs = self.dict_grid.cell_attributes[(3, 4, 0)]
        assert attrs['borderwidth_bottom'] == 42

    def test_parse_to_height(self):
        """Unit test for parse_to_height"""

        line = "1\t0\t45"

        self.dict_grid.parse_to_height(line)

        assert self.dict_grid.row_heights[(1, 0)] == 45

    def test_parse_to_width(self):
        """Unit test for parse_to_width"""

        line = "1\t0\t43"

        self.dict_grid.parse_to_width(line)

        assert self.dict_grid.col_widths[(1, 0)] == 43

    def test_parse_to_macro(self):
        """Unit test for parse_to_macro"""

        line = "Test"

        self.dict_grid.parse_to_macro(line)

        assert self.dict_grid.macros == line