Repository: pyscript/pyscript
File: pyscript.core/tests/integration/test_01_basic.py (Python)

Code before:
        assert tb_lines[0] == "Traceback (most recent call last):"
        assert tb_lines[-1] == "Exception: this is an error inside handler"

    @only_main
    def test_execution_in_order(self):
        """
        Check that they script py tags are executed in the same order they are
        defined
        """
        self.pyscript_run(
            """
            <script type="py">import js; js.console.log('one')</script>
            <script type="py">js.console.log('two')</script>
            <script type="py">js.console.log('three')</script>
            <script type="py">js.console.log('four')</script>
        """
        )
        assert self.console.log.lines[-4:] == [
            "one",
            "two",
            "three",
            "four",
        ]

    def test_escaping_of_angle_brackets(self):
        """
        Check that script tags escape angle brackets
        """
        self.pyscript_run(
            """
            <script type="py">import js; js.console.log("A", 1<2, 1>2)</script>
            <script type="py">import js; js.console.log("B <div></div>")</script>
            <py-script>import js; js.console.log("C", 1<2, 1>2)</py-script>
            <py-script>import js; js.console.log("D <div></div>")</py-script>

        """
        )
        # in workers the order of execution is not guaranteed, better to play
        # safe
        lines = sorted(self.console.log.lines[-4:])
        assert lines == [
            "A true false",
            "B <div></div>",
            "C true false",
            "D <div></div>",
        ]

    def test_packages(self):
        self.pyscript_run(
            """
            <py-config>

Review comment (bug):
nice!
Maybe we can rewrite the test to use only two tags instead of 4?
```html
<script type="py">
    import js
    js.console.log("A", 1<2, 1>2)
    js.console.log("B <div></div>")
</script>
<py-script>
    import js
    js.console.log("C", 1<2, 1>2)
    js.console.log("D <div></div>")
</py-script>
```

This should be a bit faster in the `worker` base because it spawns only two pyodides instead of 4.
It was my original plan but I had to revert because of this bug.

Code after:
        assert tb_lines[0] == "Traceback (most recent call last):"
        assert tb_lines[-1] == "Exception: this is an error inside handler"

    @only_main
    def test_execution_in_order(self):
        """
        Check that they script py tags are executed in the same order they are
        defined
        """
        self.pyscript_run(
            """
            <script type="py">import js; js.console.log('one')</script>
            <script type="py">js.console.log('two')</script>
            <script type="py">js.console.log('three')</script>
            <script type="py">js.console.log('four')</script>
        """
        )
        assert self.console.log.lines[-4:] == [
            "one",
            "two",
            "three",
            "four",
        ]

    def test_escaping_of_angle_brackets(self):
        """
        Check that script tags escape angle brackets
        """
        self.pyscript_run(
            """
            <script type="py">
                import js
                js.console.log("A", 1<2, 1>2)
                js.console.log("B <div></div>")
            </script>
            <py-script>
                import js
                js.console.log("C", 1<2, 1>2)
                js.console.log("D <div></div>")
            </py-script>
        """
        )
        # in workers the order of execution is not guaranteed, better to play
        # safe
        lines = sorted(self.console.log.lines[-4:])
        assert lines == [
            "A true false",
            "B <div></div>",
            "C true false",
            "D <div></div>",
        ]