@@ -1955,6 +1955,38 @@ def test_open_files_enametoolong(self):
19551955 assert p .open_files () == []
19561956 assert m .called
19571957
1958+ # Test parsing variants of fdinfo content ( during Process.open_files() )
1959+
1960+ def test_open_files_fdinfo_parsing_avg (self ):
1961+ # Case typical fdinfo file content
1962+ fdinfo_content = """\
1963+ pos: 0
1964+ flags: 02100000
1965+ mnt_id: 129
1966+ ino: 29836347532685335"""
1967+ self ._do_test_fdinfo_parsing (fdinfo_content , (0 , 0o2100000 ))
1968+
1969+ def test_open_files_fdinfo_parsing_only_flags (self ):
1970+ # Case only flags.
1971+ # Seen in Docker python + Google Cloud Run
1972+ # https://github.com/giampaolo/psutil/issues/2596
1973+ fdinfo_content = """\
1974+ flags: 02100000"""
1975+ self ._do_test_fdinfo_parsing (fdinfo_content , (None , 0o2100000 ))
1976+
1977+ def test_open_files_fdinfo_parsing_empty (self ):
1978+ # extereme case the file is empty (not seen in practice)
1979+ fdinfo_content = ""
1980+ self ._do_test_fdinfo_parsing (fdinfo_content , (None , None ))
1981+
1982+ def _do_test_fdinfo_parsing (self , content , expected ):
1983+ # `f`` needs to be a file in binary mode,
1984+ # simulating what is done in Process.open_flles()
1985+ f = io .BytesIO (content .encode ())
1986+ actual_pos , actual_flags = psutil ._pslinux ._parse_fdinfo (f )
1987+ assert actual_pos == expected [0 ]
1988+ assert actual_flags == expected [1 ]
1989+
19581990 # --- mocked tests
19591991
19601992 def test_terminal_mocked (self ):
0 commit comments