Esempio n. 1
0
    def test_set_func(self):

        c1 = Command('foo', 'my_adder', 'Target', t='t')

        self.failIf(c1.is_set())

        c1.func = lambda x: x
        self.failUnless(c1.is_set())
Esempio n. 2
0
    def test_format_params(self):

        c1 = Command('foo', None, 'a', 'b', c='c')

        form = c1._format_params()

        ans = "( a, b, c=c )"
        self.failUnlessEqual(form, ans)
Esempio n. 3
0
    def testget_all_values(self):

        c1 = Command('tag', 'adder', 1, 2, a=3, b=4)
        c1.add_other_dep(5)

        all_vals = c1.all_values
        set_all = set(all_vals)

        self.failUnlessEqual(set_all, set(range(1, 6)))
Esempio n. 4
0
    def testkeep( self ):
        
        command = Command( 'tag', None, this=True, that=False )
        
        command = mf.keep(command, ['this','foo'] )

        self.failIf( command.has_key('that') )
        
        self.failUnless( command.has_key('this') )
Esempio n. 5
0
    def testgetTargets(self):

        t1 = Target('t1')
        t2 = Target('t2')
        cmd = Command('tag', None, t1)
        cmd2 = Command('tag', None, t2=t2)

        cp = CommandPack([cmd, cmd2])

        tset = set(cp.getTargets())

        self.failUnlessEqual(tset, set([t1, t2]))
Esempio n. 6
0
    def testgetSources(self):

        s1 = Source('t1')
        s2 = Source('t2')
        cmd = Command('tag', None, s1)
        cmd2 = Command('tag', None, s2=s2)

        cp = CommandPack([cmd, cmd2])

        tset = set(cp.getSources())

        self.failUnlessEqual(tset, set([s1, s2]))
Esempio n. 7
0
    def test_init(self):

        c1 = Command('foo', 'my_adder', 'Target', t='t')

        self.failUnlessEqual(c1.tag, 'foo')

        self.failIf(c1.is_set())

        self.failUnlessEqual(c1.adder, 'my_adder', 'foo')

        self.failUnlessEqual(c1.params, ['Target'], 'foo')

        self.failUnlessEqual(c1.kparams, {'t': 't'}, 'foo')
Esempio n. 8
0
    def test_rplace_scalar_str(self):

        scal = Scalar()

        ss = scal.data
        scal.set(3)
        c1 = Command('foo', None)

        snew = c1._rplace_scalar_str(ss)

        self.failUnlessEqual(
            snew,
            '3',
        )
Esempio n. 9
0
 def testdiscard( self ):
     command = Command( 'tag', None, this=True, that=False )
     
     cmd = mf.discard(command, ['that'] )
     
     self.failUnless( cmd.has_key('this') )
     self.failIf( cmd.has_key('that') )
Esempio n. 10
0
 def testsplit( self ):
     
     command = Command( 'tag', None, this=True, that=False )
     
     c1,c2 = mf.split(command)
     
     self.failUnlessEqual( c1, c2 )
     self.failIfEqual( id(c1), id(c2) )
Esempio n. 11
0
 def testkeywordmap( self ):
     
     command = Command( 'tag', None, this=True, that='False' )
     
     cmd = mf.keywordmap(command, {'that':'spam'} )
     
     self.failUnless( cmd.has_key('spam') )
     self.failUnlessEqual(cmd['spam'],  'False' )
     self.failIf( cmd.has_key('that') )
Esempio n. 12
0
    def testtruefalseHelper( self ):
        
        command = Command( 'tag', None, this=True, that=False )
        
        command = mf.truefalseHelper( command, true='tt', false='ff' )
#        command, true='y', false='n'
        
        self.failUnlessEqual( command['this'],'tt')
        self.failUnlessEqual( command['that'],'ff')
Esempio n. 13
0
    def __call__(self, c1, c2):
        """
        add c1 and c2 together to form a pipe command
        @return: a  multiDriver instance
        """
        if isinstance(c1, DataContainer):
            driver = RemoteDriver()

            if isinstance(c2, Command):
                driver.setSource(c1)
                driver.addCommand(c2)

            else:

                raise TypeError(self.ERRORMSG2)

        elif isinstance(c1, Command):

            if isinstance(c1.func, RemoteDriver):
                driver = c1.func
            else:
                driver = RemoteDriver()
                driver.addCommand(c1)

            if isinstance(c2, DataContainer):
                driver.setTarget(c2)

            elif isinstance(c2, Command):
                driver.addCommand(c2)

            elif c2 is None:
                pass
            else:
                raise TypeError(self.ERRORMSG1 % type(c2))
        else:

            raise TypeError(self.ERRORMSG1 % type(c2))

        com = Command("_multi_", self)
        com.func = driver

        return com
Esempio n. 14
0
    def testsetSource(self):

        cp = CommandPack(['comm'])

        self.failUnlessEqual(cp.source, True)

        cp.source = 'tgt'
        self.failUnlessEqual(cp.source, 'tgt')

        cmd = Command('tag', None)
        cp = CommandPack([cmd], in_cont=None)
        self.failUnlessRaises(Exception, setattr, cp, 'source', 'src')

        cmd = Command('tag', None, Source)
        cp = CommandPack([cmd], in_cont=None)

        src = Source('tgt')
        cp.source = src
        self.failUnlessEqual(cp.source, None)
        self.failUnlessEqual(cmd.getSources(), [src])
Esempio n. 15
0
    def testsetTarget(self):

        cp = CommandPack(['comm'])

        self.failUnlessEqual(cp.target, True)

        cp.target = 'tgt'
        self.failUnlessEqual(cp.target, 'tgt')

        cmd = Command('tag', None)
        cp = CommandPack([cmd], out_cont=None)
        self.failUnlessRaises(Exception, setattr, cp, 'target', 'tgt')

        cmd = Command('tag', None, Target)
        cp = CommandPack([cmd], out_cont=None)

        tgt = Target('tgt')
        cp.target = tgt
        self.failUnlessEqual(cp.target, None)
        self.failUnlessEqual(cmd.getTargets(), [tgt])
Esempio n. 16
0
    def testgetNodeList(self):

        cmd = Command('tag', None)

        node = Node(cmd)

        cp = CommandPack([cmd])

        nlist = cp.getNodeList()

        self.failUnlessEqual(nlist, [node])
Esempio n. 17
0
    def testcopy(self):

        foo_tgt = Target('foo')
        bar_tgt = Target('bar')
        spam_src = Source('spam')

        c1 = Command('foo', None, foo_tgt, x=bar_tgt, src=spam_src)

        c2 = c1.copy()

        self.failUnlessEqual(c1, c2)

        self.failIfEqual(id(c1), id(c2))

        func = lambda x: x

        c2.func = func

        self.failIfEqual(c1, c2)

        c1.func = func

        self.failUnlessEqual(c1, c2)
Esempio n. 18
0
    def testsetunusedsource(self):

        foo_src = Source('foo')

        cmd = Command('foo', None, Source)

        cmd.setunusedsource(foo_src)

        sources = cmd.getSources()

        self.failUnlessEqual(sources, [foo_src])

        self.failUnlessRaises(Exception, cmd.setunusedsource, foo_src)

        cmd = Command('foo', None, Target)

        self.failUnlessRaises(Exception, cmd.setunusedsource, foo_src)

        cmd.add_other_dep(foo_src)
        self.failUnlessEqual(sources, [foo_src])
Esempio n. 19
0
    def testsetunusedtarget(self):

        foo_tgt = Target('foo')

        cmd = Command('foo', None, Target)

        cmd.setunusedtarget(foo_tgt)

        targets = cmd.getTargets()

        self.failUnlessEqual(targets, [foo_tgt])

        self.failUnlessRaises(Exception, cmd.setunusedtarget, foo_tgt)

        cmd = Command('foo', None, Source)

        self.failUnlessRaises(Exception, cmd.setunusedtarget, foo_tgt)

        cmd.add_other_dep(foo_tgt)
        self.failUnlessEqual(targets, [foo_tgt])
Esempio n. 20
0
    def test_get_target_cont(self):

        foo_tgt = Target('foo')
        bar_tgt = Target('bar')
        spam_src = Source('spam')

        c1 = Command('foo', None, foo_tgt, x=bar_tgt, src=spam_src)

        tc = c1.target_containers

        self.failUnlessEqual(len(tc), 2)

        self.failUnless('foo' in tc)
        self.failUnless('bar' in tc)

        self.failIf('spam' in tc)
Esempio n. 21
0
    def test_get_source_cont(self):

        foo_src = Source('foo')
        bar_src = Source('bar')
        spam_tgt = Target('spam')

        c1 = Command('foo', None, foo_src, x=bar_src, src=spam_tgt)

        sc = c1.source_containers

        self.failUnlessEqual(len(sc), 2)

        self.failUnless('foo' in sc)
        self.failUnless('bar' in sc)

        self.failIf('spam' in sc)
Esempio n. 22
0
    def testgenerate_command(self):

        struct = Structure()

        _env['slimvars']['keep_tb_info'] = False

        c1 = struct.generate_command('cmnd', a1=11)

        c2 = Command('cmnd', None, a1=11)

        self.failUnlessEqual(c1, c2)
        self.failUnlessEqual(c1.tb_info, None)

        _env['slimvars']['keep_tb_info'] = True

        c1 = struct.generate_command('cmnd', a1=11)
        self.failUnless(isinstance(c1.tb_info, str))
Esempio n. 23
0
    def setUp(self):
        """
        create commands
        """
        self.sourceOf1 = Source(1)
        self.sourceOfBob = Source('bob')

        self.targetOf2 = Target(2)
        self.targetOfFoo = Target('foo')

        self.c1 = Command('testFunc', '__adder', 1, a=2)
        self.c2 = Command('testFunc', '__adder', 3, b=Source)
        self.c3 = Command('testFunc', '__adder', self.sourceOf1,
                          self.sourceOfBob)
        self.c4 = Command('testFunc', '__adder', self.targetOfFoo,
                          self.targetOf2)

        #        for cmd in [self.c1,self.c2,self.c3,self.c4]:
        self.c1.func = testFunc
Esempio n. 24
0
    def test_kw_params(self):

        c1 = Command('foo', None, 'a', 'b', c='c')

        # test has_key
        self.failUnless(c1.has_key('c'))
        self.failIf(c1.has_key('d'))

        self.failUnlessEqual(c1['c'], 'c')

        c1['c'] = 'd'

        self.failUnlessEqual(c1['c'], 'd')

        c1.del_kw('c')

        self.failIf(c1.has_key('c'))
Esempio n. 25
0
    def testgetSources(self):

        foo_src = Source('foo')
        bar_src = Source('bar')
        spam_src = Source('spam')
        spam_tgt = Target('eggs')

        c1 = Command('foo', None, foo_src, x=bar_src, ssc=spam_tgt)
        c1.add_other_dep(spam_src)

        sources = c1.getSources()

        self.failUnless(foo_src in sources)
        self.failUnless(bar_src in sources)
        self.failUnless(spam_src in sources)
        #        print sources
        self.failIf(spam_tgt in sources)

        c1 = Command('foo', None)
        targets = c1.getSources()
        self.failUnlessEqual(targets, [])
Esempio n. 26
0
class CommandTest(unittest.TestCase):
    """
    Test Command Class
    """
    def setUp(self):
        """
        create commands
        """
        self.sourceOf1 = Source(1)
        self.sourceOfBob = Source('bob')

        self.targetOf2 = Target(2)
        self.targetOfFoo = Target('foo')

        self.c1 = Command('testFunc', '__adder', 1, a=2)
        self.c2 = Command('testFunc', '__adder', 3, b=Source)
        self.c3 = Command('testFunc', '__adder', self.sourceOf1,
                          self.sourceOfBob)
        self.c4 = Command('testFunc', '__adder', self.targetOfFoo,
                          self.targetOf2)

        #        for cmd in [self.c1,self.c2,self.c3,self.c4]:
        self.c1.func = testFunc

    def tearDown(self):
        """
        clears the Hashtable singleton class 
        """
        env['table'].clear()

    def testCopy(self):
        """
        test that the copy method works
        """
        c3 = self.c1.copy()

        self.assertEqual(c3, self.c1, "%s != %s" % (c3, self.c1))

        self.assertNotEqual(id(c3), id(self.c1))

    def testRun(self):
        """
        test the run method
        """
        ran = self.c1.run()

        self.assertEqual(ran, ((1, ), {'a': 2}))

        ran = self.c1.run()
        #test that the same function works twice
        self.assertEqual(ran, ((1, ), {'a': 2}))

        # if the function is not set then the command can not run
        self.assertRaises(Exception, self.c2.run)

    def testGetSources(self):
        """
        test that the getSources method returns all of 
        the Source class instances contained within
        the Command 
        """
        sources = self.c3.getSources()

        self.assertEqual(len(sources), 2,
                         "returned more sources than are in the command")

        self.assertTrue(self.sourceOf1 in sources, "missing source of 1")

        self.assertTrue(self.sourceOfBob in sources, "missing source of bob")

        noSources = self.c1.getSources()

        self.assertEqual(len(noSources), 0,
                         "returned more sources than are in the command")

    def testGetTargets(self):
        """
        test that the getTargets method returns all of 
        the Target class instances contained within
        the Command 
        """
        targets = self.c4.getTargets()

        self.assertEqual(len(targets), 2,
                         "returned more targets than are in the command")

        self.assertTrue(self.targetOf2 in targets, "missing target of 1")

        self.assertTrue(self.targetOfFoo in targets, "missing target of bob")

        noTargets = self.c1.getTargets()

        self.assertEqual(len(noTargets), 0,
                         "returned more targets than are in the command")

    def test_params(self):
        """
        test the Command.params manipulation functions
        """

        c1 = self.c1.copy()

        c1.del_par(0)

        self.failUnlessEqual(c1.params, [])

        self.failUnlessRaises(IndexError, c1.del_par, 0)
        self.failUnlessRaises(IndexError, c1.del_par, 99)

        c2 = self.c2.copy()

        par = c2.pop_par(0)

        self.failUnlessEqual(par, 3)
        self.failUnlessEqual(c1.params, [])

        self.failUnlessRaises(IndexError, c1.del_par, 0)
        self.failUnlessRaises(IndexError, c1.del_par, 99)


#        if NI: raise NotImplementedError("test not implemented")

    def test_adder(self):

        if NI: raise NotImplementedError("test not implemented")

    def testhas_unusedtarget(self):

        cmd = Command('foo', None, Target)

        self.failUnless(cmd.has_unusedtarget())

        cmd = Command('foo', None, t=Target)

        self.failUnless(cmd.has_unusedtarget())

        cmd = Command('foo', None)
        cmd.add_other_dep(Target)
        self.failUnless(cmd.has_unusedtarget())

        self.failIf(self.c1.has_unusedtarget())

    def testsetunusedtarget(self):

        foo_tgt = Target('foo')

        cmd = Command('foo', None, Target)

        cmd.setunusedtarget(foo_tgt)

        targets = cmd.getTargets()

        self.failUnlessEqual(targets, [foo_tgt])

        self.failUnlessRaises(Exception, cmd.setunusedtarget, foo_tgt)

        cmd = Command('foo', None, Source)

        self.failUnlessRaises(Exception, cmd.setunusedtarget, foo_tgt)

        cmd.add_other_dep(foo_tgt)
        self.failUnlessEqual(targets, [foo_tgt])

    def testgetTargets(self):

        foo_tgt = Target('foo')
        bar_tgt = Target('bar')
        spam_tgt = Target('spam')
        spam_src = Source('eggs')

        c1 = Command('foo', None, foo_tgt, x=bar_tgt, ssc=spam_src)
        c1.add_other_dep(spam_tgt)

        targets = c1.getTargets()

        self.failUnless(foo_tgt in targets)
        self.failUnless(bar_tgt in targets)
        self.failUnless(spam_tgt in targets)

        self.failIf(spam_src in targets)

        c1 = Command('foo', None)
        targets = c1.getTargets()
        self.failUnlessEqual(targets, [])

    def test_set_func(self):

        c1 = Command('foo', 'my_adder', 'Target', t='t')

        self.failIf(c1.is_set())

        c1.func = lambda x: x
        self.failUnless(c1.is_set())

    def test_init(self):

        c1 = Command('foo', 'my_adder', 'Target', t='t')

        self.failUnlessEqual(c1.tag, 'foo')

        self.failIf(c1.is_set())

        self.failUnlessEqual(c1.adder, 'my_adder', 'foo')

        self.failUnlessEqual(c1.params, ['Target'], 'foo')

        self.failUnlessEqual(c1.kparams, {'t': 't'}, 'foo')

    def test_format_params(self):

        c1 = Command('foo', None, 'a', 'b', c='c')

        form = c1._format_params()

        ans = "( a, b, c=c )"
        self.failUnlessEqual(form, ans)

    def test_kw_params(self):

        c1 = Command('foo', None, 'a', 'b', c='c')

        # test has_key
        self.failUnless(c1.has_key('c'))
        self.failIf(c1.has_key('d'))

        self.failUnlessEqual(c1['c'], 'c')

        c1['c'] = 'd'

        self.failUnlessEqual(c1['c'], 'd')

        c1.del_kw('c')

        self.failIf(c1.has_key('c'))

    def test_get_target_cont(self):

        foo_tgt = Target('foo')
        bar_tgt = Target('bar')
        spam_src = Source('spam')

        c1 = Command('foo', None, foo_tgt, x=bar_tgt, src=spam_src)

        tc = c1.target_containers

        self.failUnlessEqual(len(tc), 2)

        self.failUnless('foo' in tc)
        self.failUnless('bar' in tc)

        self.failIf('spam' in tc)

    def testcopy(self):

        foo_tgt = Target('foo')
        bar_tgt = Target('bar')
        spam_src = Source('spam')

        c1 = Command('foo', None, foo_tgt, x=bar_tgt, src=spam_src)

        c2 = c1.copy()

        self.failUnlessEqual(c1, c2)

        self.failIfEqual(id(c1), id(c2))

        func = lambda x: x

        c2.func = func

        self.failIfEqual(c1, c2)

        c1.func = func

        self.failUnlessEqual(c1, c2)

    def test_rplace_scalar_str(self):

        scal = Scalar()

        ss = scal.data
        scal.set(3)
        c1 = Command('foo', None)

        snew = c1._rplace_scalar_str(ss)

        self.failUnlessEqual(
            snew,
            '3',
        )

    def testgetSources(self):

        foo_src = Source('foo')
        bar_src = Source('bar')
        spam_src = Source('spam')
        spam_tgt = Target('eggs')

        c1 = Command('foo', None, foo_src, x=bar_src, ssc=spam_tgt)
        c1.add_other_dep(spam_src)

        sources = c1.getSources()

        self.failUnless(foo_src in sources)
        self.failUnless(bar_src in sources)
        self.failUnless(spam_src in sources)
        #        print sources
        self.failIf(spam_tgt in sources)

        c1 = Command('foo', None)
        targets = c1.getSources()
        self.failUnlessEqual(targets, [])

    def testget_structure(self):

        if NI: raise NotImplementedError("test not implemented")

    def test_get_source_cont(self):

        foo_src = Source('foo')
        bar_src = Source('bar')
        spam_tgt = Target('spam')

        c1 = Command('foo', None, foo_src, x=bar_src, src=spam_tgt)

        sc = c1.source_containers

        self.failUnlessEqual(len(sc), 2)

        self.failUnless('foo' in sc)
        self.failUnless('bar' in sc)

        self.failIf('spam' in sc)

    def testhas_unusedsource(self):

        cmd = Command('foo', None, Source)

        self.failUnless(cmd.has_unusedsource())

        cmd = Command('foo', None, t=Source)

        self.failUnless(cmd.has_unusedsource())

        cmd = Command('foo', None)
        cmd.add_other_dep(Source)
        self.failUnless(cmd.has_unusedsource())

        self.failIf(self.c1.has_unusedsource())

    def testsetunusedsource(self):

        foo_src = Source('foo')

        cmd = Command('foo', None, Source)

        cmd.setunusedsource(foo_src)

        sources = cmd.getSources()

        self.failUnlessEqual(sources, [foo_src])

        self.failUnlessRaises(Exception, cmd.setunusedsource, foo_src)

        cmd = Command('foo', None, Target)

        self.failUnlessRaises(Exception, cmd.setunusedsource, foo_src)

        cmd.add_other_dep(foo_src)
        self.failUnlessEqual(sources, [foo_src])

    def testget_all_values(self):

        c1 = Command('tag', 'adder', 1, 2, a=3, b=4)
        c1.add_other_dep(5)

        all_vals = c1.all_values
        set_all = set(all_vals)

        self.failUnlessEqual(set_all, set(range(1, 6)))
Esempio n. 27
0
    def testhas_unusedtarget(self):

        cmd = Command('foo', None, Target)

        self.failUnless(cmd.has_unusedtarget())

        cmd = Command('foo', None, t=Target)

        self.failUnless(cmd.has_unusedtarget())

        cmd = Command('foo', None)
        cmd.add_other_dep(Target)
        self.failUnless(cmd.has_unusedtarget())

        self.failIf(self.c1.has_unusedtarget())
Esempio n. 28
0
    def testhas_unusedsource(self):

        cmd = Command('foo', None, Source)

        self.failUnless(cmd.has_unusedsource())

        cmd = Command('foo', None, t=Source)

        self.failUnless(cmd.has_unusedsource())

        cmd = Command('foo', None)
        cmd.add_other_dep(Source)
        self.failUnless(cmd.has_unusedsource())

        self.failIf(self.c1.has_unusedsource())