buildframework/helium/tools/common/python/lib/cpythontest/test_buildmodel.py
author wbernard
Wed, 23 Dec 2009 19:29:07 +0200
changeset 179 d8ac696cc51f
permissions -rw-r--r--
helium_7.0-r14027
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
179
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     1
#============================================================================ 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     2
#Name        : test_buildmodel.py 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     3
#Part of     : Helium 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     4
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     5
#Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     6
#All rights reserved.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     7
#This component and the accompanying materials are made available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     8
#under the terms of the License "Eclipse Public License v1.0"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
     9
#which accompanies this distribution, and is available
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    10
#at the URL "http://www.eclipse.org/legal/epl-v10.html".
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    11
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    12
#Initial Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    13
#Nokia Corporation - initial contribution.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    14
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    15
#Contributors:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    16
#
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    17
#Description:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    18
#===============================================================================
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    19
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    20
""" Test build.model module. """
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    21
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    22
import os
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    23
import sys
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    24
import tempfile
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    25
import unittest
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    26
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    27
import build.model
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    28
import configuration
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    29
import ccm
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    30
import amara
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    31
import logging
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    32
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    33
_logger = logging.getLogger('test.bom')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    34
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    35
database = "to1tobet"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    36
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    37
class BOMMockFolder:    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    38
    def __init__(self, name, instance, description, tasks):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    39
        self.name = name
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    40
        self.instance = instance
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    41
        self.description = description
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    42
        self.tasks = tasks
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    43
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    44
class BOMMockProject:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    45
    def __init__(self, name):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    46
        self.name = name
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    47
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    48
    def __str__(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    49
        return self.name
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    50
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    51
    @property
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    52
    def tasks(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    53
        return []
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    54
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    55
    @property
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    56
    def folders(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    57
        return [BOMMockFolder('5856', 'tr1s60', "all completed tasks for release ABS_domain/abs.mcl for collaborative projects", [])] 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    58
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    59
class BOMMock:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    60
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    61
    def __init__(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    62
        self.config = {}
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    63
        self.config['build.id'] = "mock"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    64
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    65
    @property
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    66
    def projects(self):    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    67
        return [BOMMockProject('ABS_domain-abs.mcl_200843:project:tr1s60#1')] 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    68
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    69
    def all_baselines(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    70
        return []
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    71
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    72
# Refactor required: See http://delivery.nmp.nokia.com/trac/helium/ticket/1517
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    73
class BOMTest(unittest.TestCase):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    74
    """ Test BOM and related classes. """
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    75
    
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    76
# TODO - removed until non-Synergy dependent tests can be provided.
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    77
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    78
#    def test_bom_output(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    79
#        """ Test basic BOM execution. Only new spec format will be covered!"""
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    80
#        try:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    81
#            session = ccm.open_session(database=database)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    82
#        except ccm.CCMException:
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    83
#            print "Skipping BOMTest test cases."
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    84
#            return
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    85
#            
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    86
#        project = session.create('helium-helium_0.1:project:vc1s60p1#1')
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    87
#        config_dict = {'delivery': 'tests/data/test_delivery.xml',
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    88
#                       'prep.xml': 'tests/data/test_prep.xml',
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    89
#                       'build.id': "test_0.0",
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    90
#                       'ccm.database': session.database()}
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    91
#        config = configuration.Configuration(config_dict)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    92
#        bom = build.model.BOM_new_spec_config(config, project)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    93
#        writer = build.model.BOMHTMLWriter(bom)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    94
#        writer.write("bom2.html")
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    95
#        session.close()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    96
#        os.remove("bom2.html")
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    97
#        os.remove("bom2.html.xml")
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    98
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
    99
    def test_bom_delta(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   100
        """ Testing BOM delta creation... """
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   101
        delta = build.model.BOMDeltaXMLWriter(BOMMock(), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/build_model_bom.xml'))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   102
        delta.write(os.path.join(os.environ['HELIUM_HOME'], 'build','delta.xml'))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   103
        xml = amara.parse(open(os.path.join(os.environ['HELIUM_HOME'], 'build','delta.xml'), 'r'))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   104
        assert xml.bomDelta[0].buildFrom[0] == "ido_raptor_mcl_abs_MCL.52.57"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   105
        assert xml.bomDelta[0].buildTo[0] == "mock"
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   106
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   107
        print "baselines: ", len(xml.bomDelta.content.baseline)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   108
        print "folders: ", len(xml.bomDelta.content.folder)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   109
        print "tasks: ", len(xml.bomDelta.content.task)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   110
        print "baseline[@overridden='false']:", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']"))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   111
        print "baseline[@overridden='true']: ", len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']"))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   112
        print "folder[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']"))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   113
        print "task[@status='deleted']: ", len(xml.bomDelta.content.xml_xpath("task[@status='deleted']"))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   114
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   115
        assert len(xml.bomDelta.content.baseline) == 156
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   116
        assert len(xml.bomDelta.content.folder) == 1
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   117
        assert len(xml.bomDelta.content.task) == 1
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   118
        assert len(xml.bomDelta.content.xml_xpath("baseline[@overridden='false']")) == 155
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   119
        assert len(xml.bomDelta.content.xml_xpath("baseline[@overridden='true']")) == 1
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   120
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   121
        assert len(xml.bomDelta.content.xml_xpath("folder[@status='deleted']")) == 1
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   122
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   123
        assert len(xml.bomDelta.content.xml_xpath("task[@status='deleted']")) == 1
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   124
        
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   125
    def test_validate_bom_delta(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   126
        """ Testing BOM delta validation... """
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   127
        bom_delta_validate = build.model.BOMDeltaXMLWriter((os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml')), (os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml')))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   128
        delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml'))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   129
        self.assertEqual(True, delta_bom_content_validity) 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   130
        delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_104_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_101_bom.xml'))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   131
        self.assertEqual(False, delta_bom_content_validity) 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   132
        delta_bom_content_validity = bom_delta_validate.validate_delta_bom_contents(os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_103_bom_delta.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_103_bom.xml'), os.path.join(os.environ['HELIUM_HOME'], 'tests/data/bom/bom_validate_102_bom.xml'))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   133
        self.assertEqual(None, delta_bom_content_validity) 
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   134
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   135
    def test_BOMXMLWriter(self):
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   136
        config_data = {'delivery': 'tests/data/test_delivery.xml', 'prep.xml': 'tests/data/test_prep.xml', 'build.id': 'buildid', 'symbian_rel_week': r'${symbian.version.week}', 'symbian_rel_ver': r'${symbian.version}', 'symbian_rel_year': r'${symbian.version.year}', 's60_version': r'${s60.version}', 's60_release': r'${s60.release}', 'currentRelease.xml': "tests/data/symrec/generated_release_metadata.xml"}
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   137
        bom = build.model.BOM(configuration.Configuration(config_data))
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   138
        xml_writer = build.model.BOMXMLWriter(bom)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   139
        (_, filename) = tempfile.mkstemp()
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   140
        xml_writer.write(filename)
d8ac696cc51f helium_7.0-r14027
wbernard
parents:
diff changeset
   141
        #_logger.info(open(filename).read())