Example #1
0
 def testTempFileTree(self):
     for test in xrange(100): #self.testNo):
         levels = random.choice(xrange(1, 4))
         fileNo = random.choice(xrange(1, 6))
         maxTempFiles = int(math.pow(fileNo, levels))
         
         print "Got %s levels, %s fileNo and %s maxTempFiles" % (levels, fileNo, maxTempFiles)
         
         tempFileTreeRootDir = os.path.join(self.tempDir, getRandomAlphaNumericString())
         tempFileTree = TempFileTree(tempFileTreeRootDir, fileNo, levels)
         
         tempFiles = []
         tempDirs = []
         #Check we can mac number of temp files.
         for i in xrange(maxTempFiles):
             if random.random() > 0.5:
                 tempFile = tempFileTree.getTempFile()
                 assert os.path.isfile(tempFile)
                 tempFiles.append(tempFile)
             else:
                 tempFile = tempFileTree.getTempDirectory()
                 assert os.path.isdir(tempFile)
                 tempDirs.append(tempFile)
         
         #Check assertion is created
         try:
             tempFileTree.getTempFile()
             assert False
         except RuntimeError:
             logger.debug("Got expected error message")
     
         #Now remove a few temp files
         while random.random() > 0.1 and len(tempFiles) > 0:
             tempFile = tempFiles.pop()
             assert os.path.isfile(tempFile)
             tempFileTree.destroyTempFile(tempFile)
             assert not os.path.isfile(tempFile)  
         
         #Now remove a few temp dirs
         while random.random() > 0.1 and len(tempDirs) > 0:
             tempDir = tempDirs.pop()
             assert os.path.isdir(tempDir)
             tempFileTree.destroyTempDir(tempDir)
             assert not os.path.isdir(tempDir)
         
         #Check temp files is okay
         set(tempFileTree.listFiles()) == set(tempFiles + tempDirs)
                 
         #Either remove all the temp files or just destroy the whole thing
         if random.random() > 0.5:
             #Remove all temp files and check thing is empty.
             for tempFile in tempFiles:
                 tempFileTree.destroyTempFile(tempFile)
             for tempDir in tempDirs:
                 tempFileTree.destroyTempDir(tempDir)
             os.remove(os.path.join(tempFileTreeRootDir, "lock"))
             os.rmdir(tempFileTreeRootDir)
         else:
             tempFileTree.destroyTempFiles()
             assert not os.path.isdir(tempFileTreeRootDir)
Example #2
0
 def testNewickTreeParser_UnaryNodes(self):
     #tests with unary nodes 
     for test in xrange(0, self.testNo):
         tree = getRandomTreeString()
         logger.debug("tree to try\t", tree)
         tree2 = newickTreeParser(tree, reportUnaryNodes=True)
         tree3 = printBinaryTree(tree2, True) 
         logger.debug("tree found\t", tree3)
         assert tree == tree3