587
|
1 |
#============================================================================
|
|
2 |
#Name : test_bomtofile.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 BOM to file"""
|
|
20 |
|
628
|
21 |
# pylint: disable=R0201
|
587
|
22 |
|
|
23 |
import tempfile
|
|
24 |
from shutil import rmtree
|
|
25 |
import logging
|
|
26 |
import unittest
|
|
27 |
from bomtofile import BOMWriter
|
|
28 |
|
|
29 |
_logger = logging.getLogger('test.bomtofile')
|
|
30 |
logging.basicConfig(level=logging.INFO)
|
|
31 |
|
|
32 |
class BomtofileTest(unittest.TestCase):
|
|
33 |
"""Verifiying bomtofile module"""
|
|
34 |
|
|
35 |
def test_writeprojects(self):
|
|
36 |
"""Verifying writeprojects"""
|
|
37 |
tmpdir = tempfile.mkdtemp()
|
|
38 |
testProject = _emulateProject(("testProject1", "testProject2"))
|
|
39 |
bomWriter = BOMWriter(None, "PythonUnitTesting", testProject, tmpdir)
|
|
40 |
bomWriter.writeprojects()
|
|
41 |
myFile = open(tmpdir+"/PythonUnitTesting_projects.txt",'r')
|
|
42 |
contents = myFile.readlines()
|
|
43 |
myFile.close()
|
|
44 |
rmtree(tmpdir)
|
|
45 |
assert len(contents) == 2
|
|
46 |
|
|
47 |
def test_writebaselines(self):
|
|
48 |
"""Verifying writebaselines"""
|
|
49 |
tmpdir = tempfile.mkdtemp()
|
|
50 |
testProject = _emulateProject(("testProject1", "testProject2"))
|
|
51 |
testSession = _emulateSession("testbaseline1")
|
|
52 |
bomWriter = BOMWriter(testSession, "PythonUnitTesting", testProject, tmpdir)
|
|
53 |
bomWriter.writebaselines()
|
|
54 |
myFile = open(tmpdir+"/PythonUnitTesting_baselines.txt",'r')
|
|
55 |
contents = myFile.readlines()
|
|
56 |
myFile.close()
|
|
57 |
rmtree(tmpdir)
|
|
58 |
assert len(contents) == 4
|
|
59 |
|
|
60 |
def test_writebaselines_withnodata(self):
|
|
61 |
"""Verifying writebaselines with no baseline"""
|
|
62 |
tmpdir = tempfile.mkdtemp()
|
|
63 |
testProject = _emulateProject(("testProject1", "testProject2"))
|
|
64 |
testSession = _emulateSession(None)
|
|
65 |
bomWriter = BOMWriter(testSession, "PythonUnitTesting", testProject, tmpdir)
|
|
66 |
bomWriter.writebaselines()
|
|
67 |
myFile = open(tmpdir+"/PythonUnitTesting_baselines.txt",'r')
|
|
68 |
contents = myFile.readlines()
|
|
69 |
myFile.close()
|
|
70 |
rmtree(tmpdir)
|
|
71 |
assert len(contents) == 4
|
|
72 |
|
|
73 |
|
|
74 |
def test_writetasks(self):
|
|
75 |
"""Verifying writetasks"""
|
|
76 |
tmpdir = tempfile.mkdtemp()
|
|
77 |
testProject = _emulateProject(None, ("testTask1", "testTask2"))
|
|
78 |
bomWriter = BOMWriter(None, "PythonUnitTesting", testProject, tmpdir)
|
|
79 |
bomWriter.writetasks()
|
|
80 |
myFile = open(tmpdir+"/PythonUnitTesting_tasks.txt",'r')
|
|
81 |
contents = myFile.readlines()
|
|
82 |
myFile.close()
|
|
83 |
rmtree(tmpdir)
|
|
84 |
assert len(contents) == 2
|
|
85 |
|
|
86 |
class _emulateProject():
|
|
87 |
"""Emulate a project"""
|
|
88 |
def __init__(self, project = None, task = None):
|
|
89 |
self.baseline = project
|
|
90 |
self.task = task
|
|
91 |
# just emulate amara xml_properties dictionary, as the idea is
|
|
92 |
# not to test xml file processing with amara
|
|
93 |
self.xml_properties = { 'task': None }
|
|
94 |
|
|
95 |
class _emulateSession():
|
|
96 |
"""Emulate a session"""
|
|
97 |
def __init__(self, baseline):
|
|
98 |
self.baseline = baseline
|
|
99 |
|
588
|
100 |
def create(self, _):
|
|
101 |
"""create"""
|
587
|
102 |
return _emulateProject(self.baseline)
|