configurationengine/source/cone/report/tests/unittest_report.py
changeset 3 e7e0ae78773e
equal deleted inserted replaced
2:87cfa131b535 3:e7e0ae78773e
       
     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 os
       
    18 import unittest
       
    19 
       
    20 from cone.report import generation_report
       
    21 from cone.public import plugin, api
       
    22 from testautomation.utils import remove_if_exists
       
    23 
       
    24 
       
    25 ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
       
    26 TEMP_DIR     = os.path.normpath(os.path.join(ROOT_PATH, 'temp'))
       
    27 
       
    28 class TestGenerateReport(unittest.TestCase):
       
    29     def setUp(self):
       
    30         remove_if_exists(TEMP_DIR)
       
    31 
       
    32     def test_create_report_data(self):
       
    33         rdata = generation_report.ReportData()
       
    34         self.assertEquals(rdata.context, None)
       
    35 
       
    36     def test_save_load_empty_report_data(self):
       
    37         rdata = generation_report.ReportData()
       
    38         tmpfile = os.path.join(TEMP_DIR, 'repdata.dat')
       
    39         generation_report.save_report_data(rdata, tmpfile)
       
    40         rdata2 = generation_report.load_report_data(tmpfile)
       
    41         self.assertEquals(repr(rdata), repr(rdata2))
       
    42 
       
    43     def test_save_load_report_data_with_some_content(self):
       
    44         rdata = generation_report.ReportData()
       
    45         p = api.Project(api.Storage.open(TEMP_DIR, 'w'))
       
    46         config = api.Configuration('test.confml')
       
    47         fea = config.create_feature('Foo')
       
    48         fea.create_feature('Child1')
       
    49         fea.create_feature('Child2')
       
    50         c3 = fea.create_feature('Child3')
       
    51         c3.value = 'test'
       
    52         rdata.log = ['one',
       
    53                      'two',
       
    54                      'three']
       
    55         p.add_configuration(config)
       
    56         p.save()
       
    57         rdata.context = plugin.GenerationContext(phase="pre",
       
    58                                                  tags={'target' : 'rofs3'},
       
    59                                                  output='foo',
       
    60                                                  configuration=config,
       
    61                                                  project=p)
       
    62         
       
    63         tmpfile = os.path.join(TEMP_DIR, 'repdata.dat')
       
    64         generation_report.save_report_data(rdata, tmpfile)
       
    65         rdata2 = generation_report.load_report_data(tmpfile)
       
    66         self.assertEquals(repr(rdata), repr(rdata2))
       
    67         self.assertEquals(rdata.log, rdata2.log) 
       
    68         self.assertEquals(rdata.log, rdata2.log) 
       
    69         self.assertEquals(rdata2.context.phase, 'pre')
       
    70         self.assertEquals(rdata2.context.tags, {'target' : 'rofs3'})
       
    71         self.assertEquals(rdata2.context.output, 'foo')
       
    72         self.assertEquals(rdata2.context.configuration.Foo.Child3.fqr, 'Foo.Child3')
       
    73         self.assertEquals(rdata2.context.configuration.Foo.Child3.get_value(), 'test')
       
    74         self.assertEquals(rdata2.context.configuration.Foo.Child3.value, 'test')
       
    75 
       
    76     def test_save_load_report_data_with_real_content(self):
       
    77         prj = api.Project(api.Storage.open(os.path.join(ROOT_PATH,'project')))
       
    78         config = prj.get_configuration('root.confml')
       
    79         impls = plugin.get_impl_set(config)
       
    80         context = plugin.GenerationContext(phase="normal",
       
    81                                            tags={'target' : ['rofs2']},
       
    82                                            output='temp',
       
    83                                            configuration=config)
       
    84                 
       
    85         impls.generate(context)
       
    86         prj = config.get_project()
       
    87         c1 = config.get_configuration('layer1/root.confml')
       
    88         
       
    89         self.assertEquals(len(context.generation_output), 4)
       
    90         rdata = generation_report.ReportData()
       
    91         rdata.context = context
       
    92         rdata.project = prj
       
    93         tmpfile = os.path.join(TEMP_DIR, 'repdata_real.dat')
       
    94         generation_report.save_report_data(rdata, tmpfile)
       
    95         rdata2 = generation_report.load_report_data(tmpfile)
       
    96         self.assertEquals(repr(rdata), repr(rdata2))
       
    97         dview = rdata2.context.configuration.get_default_view()
       
    98         self.assertEquals(len(rdata2.context.generation_output), 4)
       
    99 
       
   100 
       
   101 if __name__ == '__main__':
       
   102     unittest.main()