587
|
1 |
#============================================================================
|
|
2 |
#Name : test_freedisk.py
|
|
3 |
#Part of : Helium
|
|
4 |
|
|
5 |
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
6 |
#All rights reserved.
|
|
7 |
#This component and the accompanying materials are made available
|
|
8 |
#under the terms of the License "Eclipse Public License v1.0"
|
|
9 |
#which accompanies this distribution, and is available
|
|
10 |
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
11 |
#
|
|
12 |
#Initial Contributors:
|
|
13 |
#Nokia Corporation - initial contribution.
|
|
14 |
#
|
|
15 |
#Contributors:
|
|
16 |
#
|
|
17 |
#Description:
|
|
18 |
#===============================================================================
|
588
|
19 |
""" test free disk """
|
|
20 |
|
628
|
21 |
# pylint: disable=R0201
|
587
|
22 |
|
|
23 |
import unittest
|
|
24 |
import logging
|
|
25 |
import os, string
|
|
26 |
import sys
|
|
27 |
|
|
28 |
class FreeDiskTest(unittest.TestCase):
|
|
29 |
""" Acceptance tests for freedisk.py """
|
|
30 |
def test_freedisk(self):
|
|
31 |
import freedisk
|
|
32 |
freedisk.print_space_report(os.getcwd(), 1)
|
|
33 |
|
|
34 |
if sys.platform == "win32":
|
|
35 |
from win32api import GetLogicalDriveStrings
|
|
36 |
|
588
|
37 |
_logger = logging.getLogger('test_freedisk')
|
587
|
38 |
|
|
39 |
## MAKE SURE that the drive being tested MUST be there.
|
|
40 |
class ToolTest(unittest.TestCase):
|
|
41 |
"""
|
|
42 |
Setup and Tests for the script
|
|
43 |
"""
|
|
44 |
|
|
45 |
def setUp(self):
|
|
46 |
"""
|
|
47 |
All the settings related to the tests are defined here
|
|
48 |
"""
|
|
49 |
self.drive_letter = next_free_label()
|
|
50 |
|
|
51 |
def test_when_enough_space(self):
|
|
52 |
"""
|
|
53 |
Both drive and space parameters are correct with minimum required space
|
|
54 |
"""
|
|
55 |
output = os.system('python -m freedisk -d c: -s 1')
|
|
56 |
assert(output==0)
|
|
57 |
|
|
58 |
|
|
59 |
def test_when_not_enough_space(self):
|
|
60 |
"""
|
|
61 |
Both drive and space parameters are correct with maximum required space
|
|
62 |
"""
|
|
63 |
output = os.system('python -m freedisk -d c: -s 10000000000')
|
|
64 |
assert(output==-1)
|
|
65 |
|
|
66 |
def test_wrong_drive_letter(self):
|
|
67 |
"""
|
|
68 |
Tests with drive which does not exist
|
|
69 |
"""
|
628
|
70 |
print 'Running: ' + 'python -m freedisk -d %s: -s 10 ' % self.drive_letter
|
587
|
71 |
output = os.system('python -m freedisk -d %s: -s 10 ' % self.drive_letter)
|
628
|
72 |
print 'output: ' + str(output)
|
587
|
73 |
assert(output==-2)
|
|
74 |
|
|
75 |
def test_missing_parameters(self):
|
|
76 |
"""
|
|
77 |
Several cases to give invalid parameters
|
|
78 |
"""
|
|
79 |
|
|
80 |
##Required space parameter is missing
|
|
81 |
output = os.system('python -m freedisk -d c:')
|
|
82 |
assert(output==-3)
|
|
83 |
##Drive parameter is missing
|
|
84 |
output = os.system('python -m freedisk -s 1')
|
|
85 |
assert(output==-3)
|
|
86 |
##Both parameters are missing
|
|
87 |
output = os.system('python -m freedisk')
|
|
88 |
assert(output==-3)
|
|
89 |
|
|
90 |
def test_wrong_drive_parameters(self):
|
|
91 |
"""
|
|
92 |
Drive parameter is incorrect
|
|
93 |
"""
|
|
94 |
output = os.system('python -m freedisk -d c -s 10')
|
|
95 |
assert(output==0)
|
|
96 |
|
|
97 |
|
|
98 |
def next_free_label():
|
|
99 |
"""
|
|
100 |
Detects the next free drive letter for test_wrong_drive_letter
|
|
101 |
"""
|
|
102 |
for letter in set(string.ascii_uppercase)-set(GetLogicalDriveStrings()):
|
|
103 |
try:
|
|
104 |
drv_letter = letter
|
|
105 |
os.chdir(drv_letter + ':\\')
|
|
106 |
except OSError:
|
|
107 |
break
|
|
108 |
else:
|
|
109 |
raise ValueError("Out of drives")
|
|
110 |
return drv_letter
|
|
111 |
|
|
112 |
if __name__ == '__main__':
|
|
113 |
unittest.main() |