示例#1
0
    def test_fill_hatch2(self):
        kernel = bootstrap.bootstrap()
        try:
            kernel.console("operation* delete\n")
            kernel.console("rect 0 0 1in 1in\n")
            kernel.console("rect 3in 0 1in 1in\n")
            kernel.console("hatch\n")
            hatch = list(kernel.elements.ops())[0]
            hatch.hatch_type = "eulerian"
            rect0 = list(kernel.elements.elems())[0]
            hatch.add_node(copy(rect0))
            rect1 = list(kernel.elements.elems())[1]
            hatch.add_node(copy(rect1))
            commands = list()
            # kernel.console("tree list\n")
            hatch.preprocess(kernel.root, Matrix(), commands)
            for command in commands:
                command()
            # kernel.console("tree list\n")
            polyline_node0 = hatch.children[0]
            shape0 = polyline_node0.shape
            self.assertEqual(len(shape0), 77)
            # print(shape0)

            polyline_node1 = hatch.children[1]
            shape1 = polyline_node1.shape
            self.assertEqual(len(shape1), 50)
            # print(shape1)
        finally:
            kernel.shutdown()
示例#2
0
 def test_kernel_commands(self):
     """
     Tests all commands with no arguments to test for crashes...
     """
     kernel = bootstrap.bootstrap()
     try:
         for cmd, path, command in kernel.find("command/.*"):
             if "server" in command:
                 continue
             if "ruida" in command:
                 continue
             if "quit" in command:
                 continue
             if "shutdown" in command:
                 continue
             if "loop" in command:
                 continue
             if not cmd.regex:
                 print("Testing command: %s" % command)
                 # command should be generated with something like
                 # kernel.console(" ".join(command.split("/")[1:]) + "\n")
                 # if first parameter is not base but this fails so not
                 # changing yet
                 kernel.console(command.split("/")[-1] + "\n")
     finally:
         kernel.shutdown()
示例#3
0
 def test_fill_kernel_registered(self):
     kernel = bootstrap.bootstrap()
     try:
         eulerian_fill_k = kernel.lookup("hatch/eulerian")
         self.assertIs(eulerian_fill_k, eulerian_fill)
     finally:
         kernel.shutdown()
示例#4
0
 def test_elements_specific(self):
     """
     Tests specific elements for correct non-failure.
     """
     kernel = bootstrap.bootstrap()
     try:
         kernel.console("polyline grid 3 3\n")
         kernel.console("polyline 3cm 3cm  2cm 2cm 1cm 1cm grid 3 3\n")
         kernel.console("circle 2cm 2cm 1cm grid 3 3\n")
         kernel.console("rect 2cm 2cm 1cm 1cm grid 3 3\n")
         kernel.console("ellipse 2cm 2cm 1cm 1cm grid 3 3\n")
         kernel.console("line 2cm 2cm 1cm 1cm grid 3 3\n")
     finally:
         kernel.shutdown()
示例#5
0
    def test_elements_shapes(self):
        """
        Intro test for elements

        :return:
        """
        kernel = bootstrap.bootstrap()
        try:
            kernel_root = kernel.get_context("/")
            kernel_root("shape 5 2in 2in 1in\n")
            # kernel_root("polygon 1in 1in 2in 2in 0in 4cm\n")

        finally:
            kernel.shutdown()
示例#6
0
    def test_elements_clipboard(self):
        """
        Intro test for elements

        :return:
        """
        kernel = bootstrap.bootstrap()
        try:
            kernel_root = kernel.get_context("/")
            kernel_root("rect 1in 1in 1in 1in stroke red fill blue\n")
            kernel_root("clipboard copy\n")
            kernel_root("clipboard paste -xy 2in 2in\n")
            kernel_root("grid 2 4\n")
        finally:
            kernel.shutdown()
示例#7
0
    def test_echo_and_ansi(self):
        """
        Tests all echo options separately and combined
        with output to ansi terminal window
        """
        echo_commands = [
            "echo",
            "echo [bg-white][black] black text",
            "echo [red] red text",
            "echo [green] green text",
            "echo [yellow] yellow text",
            "echo [blue] blue text",
            "echo [magenta] magenta text",
            "echo [cyan] cyan text",
            "echo [bg-black][white] white text",
            "echo [bg-black][white] black background",
            "echo [bg-red] red background",
            "echo [bg-green] green background",
            "echo [bg-yellow] yellow background",
            "echo [bg-blue] blue background",
            "echo [bg-magenta] magenta background",
            "echo [bg-cyan] cyan background",
            "echo [bg-white][black] white background",
            "echo [bg-white][black] bright black text",
            "echo [bold][red] bright red text",
            "echo [bold][green] bright green text",
            "echo [bold][yellow] bright yellow text",
            "echo [bold][blue] bright blue text",
            "echo [bold][magenta] bright magenta text",
            "echo [bold][cyan] bright cyan text",
            "echo [bold][bg-black][white] bright white text",
            "echo [bold] bold text [/bold] normal text",
            "echo [italic] italic text [/italic] normal text",
            "echo [underline] underline text [/underline] normal text",
            "echo [underscore] underscore text [/underscore] normal text",
            "echo [negative] negative text [positive] positive text",
            "echo [negative] negative text [normal] normal text",
            "echo [raw][red] red bbcode and normal text",
        ]

        kernel = bootstrap.bootstrap()
        try:
            for echo in echo_commands:
                print("Testing echo command: %s" % echo)
                kernel.console(echo + "\n")
        finally:
            kernel.shutdown()
示例#8
0
    def test_elements_type(self):
        """
        Tests some generic elements commands and validates output as correct type
        """
        kernel = bootstrap.bootstrap()

        @kernel.console_command("validate_type", input_type="elements")
        def validation_type(command, data=None, **kwargs):
            for node in data:
                self.assertTrue(isinstance(node, Node))

        try:
            for cmd, path, command in kernel.find("command/elements.*"):
                kernel.console("element* " + command.split("/")[-1] +
                               " validate_type\n")
        finally:
            kernel.shutdown()
示例#9
0
    def test_penbox(self):
        """
        Test penbox code

        :return:
        """
        kernel = bootstrap.bootstrap()
        try:
            kernel_root = kernel.get_context("/")
            kernel_root("penbox testpasses add 5 set 0-4 hatch_angle 0-90\n")
            self.assertEqual(len(kernel_root.elements.penbox["testpasses"]), 5)
            self.assertEqual(
                kernel_root.elements.penbox["testpasses"][-1]["hatch_angle"],
                90)

        finally:
            kernel.shutdown()
示例#10
0
    def test_elements_circle(self):
        """
        Intro test for elements

        :return:
        """
        kernel = bootstrap.bootstrap()
        try:
            kernel_root = kernel.get_context("/")
            kernel_root("circle 1in 1in 1in\n")
            for node in kernel_root.elements.elems():
                # print(element)
                self.assertEqual(
                    node.shape,
                    Circle(
                        center=(1000 * UNITS_PER_MIL, 1000 * UNITS_PER_MIL),
                        r=1000 * UNITS_PER_MIL,
                    ),
                )
                self.assertEqual(node.stroke, "blue")
        finally:
            kernel.shutdown()
示例#11
0
    def test_elements_rect(self):
        """
        Intro test for elements

        :return:
        """
        kernel = bootstrap.bootstrap()
        try:
            kernel_root = kernel.get_context("/")
            kernel_root("rect 1in 1in 1in 1in stroke red fill blue\n")
            for node in kernel_root.elements.elems():
                self.assertEqual(
                    node.shape,
                    Rect(
                        1000 * UNITS_PER_MIL,
                        1000 * UNITS_PER_MIL,
                        1000 * UNITS_PER_MIL,
                        1000 * UNITS_PER_MIL,
                    ),
                )
                self.assertEqual(node.stroke, "red")
                self.assertEqual(node.fill, "blue")
        finally:
            kernel.shutdown()
    def test_actualize_pureblack(self):
        """
        Test that a pure black image does not crash.

        :return:
        """
        kernel = bootstrap.bootstrap()
        try:
            kernel_root = kernel.get_context("/")
            # kernel_root("channel print console\n")
            image = Image.new("RGBA", (256, 256), "black")
            elements = kernel_root.elements
            node = elements.elem_branch.add(
                image=image, dpi=1000.0, matrix=Matrix(), type="elem image"
            )
            node.emphasized = True
            kernel_root("image resample\n")
            for element in kernel_root.elements.elems():
                if node.type == "elem image":
                    self.assertEqual(element.image.size, (256, 256))
                    self.assertEqual(element.matrix.value_trans_x(), 0)
                    self.assertEqual(element.matrix.value_trans_y(), 0)
        finally:
            kernel.shutdown()