예제 #1
0
파일: mem.py 프로젝트: noyoshi/pytop
def memory_usage():
    mem = psutil.virtual_memory()
    total = filesize.traditional(mem.total)
    avaliable = filesize.traditional(mem.available)
    used = filesize.traditional(mem.used)

    return DataGroup("Memory", [
        OutputData("Total", total),
        OutputData("Avaliable", avaliable),
        OutputData("Used", used)
    ])
예제 #2
0
    def test_traditional(self):

        self.assertEqual(
            filesize.traditional(0),
            '0 bytes'
        )
        self.assertEqual(
            filesize.traditional(1),
            '1 byte'
        )
        self.assertEqual(
            filesize.traditional(2),
            '2 bytes'
        )
        self.assertEqual(
            filesize.traditional(1024),
            '1.0 KB'
        )

        self.assertEqual(
            filesize.traditional(1024 * 1024),
            '1.0 MB'
        )

        self.assertEqual(
            filesize.traditional(1024 * 1024 + 1),
            '1.0 MB'
        )

        self.assertEqual(
            filesize.traditional(1.5 * 1024 * 1024),
            '1.5 MB'
        )
예제 #3
0
    def test_traditional(self):

        self.assertEqual(filesize.traditional(0), "0 bytes")
        self.assertEqual(filesize.traditional(1), "1 byte")
        self.assertEqual(filesize.traditional(2), "2 bytes")
        self.assertEqual(filesize.traditional(1024), "1.0 KB")

        self.assertEqual(filesize.traditional(1024 * 1024), "1.0 MB")

        self.assertEqual(filesize.traditional(1024 * 1024 + 1), "1.0 MB")

        self.assertEqual(filesize.traditional(1.5 * 1024 * 1024), "1.5 MB")
예제 #4
0
def neetwork():
    new_value = psutil.net_io_counters().bytes_sent + \
        psutil.net_io_counters().bytes_recv

    if neetwork.old_value:
        value = new_value - neetwork.old_value
    else:
        value = new_value

    value = filesize.traditional(value)

    neetwork.old_value = new_value

    return DataGroup("Network", [OutputData("IO", value, color=magenta)])
예제 #5
0
    def test_errors(self):

        with self.assertRaises(TypeError):
            filesize.traditional("foo")
예제 #6
0
    def test_errors(self):

        with self.assertRaises(ValueError):
            filesize.traditional('foo')