unittests.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- Python -*-
00003 # -*- coding: utf-8 -*-
00004 
00005 '''rtshell
00006 
00007 Copyright (C) 2009-2010
00008     Geoffrey Biggs
00009     RT-Synthesis Research Group
00010     Intelligent Systems Research Institute,
00011     National Institute of Advanced Industrial Science and Technology (AIST),
00012     Japan
00013     All rights reserved.
00014 Licensed under the Eclipse Public License -v 1.0 (EPL)
00015 http://www.opensource.org/licenses/eclipse-1.0.txt
00016 
00017 Unit tests.
00018 
00019 '''
00020 
00021 
00022 import unittest
00023 
00024 import rtshell.eval_const
00025 import rtshell.rts_exceptions
00026 import rtshell.port_types
00027 import rtshell.user_mods
00028 
00029 import blorg
00030 
00031 
00032 class TestUserMods(unittest.TestCase):
00033     def test_load_mods(self):
00034         mods = rtshell.user_mods.load_mods('test_mod1,test_mod2')
00035         self.assertEqual(len(mods), 2)
00036         self.assertEqual(mods[0].name, 'test_mod1')
00037         self.assertEqual(type(mods[0].mod), type(rtshell.user_mods))
00038         self.assertEqual(mods[1].name, 'test_mod2')
00039         self.assertEqual(type(mods[1].mod), type(rtshell.user_mods))
00040         self.assertRaises(ImportError, rtshell.user_mods.load_mods, 'blurgle')
00041 
00042     def test_load_mods_and_poas(self):
00043         mods = rtshell.user_mods.load_mods_and_poas('test_mod1,test_mod2')
00044         self.assertEqual(len(mods), 4)
00045         self.assertEqual(mods[0].name, 'test_mod1')
00046         self.assertEqual(type(mods[0].mod), type(rtshell.user_mods))
00047         self.assertEqual(mods[1].name, 'test_mod1__POA')
00048         self.assertEqual(type(mods[1].mod), type(rtshell.user_mods))
00049         self.assertRaises(ImportError, rtshell.user_mods.load_mods_and_poas,
00050                 'blorg')
00051 
00052 
00053 class TestEvalConst(unittest.TestCase):
00054     def setUp(self):
00055         self.mods = [rtshell.user_mods.Module('test_mod1')]
00056         self.const = 'test_mod1.Dummy(4,2)'
00057 
00058     def test_replace_mod_name(self):
00059         self.assertEqual(rtshell.eval_const.replace_mod_name(self.const,
00060             self.mods), 'mods[0].mod.Dummy(4,2)')
00061 
00062     def test_replace_time(self):
00063         const = 'blurgle({time})'
00064         self.assert_(len(rtshell.eval_const.replace_time(const)) > len(const))
00065 
00066     def test_eval_const(self):
00067         class Data(object):
00068             def __init__(self, val):
00069                 self.val = val
00070 
00071         self.assertEqual(rtshell.eval_const.eval_const('1', self.mods), 1)
00072         self.assertEqual(rtshell.eval_const.eval_const('list((1, 2, 3))',
00073             self.mods), [1, 2, 3])
00074 
00075 
00076 class TestParseTargets(unittest.TestCase):
00077     def setUp(self):
00078         self.p1 = (['/', 'localhost', 'my.host_cxt', 'comp0.rtc'], 'input0',
00079                 'namae', 'blorg.format')
00080         self.p2 = (['/', 'localhost', 'my.host_cxt', 'comp1.rtc'], 'out_put1',
00081                 'namae2', None)
00082         self.p3 = (['/', 'localhost', 'my.host_cxt', 'comp1.rtc'], 'out_put1',
00083                 None, 'blorg.format')
00084         self.p4 = (['/', 'localhost', 'my.host_cxt', 'comp0.rtc'], 'input0',
00085                 None, None)
00086 
00087     def test_parse_targets(self):
00088         ps = rtshell.port_types.parse_targets(['/localhost/my.host_cxt/comp0.rtc:input0.namae#blorg.format',
00089             '/localhost/my.host_cxt/comp1.rtc:out_put1.namae2',
00090             '/localhost/my.host_cxt/comp1.rtc:out_put1#blorg.format',
00091             '/localhost/my.host_cxt/comp0.rtc:input0'])
00092         self.assertEqual(ps[0], self.p1)
00093         self.assertEqual(ps[1], self.p2)
00094         self.assertEqual(ps[2], self.p3)
00095         self.assertEqual(ps[3], self.p4)
00096         self.assertRaises(rtshell.rts_exceptions.BadPortSpecError,
00097                 rtshell.port_types.parse_targets, ['this_is_wrong'])
00098         self.assertRaises(rtshell.rts_exceptions.BadPortSpecError,
00099                 rtshell.port_types.parse_targets, ['/localhost/comp0.rtc'])
00100         self.assertRaises(rtshell.rts_exceptions.BadPortSpecError,
00101                 rtshell.port_types.parse_targets, [''])
00102 
00103 
00104 if __name__ == '__main__':
00105     unittest.main()
00106 
00107 
00108 # vim: tw=79
00109 


rtshell
Author(s): Geoffrey Biggs
autogenerated on Fri Aug 28 2015 12:55:12