File: regular_file_readall.py

package info (click to toggle)
python-eventlet 0.40.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,200 kB
  • sloc: python: 25,109; sh: 78; makefile: 32
file content (41 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download | duplicates (3)
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
__test__ = False

if __name__ == '__main__':
    import eventlet
    eventlet.monkey_patch()

    import io
    import os
    import tempfile

    with tempfile.NamedTemporaryFile() as tmp:
        with open(tmp.name, "wb") as fp:
            fp.write(b"content")

        # test BufferedReader.read()
        fd = os.open(tmp.name, os.O_RDONLY)
        fp = os.fdopen(fd, "rb")
        with fp:
            content = fp.read()
        assert content == b'content'

        # test FileIO.read()
        fd = os.open(tmp.name, os.O_RDONLY)
        fp = os.fdopen(fd, "rb", 0)
        with fp:
            content = fp.read()
        assert content == b'content'

        # test FileIO.readall()
        fd = os.open(tmp.name, os.O_RDONLY)
        fp = os.fdopen(fd, "rb", 0)
        with fp:
            content = fp.readall()
        assert content == b'content'

        # test FileIO.readall() (for Python 2 and Python 3)
        with open(tmp.name, "rb", 0) as fp:
            content = fp.readall()
        assert content == b'content'

    print("pass")