예제 #1
0
    def testMultipleItems(self):
        process1 = sysinfo_pb2.Process()
        process1.pid = 1
        process1.username = '******'
        process1.nice = 10
        process1.VMS_size = 42
        process1.RSS_size = 43
        process1.status = 'sleeping'
        process1.cpu_percent = 1.5
        process1.memory_percent = 2.5
        process1.exe = '/foo/bar'

        process2 = sysinfo_pb2.Process()
        process2.pid = 2
        process2.username = '******'
        process2.VMS_size = 40
        process2.RSS_size = 41
        process2.status = 'zombie'
        process2.exe = '/foo/baz/quux'

        ps = representer.ProcessList([process1, process2])

        out = io.StringIO()
        ps._repr_pretty_(pretty.PrettyPrinter(out, max_width=55), cycle=False)

        expected = """
   PID USER       NI  VIRT   RES S CPU% MEM% Command
     1 admin      10   42B   43B S  1.5  2.5 /foo/bar
     2 admin       0   40B   41B Z  0.0  0.0 /foo/baz/q
"""
        self.assertEqual(out.getvalue(), expected)
예제 #2
0
    def testExceedMaxWidth(self):
        process = sysinfo_pb2.Process()
        process.pid = 1
        process.username = '******'
        process.nice = 10
        process.VMS_size = 42
        process.RSS_size = 43
        process.status = 'sleeping'
        process.cpu_percent = 1.5
        process.memory_percent = 2.5
        process.exe = '/foo/bar/baz'

        out = io.StringIO()
        pp = pretty.PrettyPrinter(out, max_width=55)
        representer.process_pretty(process, pp, cycle=False)

        expected = '     1 longusern  10   42B   43B S  1.5  2.5 /foo/bar/baz'

        self.assertEqual(out.getvalue(), expected)
예제 #3
0
    def testSlice(self):
        process1 = sysinfo_pb2.Process()
        process2 = sysinfo_pb2.Process()

        ps = representer.ProcessList([process1, process2])
        self.assertIsInstance(ps[:1], representer.ProcessList)