File: test_standalone_print_function.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (41 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""In which we test py3 print function syntax
(incompatible with py2 syntax in the same file)"""

from __future__ import print_function

from rpython.translator.c.test import test_standalone

setup_module = test_standalone.setup_module
teardown_module = test_standalone.teardown_module


class TestStandalonePrintFunction(test_standalone.StandaloneTestsVerified):

    def test_print_function(self):
        def entry_point(argv):
            print("hello simpler world")
            argv = argv[1:]
            print("argument count:", len(argv))
            print("arguments:", argv)
            # with a space
            print("argument lengths:", end=" ")
            print([len(s) for s in argv])
            # with no space
            print("argument lengths:", end="")
            print([len(s) for s in argv])
            # strange ending
            print("end", "is", end="\nstrange!\r\n")
            return 0

        t, cbuilder = self.compile(entry_point)
        data = cbuilder.cmdexec("hi there")
        assert data.startswith(
            "hello simpler world\n"
            "argument count: 2\n"
            "arguments: [hi, there]\n"
            "argument lengths: [2, 5]\n"
            "argument lengths:[2, 5]\n"
            "end is\nstrange!\n"
        )
        # NB. RPython has only str, not repr, so str() on a list of strings
        # gives the strings unquoted in the list