@@ -10,22 +10,22 @@ def BytesToMB(bytes):
10
10
# Black box testing
11
11
class TestPsutil (unittest .TestCase ):
12
12
def test_cpu_count (self ):
13
- assert (psutil .cpu_count () == 4 )
13
+ self . assertEqual (psutil .cpu_count (), 4 )
14
14
15
15
def test_cpu_percent (self ):
16
16
percent = psutil .cpu_percent ()
17
- assert (percent >= 0 and percent <= 400 )
17
+ self . assertTrue (percent >= 0 and percent <= 400 )
18
18
19
19
def test_virtual_memory (self ):
20
20
total , available , percent , used , free , active , inactive , \
21
21
buff , cache , shared = psutil .virtual_memory ()
22
22
23
- assert (percent >= 0 and percent <= 100 )
23
+ self . assertTrue (percent >= 0 and percent <= 100 )
24
24
available = BytesToMB (available )
25
25
cache = BytesToMB (cache )
26
- assert (cache >= 100 and cache < 2048 )
27
- assert (available >= 128 )
28
- assert (available <= 4096 )
26
+ self . assertTrue (cache >= 100 and cache < 2048 )
27
+ self . assertTrue (available >= 128 )
28
+ self . assertTrue (available <= 4096 )
29
29
30
30
def test_disk_io_counters (self ):
31
31
read_count , write_count , read_bytes , write_bytes , \
@@ -34,35 +34,35 @@ def test_disk_io_counters(self):
34
34
= psutil .disk_io_counters ()
35
35
disk_in = BytesToMB (read_bytes )
36
36
disk_out = BytesToMB (write_bytes )
37
- assert (disk_in < 10 * 1024 )
38
- assert (disk_in > 128 )
39
- assert (disk_out < 10 * 1024 )
40
- assert (disk_out > 128 )
37
+ self . assertTrue (disk_in < 10 * 1024 )
38
+ self . assertTrue (disk_in > 128 )
39
+ self . assertTrue (disk_out < 10 * 1024 )
40
+ self . assertTrue (disk_out > 128 )
41
41
42
42
def test_process_iter_and_uids (self ):
43
43
count = 0
44
44
for proc in psutil .process_iter ():
45
45
count += 1
46
46
real , effective , saved = proc .uids ()
47
- assert (real >= 0 and real <= 0xffff )
48
- assert (effective >= 0 and effective <= 0xffff )
49
- assert (saved >= 0 and saved <= 0xffff )
50
- assert (count > 0 )
47
+ self . assertTrue (real >= 0 and real <= 0xffff )
48
+ self . assertTrue (effective >= 0 and effective <= 0xffff )
49
+ self . assertTrue (saved >= 0 and saved <= 0xffff )
50
+ self . assertTrue (count > 0 )
51
51
52
52
def test_psutil_process_functions (self ):
53
53
for proc in psutil .process_iter ():
54
54
real , effective , saved = proc .uids ()
55
55
if real < 1000 :
56
56
continue
57
- assert (proc .pid <= 0xffff )
58
- assert (proc .ppid () >= 0 and proc .ppid () <= 0xffff )
59
- assert ( isinstance ( proc .name (), str ) )
60
- assert ( isinstance ( proc .username (), str ) )
57
+ self . assertTrue (proc .pid <= 0xffff )
58
+ self . assertTrue (proc .ppid () >= 0 and proc .ppid () <= 0xffff )
59
+ self . assertIsInstance ( proc .name (), str )
60
+ self . assertIsInstance ( proc .username (), str )
61
61
timestamp = datetime .datetime \
62
62
.fromtimestamp (proc .create_time ()) \
63
63
.strftime ("%Y-%m-%d %H:%M:%S" )
64
- assert ( isinstance ( timestamp , str ) )
65
- assert ( isinstance ( proc .cmdline (), list ) )
64
+ self . assertIsInstance ( timestamp , str )
65
+ self . assertIsInstance ( proc .cmdline (), list )
66
66
67
67
rIO , wIO , rB , wB , read_chars , write_chars \
68
68
= proc .io_counters ()
@@ -76,12 +76,12 @@ def test_psutil_process_functions(self):
76
76
rIO = BytesToMB (rIO )
77
77
wIO = BytesToMB (wIO )
78
78
79
- assert (rss <= 1024 )
80
- assert (vms <= 1024 )
81
- assert (cpu >= 0 and cpu <= 100 )
82
- assert (ram >= 0 and ram <= 100 )
83
- assert (rIO < 1024 )
84
- assert (wIO < 1024 )
79
+ self . assertTrue (rss <= 1024 )
80
+ self . assertTrue (vms <= 1024 )
81
+ self . assertTrue (cpu >= 0 and cpu <= 100 )
82
+ self . assertTrue (ram >= 0 and ram <= 100 )
83
+ self . assertTrue (rIO < 1024 )
84
+ self . assertTrue (wIO < 1024 )
85
85
break
86
86
87
87
0 commit comments