Ejemplo n.º 1
0
    def test_isAutoAlias(self):
        at = AT()
        ret = at.isAutoAlias()
        self.assertTrue(ret)  # should be true

        at = AT({'alias': 'alias_test', 'test_key': 'at_test'})
        ret = at.isAutoAlias(withEmpty=False)
        self.assertFalse(ret)  # should be false
Ejemplo n.º 2
0
    def test_AT_isAutoAlias(self):
        """ test AT isAutoAlias() """
        at = AT()
        self.assertTrue(at.isAutoAlias())

        at = AT({'alias': 'alias_test', 'test_key': 'at_test'})
        ret = at.isAutoAlias(withEmpty=False)
        self.assertFalse(ret)
Ejemplo n.º 3
0
    def test_AT_markUpToDate(self):
        """ test AT isstale(), markUpToDate() """
        at = AT({'alias': 'n'})
        self.assertTrue(at.isstale())

        at.markUpToDate()
        self.assertFalse(at.isstale())
Ejemplo n.º 4
0
 def test_AT_baseDir(self):
     """ test AT baseDir(), dir() """
     at = AT({'alias': 'g'})
     basedir = at.baseDir("/tmp/")
     self.assertEqual(basedir, "/tmp/")
     fullpath = at.dir("test.test")
     self.assertEqual(fullpath, "/tmp/test.test")
Ejemplo n.º 5
0
    def test_baseDir(self):
        at = AT({'alias': 'g'})
        basedir = at.baseDir("/tmp/")
        if (self.verbose):
            print "\nAT Class base directory", basedir

        self.assertEqual(basedir, "/tmp/")
Ejemplo n.º 6
0
    def test_output(self):
        at = AT({'alias': 'b'})
        bdpout = len(at)
        if (self.verbose):
            print "\nAT Class number of BDP out:", bdpout

        self.assertEqual(bdpout, 0)  ## should have no output bdp
Ejemplo n.º 7
0
    def test_len2(self):
        at = AT({'alias': 'c'})
        tuple = at.len2()  # bdp_in and bdp_out tuple
        if (self.verbose):
            print "\nAT Class (bdp_in, bdp_out):", tuple

        self.assertEqual(tuple, (0, 0))  ## should be (0,0)
Ejemplo n.º 8
0
 def test_AT_loggername(self):
     """ test AT set/getloggername() """
     at = AT({'alias': 'log'})
     name = "admit_logger"
     at.setloggername(name)
     ret = at.getloggername()
     self.assertEqual(ret, name)
Ejemplo n.º 9
0
    def test_key(self):
        at = AT({'alias': 't', 'test_key': 'at_test'})
        key = "test_key"
        val = "TEST"

        t1 = at.haskey("testtesttest")  # invalid key
        self.assertEqual(t1, False)

        # test haskey()
        t1 = at.haskey(key)  # AT should have the key set at init
        self.assertTrue(t1)

        # test setkey()
        at.setkey(name=key, value=val, isinit=True)

        # test getkey()
        ret = at.getkey(key)
        if (self.verbose):
            print "\n test key:", ret

        self.assertEqual(ret, "TEST")

        # test {key:val} way of setting a key
        at.setkey(name={key: "TEST2"})

        ret = at.getkey(key)
        if (self.verbose):
            print "\n alias key:", ret

        self.assertEqual(ret, "TEST2")
Ejemplo n.º 10
0
    def test_checktype(self):
        at = AT()
        bdp = BDP()
        ret = at.checktype(bdp)

        self.assertEquals(ret,
                          None)  # should be None without raising an exception
Ejemplo n.º 11
0
    def test_input(self):
        at = AT({'alias': 'a'})
        bdpin = len(at._bdp_in)
        if (self.verbose):
            print "\nAT Class number of BDP in:", bdpin

        self.assertEqual(bdpin, 0)  ## should have no input bdp
Ejemplo n.º 12
0
    def test_effectivelevel(self):
        at = AT({'alias': 'f'})
        at.seteffectivelevel(40)
        level = at.geteffectivelevel()
        if (self.verbose):
            print "\nAT Class effective logging level", level

        self.assertEqual(level, 40)
Ejemplo n.º 13
0
    def test_enabled(self):
        at = AT({'alias': 'm'})
        at.enabled(False)
        after = at._enabled
        if (self.verbose):
            print "\nAT Class state _enabled", after

        self.assertEqual(after, False)
Ejemplo n.º 14
0
 def test_AT_logginglevel(self):
     """ test AT setlogginglevel and getlogginglevel methods """
     # CRITICAL    50
     at = AT({'alias': 'e'})
     at.setlogginglevel(50)
     level = at.getlogginglevel()
     self.assertEqual(level, 50)
     self.assertEqual(level, logging.CRITICAL)
Ejemplo n.º 15
0
    def test_dir(self):
        at = AT({'alias': 'h'})
        basedir = at.baseDir("/tmp/")
        fullpath = at.dir("test.test")
        if (self.verbose):
            print "\nAT Fullpath:", fullpath

        self.assertEqual(fullpath, "/tmp/test.test")
Ejemplo n.º 16
0
    def test_markChanged(self):
        at = AT({'alias': 'p'})
        at.markChanged()
        state = at._stale
        if (self.verbose):
            print "\nAT Class state _stale", state

        self.assertEqual(state, True)
Ejemplo n.º 17
0
    def test_mkext(self):
        at = AT({'alias': 'k'})
        t1 = at.mkext("x", "z")  # return 'x-k.z'
        t2 = at.mkext("x.y", "z")  # return 'x-k.z'
        t3 = at.mkext("x.y", "z", "a")  # return 'x-a.z'

        self.assertEqual(t1, "x-k.z")
        self.assertEqual(t2, "x-k.z")
        self.assertEqual(t3, "x-a.z")
Ejemplo n.º 18
0
    def test_loggername(self):
        at = AT({'alias': 'log'})
        name = "admit_logger"
        at.setloggername(name)
        ret = at.getloggername()
        if (self.verbose):
            print "\nAT Class Logger Name:", name

        self.assertEqual(ret, name)
Ejemplo n.º 19
0
    def test_AT_getsetAlias(self):
        """ test AT get(), set(), setAlias """
        at = AT({'alias': 'test'})
        self.assertEqual(at.get('_alias'), 'test')

        at.set('_alias', 'alias_test')
        self.assertEqual(at.get('_alias'), 'alias_test')

        alias = ({'w': 0}, 0)
        at.setAlias(alias, 'alias_test_2')
        self.assertEqual(at.get('_alias'), 'alias_test_2')
Ejemplo n.º 20
0
 def test_AT_projectID(self):
     """ test AT setProject(), getProject(), id() """
     at = AT({'alias': 'q'})
     self.project.addtask(at)
     # get the taskid before adding project id
     tid = at._taskid
     # now set the project id
     at.setProject(2)
     self.assertEqual(at.getProject(), 2)
     # now strip out the project id from _taskid
     self.assertEqual(at.id(True), tid)
Ejemplo n.º 21
0
    def test_get_set(self):
        at = AT({'alias': 'test'})
        ret = at.get('_alias')
        self.assertTrue(ret == 'test')

        at.set('_alias', 'alias_test')
        ret = at.get('_alias')
        self.assertEqual(ret, 'alias_test')

        at.setAlias(({'w': 0}, 0), 'alias_test_2')
        ret = at.get('_alias')
        self.assertEqual(ret, 'alias_test_2')
Ejemplo n.º 22
0
    def test_markUpToDate(self):
        at = AT({'alias': 'n'})
        state = at.isstale()
        if (self.verbose):
            print "\nAT Class state", state

        self.assertTrue(state)  # should be True

        at.markUpToDate()
        state = at.isstale()
        if (self.verbose):
            print "\nAT Class state", state  # should be False

        self.assertFalse(state)
Ejemplo n.º 23
0
    def test_AT_mkdir(self):
        """ test AT mkdir() """
        at = AT({'alias': 's'})
        # test with full path
        tmpdir = "/tmp/test1_%d" % os.getpid()
        at.mkdir(tmpdir)
        self.assertTrue(os.path.exists(tmpdir))
        os.rmdir(tmpdir)

        # test with relative path
        basedir = at.baseDir("/tmp/")
        tail = "test2_%d" % os.getpid()
        tmpdir = "/tmp/" + tail
        at.mkdir(tail)
        self.assertTrue(os.path.exists(tmpdir))
        os.rmdir(tmpdir)
Ejemplo n.º 24
0
    def test_logginglevel(self):
        """
            CRITICAL    50
            ERROR       40
            WARNING     30
            INFO        20
            DEBUG       10
            NOTSET      0
        """
        at = AT({'alias': 'e'})
        at.setlogginglevel(50)
        level = at.getlogginglevel()

        if (self.verbose):
            print "\nAT Class logging level", level

        self.assertEqual(level, 50)
Ejemplo n.º 25
0
    def test_FM_add_remove(self):
        """ test FM add() and remove() """
        fm = admit.Flow()

        # connection map diagram: a0->a1->a2->a3
        # structure of an element of the triple-nested dictionary of connmap:
        #     src_taskid: {des_taskid: {des_bdpport: (si,sp, di,dp)}}

        self.correct_connmap = {
            0: {
                1: {
                    0: (0, 0, 1, 0)
                }
            },
            1: {
                2: {
                    0: (1, 0, 2, 0)
                }
            },
            2: {
                3: {
                    0: (2, 0, 3, 0)
                }
            }
        }
        tasklist = list()
        for i in range(0, 4):
            a = AT()
            a._baseDir = admit.Project.baseDir
            # Each AT needs an output BDP
            b = File_BDP()
            b.type = "TEST_BDP%d" % i
            a._bdp_out.append(b)
            tasklist.append(a)
            if i == 0:
                taskid = fm.add(tasklist[i])
            else:
                taskid = fm.add(tasklist[i], [(tasklist[i - 1]._taskid, 0)])
        self.assertEqual(fm._connmap, self.correct_connmap)

        # Remove a2 and its downstream from a0->a1->a2->a3
        # The result diagram is a0->a1
        self.correct_connmap = {0: {1: {0: (0, 0, 1, 0)}}}
        fm.remove(2)
        self.assertEqual(fm._connmap, self.correct_connmap)
Ejemplo n.º 26
0
    def test_mkdir(self):
        at = AT({'alias': 's'})
        # test with full path
        tmpdir = "/tmp/test1_%d" % os.getpid()
        at.mkdir(tmpdir)
        t1 = os.path.exists(tmpdir)

        self.assertEqual(t1, True)
        os.rmdir(tmpdir)

        # test with relative path
        basedir = at.baseDir("/tmp/")  # set base dir to /tmp/
        tail = "test2_%d" % os.getpid()
        tmpdir = "/tmp/" + tail
        at.mkdir(tail)
        t1 = os.path.exists(tmpdir)

        self.assertEqual(t1, True)
        os.rmdir(tmpdir)
Ejemplo n.º 27
0
    def test_AT_bdp(self):
        """ test AT bdp methods """
        at = AT({'alias': 'w'})
        self.project.addtask(at)

        # input bdp
        at.set_bdp_in([(BDP, 1, bt.REQUIRED)])
        self.assertEqual(len(at._bdp_in), 1)

        at.clearinput()
        self.assertIsNone(at._bdp_in[0])

        at.addinput(BDP())
        self.assertIsNotNone(at._bdp_in[0])

        # output bdp
        at.set_bdp_out([(BDP, 1)])
        self.assertEqual(len(at._bdp_out), 1)

        # test clearoutput
        at.clearoutput()
        self.assertIsNone(at._bdp_out[0])

        output1 = BDP()
        at.addoutput(output1)
        isIn = output1 in at  # call __contains__
        self.assertTrue(isIn)

        output2 = File_BDP({'file': 'test.file'})
        at[0] = output2  # call __setitem__
        isIn = output2 in at  # call __contains__ again
        self.assertTrue(isIn)

        # test __iter__
        counter = 0
        for b in at._bdp_out:
            counter += 1
        self.assertEqual(counter, 1)

        item1 = at[0]  # call __getitem__ at index = 0
        self.assertIsInstance(item1, admit.File_BDP)
Ejemplo n.º 28
0
    def test_AT_key(self):
        """ test AT setkey(), getkey(), and haskey() """
        at = AT({'alias': 't', 'test_key': 'at_test'})
        key = "test_key"

        # test invalid key
        self.assertFalse(at.haskey("testtesttest"))

        # test haskey()
        # AT should have the key set at init
        self.assertTrue(at.haskey(key))

        # test setkey()
        at.setkey(name=key, value="TEST", isinit=True)

        # test getkey()
        self.assertEqual(at.getkey(key), "TEST")

        # test {key:val} way of setting a key
        at.setkey(name={key: "TEST2"})
        self.assertEqual(at.getkey(key), "TEST2")
Ejemplo n.º 29
0
    def test_projectID(self):
        at = AT({'alias': 'q'})
        self.project.addtask(at)

        # get the taskid before adding project id
        tid = at._taskid
        if (self.verbose):
            print "\nAT Class taskid (before):", at._taskid

        # now set the project id
        pid = 2
        at.setProject(pid)
        pid = at.getProject()
        if (self.verbose):
            print "\nAT Class project", pid

        self.assertEqual(pid, 2)

        # now strip out the project id from _taskid
        taskid = at.id(True)
        if (self.verbose):
            print "\nAT Class taskid (after):", taskid

        self.assertEqual(taskid, tid)
Ejemplo n.º 30
0
    def test_bdp(self):
        at = AT({'alias': 'w'})
        self.project.addtask(at)

        # input bdp
        at.set_bdp_in([(BDP, 1, bt.REQUIRED)])
        bdpin = len(at._bdp_in)
        if (self.verbose):
            print "\nAT Class number of BDP input:", bdpin

        self.assertEqual(bdpin, 1)  ## should have one input bdp

        at.clearinput()
        bdpin = at._bdp_in[0]
        if (self.verbose):
            print "\nAT Class BDP input:", bdpin

        self.assertEqual(bdpin, None)

        at.addinput(BDP())
        bdpin = at._bdp_in[0]

        self.assertFalse(bdpin is None)

        # output bdp
        at.set_bdp_out([(BDP, 1)])  # set_bdp_out
        bdpout = len(at._bdp_out)
        if (self.verbose):
            print "\nAT Class number of BDP output:", bdpout

        self.assertEqual(bdpout, 1)  ## should have one output bdp

        # test clearoutput
        at.clearoutput()
        bdpout = at._bdp_out[0]
        if (self.verbose):
            print "\nAT Class BDP output:", bdpout

        self.assertEqual(bdpout, None)

        output1 = BDP()
        at.addoutput(output1)

        isIn = output1 in at  # call __contains__
        self.assertTrue(isIn)

        #at.set_bdp_out([(File_BDP,2)])
        output2 = File_BDP({'file': 'test.file'})

        at[0] = output2  # call __setitem__

        isIn = output2 in at  # call __contains__ again
        self.assertTrue(isIn)

        # test __iter__
        counter = 0
        for b in at._bdp_out:
            counter += 1
            if (self.verbose):
                print "Output BDP:", b

        self.assertEqual(counter, 1)

        item1 = at[0]  # call __getitem__ at index = 0
        type = isinstance(item1, admit.File_BDP)
        self.assertTrue(type)