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) ])
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' )
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")
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)])
def test_errors(self): with self.assertRaises(TypeError): filesize.traditional("foo")
def test_errors(self): with self.assertRaises(ValueError): filesize.traditional('foo')