3
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import unittest, os, shutil
|
|
18 |
|
|
19 |
from commandplugin import commandml
|
|
20 |
|
|
21 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
22 |
TMP_PATH = os.path.join(ROOT_PATH, 'temp')
|
|
23 |
TMP_FILE1 = os.path.join(TMP_PATH, 'sub/one.txt')
|
|
24 |
TMP_FILE2 = os.path.join(TMP_PATH, 'foobar/two.txt')
|
|
25 |
TMP_FILE3 = os.path.join(TMP_PATH, 'three.txt')
|
|
26 |
|
|
27 |
def norm(path):
|
|
28 |
return os.path.normpath(path)
|
|
29 |
|
|
30 |
def create_file(path):
|
|
31 |
if not os.path.exists(os.path.dirname(path)):
|
|
32 |
os.makedirs(os.path.dirname(path))
|
|
33 |
f = open(path, "w")
|
|
34 |
f.write('something...')
|
|
35 |
f.close()
|
|
36 |
|
|
37 |
class TestCommandUtil(unittest.TestCase):
|
|
38 |
def test_get_folder_set(self):
|
|
39 |
if os.path.exists(TMP_PATH):
|
|
40 |
shutil.rmtree(TMP_PATH)
|
|
41 |
os.mkdir(TMP_PATH)
|
|
42 |
create_file(TMP_FILE1)
|
|
43 |
fset1 = commandml.get_folder_set(TMP_PATH)
|
|
44 |
|
|
45 |
self.assertEquals(len(fset1), 1)
|
|
46 |
self.assertEquals(fset1, set([norm('sub/one.txt')]))
|
|
47 |
|
|
48 |
create_file(TMP_FILE2)
|
|
49 |
create_file(TMP_FILE3)
|
|
50 |
fset2 = commandml.get_folder_set(TMP_PATH)
|
|
51 |
nset = fset2 - fset1
|
|
52 |
self.assertEquals(nset, set([norm('foobar/two.txt'),
|
|
53 |
norm('three.txt')]))
|
|
54 |
|
|
55 |
|
|
56 |
if __name__ == '__main__':
|
|
57 |
unittest.main()
|