Example #1
0
 def test_memory_1(self):
     """ mafComparator should be memory clean for seed testing examples
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_1'))
     parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     for maf1, maf2  in knownValuesSeed:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.join(tmpDir, 'output.xml'),
                 '--samples=10', '--logLevel=critical']
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         for i in xrange(0, 4):
             mtt.recordCommands([cmd], tmpDir)
             mtt.runCommandsS([cmd], tmpDir)
             self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
Example #2
0
 def test_memoryTest_6(self):
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_6'))
     i = -1
     for maf1, maf2, totalTrue, totalFalse in knownValues:
         i += 1
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--samples=1000', '--logLevel=critical',
                 '--numberOfPairs=%s' % knownValuesNumberOfPairs[i],
                 ]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #3
0
 def test_memory_0(self):
     """ mafComparator should be memory clean for bed parsing examples
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_0'))
     for maf1, maf2, bed, totalTrue, totalTrueInInterval in knownValuesBed:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         testBed = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'bed.bed')), 
                                bed, [''])
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--samples=1000', '--logLevel=critical',
                 ]
         if bed != '':
             cmd += ['--bedFiles', os.path.abspath(os.path.join(tmpDir, 'bed.bed'))]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #4
0
 def test_memory_3(self):
     """ mafComparator should be memory clean for known values using --near option
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()        
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_3'))
     for maf1, maf2, near, totalTrue, totalFalse in knownValuesNear:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--near=%d' % near, 
                 '--samples=1000', '--logLevel=critical',
                 ]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #5
0
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     global g_header
     customOpts = mafval.GenericValidationOptions()
     for i in xrange(0, len(g_blocks)):
         tmpDir = os.path.abspath(mtt.makeTempDir('memory1'))
         testMafPath, g_header = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, 'test.maf')),
             g_blocks[i][0], g_headers)
         parent = os.path.dirname(os.path.dirname(
             os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(
             os.path.abspath(os.path.join(parent, 'test', 'mafRowOrderer')))
         cmd += ['--maf', testMafPath, '--order', '%s' % g_order]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'ordered.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(
             mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         self.assertTrue(
             mafval.validateMaf(os.path.join(tmpDir, 'ordered.maf'),
                                customOpts))
         mtt.removeDir(tmpDir)
Example #6
0
 def test_memoryTest_6(self):
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_6'))
     i = -1
     for maf1, maf2, totalTrue, totalFalse in knownValues:
         i += 1
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--samples=1000', '--logLevel=critical',
                 '--numberOfPairs=%s' % knownValuesNumberOfPairs[i],
                 ]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     for i in xrange(0, 10):
         shuffledBlocks = []
         expectedOutput = []
         tmpDir = os.path.abspath(mtt.makeTempDir())
         order = [1] * len(g_duplicateBlocks) + [0] * len(g_nonDuplicateBlocks)
         random.shuffle(order)
         random.shuffle(g_duplicateBlocks)
         random.shuffle(g_nonDuplicateBlocks)
         j, k = 0, 0
         for dupBlock in order:
             if dupBlock:
                 shuffledBlocks.append(g_duplicateBlocks[j][0])
                 expectedOutput.append(g_duplicateBlocks[j][1])
                 j += 1
             else:
                 shuffledBlocks.append(g_nonDuplicateBlocks[k])
                 expectedOutput.append(g_nonDuplicateBlocks[k])
                 k += 1
         testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')),
                                ''.join(shuffledBlocks), g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = [valgrind, '--leak-check=full', '--show-reachable=yes', '--track-origins=yes', '--xml=yes', 
                '--xml-file=' + os.path.join(tmpDir, 'valgrind.xml')]
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafBlockDuplicateFilter')), 
                '--maf', os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf'))]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))]
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeTempDir()
Example #8
0
 def testMemory2(self):
     """ If valgrind is installed on the system, check for memory related errors (2).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     global g_header
     for i in xrange(0, len(g_nonOverlappingBlocks)):
         tmpDir = os.path.abspath(mtt.makeTempDir('memory2'))
         testMafPath, g_header = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, 'test.maf')),
             ''.join(g_nonOverlappingBlocks[i][0]), g_headers)
         parent = os.path.dirname(os.path.dirname(
             os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(
             os.path.abspath(
                 os.path.join(parent, 'test', 'mafPositionFinder')))
         cmd += [
             '--maf', testMafPath, '--seq', g_targetSeq, '--pos',
             '%d' % g_nonOverlappingBlocks[i][1]
         ]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'found.txt'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(
             mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
Example #9
0
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir('memeory1'))
     customOpts = mafval.GenericValidationOptions()
     for a, expected, strand in g_blocks:
         testMaf = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, 'test.maf')), ''.join(a),
             g_headers)
         parent = os.path.dirname(os.path.dirname(
             os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [
             os.path.abspath(os.path.join(parent, 'test',
                                          'mafStrander')), '--maf',
             os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seq',
             'target', '--strand', strand
         ]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'coerced.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(
             mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         self.assertTrue(
             mafval.validateMaf(os.path.join(tmpDir, 'coerced.maf'),
                                customOpts))
     mtt.removeDir(tmpDir)
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     for i in xrange(0, 10):
         shuffledBlocks = []
         tmpDir = os.path.abspath(mtt.makeTempDir())
         order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks)
         random.shuffle(order)
         random.shuffle(g_overlappingBlocks)
         random.shuffle(g_nonOverlappingBlocks)
         j, k = 0, 0
         for isOverlapping in order:
             if isOverlapping:
                 shuffledBlocks.append(g_overlappingBlocks[j])
                 j += 1
             else:
                 shuffledBlocks.append(g_nonOverlappingBlocks[k])
                 k += 1
         testMaf = mtt.testFile(os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')),
                                ''.join(shuffledBlocks), g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = [valgrind, '--leak-check=full', '--show-reachable=yes', '--track-origins=yes', '--xml=yes', 
                '--xml-file=' + os.path.join(tmpDir, 'valgrind.xml')]
         cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafBlockExtractor')))
         cmd += ['--maf', os.path.abspath(os.path.join(os.curdir, 'tempTestDir', 'test.maf')),
                 '--seq', g_targetSeq, '--start', '%d' % g_targetRange[0], 
                 '--stop', '%d' % g_targetRange[1]]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))]
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeTempDir()
Example #11
0
 def testMemory0(self):
     """ If valgrind is installed on the system, check for memory related errors (0).
 """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_0'))
     parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     customOpts = mafval.GenericValidationOptions()
     for target, mafSeq, solutionDict in g_knownGood:
         testMaf = mtt.testFile(
             os.path.join(os.path.abspath(tmpDir), 'test.maf'), mafSeq,
             g_headers)
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(
             os.path.abspath(os.path.join(parent, 'test', 'mafCoverage')))
         cmd += [
             '--maf',
             os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--species',
             target
         ]
         outpipes = [os.path.join('/dev', 'null')]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(
             mafval.validateMaf(os.path.join(tmpDir, 'test.maf'),
                                customOpts))
         self.assertTrue(
             mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
Example #12
0
 def dtestMemory2(self):
     """ If valgrind is installed on the system, check for memory related errors (2).
     """
     valgrind = mtt.which("valgrind")
     if valgrind is None:
         return
     global g_header
     for i in xrange(0, len(g_nonOverlappingBlocks)):
         tmpDir = os.path.abspath(mtt.makeTempDir())
         testMafPath, g_header = mtt.testFile(
             os.path.abspath(os.path.join(os.curdir, "tempTestDir", "test.maf")),
             "".join(g_nonOverlappingBlocks[i][0]),
             g_headers,
         )
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = [
             valgrind,
             "--leak-check=full",
             "show-reachable=yes",
             "--track-origins=yes",
             "--xml=yes",
             "--xml-file=" + os.path.join(tmpDir, "valgrind.xml"),
         ]
         cmd.append(os.path.abspath(os.path.join(parent, "test", "mafBlockFinder")))
         cmd += ["--maf", testMafPath, "--seq", g_targetSeq, "--pos", "%d" % g_nonOverlappingBlocks[i][1]]
         outpipes = [os.path.abspath(os.path.join(tmpDir, "found.txt"))]
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, "valgrind.xml")))
         mtt.removeTempDir()
Example #13
0
 def testMemory2(self):
     """ If valgrind is installed on the system, check for memory related errors (2).
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     i = -1
     for inblocks, seq, start, stop, outblocks in self.testSet:
         i += 1
         tmpDir = os.path.abspath(mtt.makeTempDir('memory_2'))
         random.shuffle(g_nonOverlappingBlocks)
         testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                                ''.join(map(str, inblocks)), g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafExtractor')))
         cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                 '--seq', seq, '--start', '%d' % start, 
                 '--stop', '%d' % stop,
                 ]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
Example #14
0
 def testHardExtraction_0(self):
     """ mafExtractor should output trimmed blocks by default.
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     customOpts = mafval.GenericValidationOptions()
     i = -1
     for inblocks, seq, start, stop, outblocks in self.testSet:
         i += 1
         tmpDir = os.path.abspath(mtt.makeTempDir('hardextraction_0'))
         testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                                ''.join(map(str, inblocks)), g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = [os.path.abspath(os.path.join(parent, 'test', 'mafExtractor'))]
         cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                 '--seq', seq, '--start', '%d' % start, 
                 '--stop', '%d' % stop,
                 ]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mafIsHardExtracted('hardextraction_0_%d' % i, outblocks, 
                                            os.path.join(tmpDir, 'extracted.maf')))
         self.assertTrue(mafval.validateMaf(os.path.join(tmpDir, 'extracted.maf'), customOpts))
         mtt.removeDir(tmpDir)
 def testMemory_3(self):
     """ mafTransitiveClosure should be memory clean.
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_3'))
     for inMaf, outList in self.knownResults:
         testMaf = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, 'test.maf')), inMaf,
             g_headers)
         parent = os.path.dirname(os.path.dirname(
             os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [
             os.path.abspath(
                 os.path.join(parent, 'test', 'mafTransitiveClosure')),
             '--maf',
             os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--sort'
         ]
         outpipes = [
             os.path.abspath(os.path.join(tmpDir, 'transitiveClosure.maf'))
         ]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
 def _testMemory1(self):
   """ If valgrind is installed on the system, check for memory related errors (0).
   """
   valgrind = mtt.which('valgrind')
   if valgrind is None:
     return
   mtt.makeTempDirParent()
   for i in xrange(0, 10):
     shuffledBlocks = []
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_1'))
     order = [1] * len(g_overlappingBlocks) + [0] * len(g_nonOverlappingBlocks)
     random.shuffle(order)
     random.shuffle(g_overlappingBlocks)
     random.shuffle(g_nonOverlappingBlocks)
     j, k = 0, 0
     for isOverlapping in order:
       if isOverlapping:
         shuffledBlocks.append(g_overlappingBlocks[j][0])
         j += 1
       else:
         shuffledBlocks.append(g_nonOverlappingBlocks[k][0])
         k += 1
     testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                            ''.join(shuffledBlocks), g_headers)
     parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     cmd = mtt.genericValgrind(tmpDir)
     cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafPairCoverage')))
     cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
             '--seq1', 'target.*', '--seq2', g_targetSeq2,
             ]
     outpipes = [os.path.join('/dev', 'null')]
     mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
     mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
     self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
Example #17
0
 def test_memoryTest_4(self):
     """ --wigglePairs options should be memory clean
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_4'))
     for maf1, maf2, ref, partner, binlen, valuesDictList in knownValuesWiggles:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--samples=1000', '--logLevel=critical',
                 '--wigglePairs=%s:%s' % (ref, partner),
                 '--wiggleBinLength=%d' % binlen,
                 ]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #18
0
 def test_memory_1(self):
     """ mafComparator should be memory clean for seed testing examples
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_1'))
     parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     for maf1, maf2  in knownValuesSeed:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.join(tmpDir, 'output.xml'),
                 '--samples=10', '--logLevel=critical']
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         for i in xrange(0, 4):
             mtt.recordCommands([cmd], tmpDir)
             mtt.runCommandsS([cmd], tmpDir)
             self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
Example #19
0
 def test_memory_0(self):
     """ mafComparator should be memory clean for bed parsing examples
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_0'))
     for maf1, maf2, bed, totalTrue, totalTrueInInterval in knownValuesBed:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         testBed = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'bed.bed')), 
                                bed, [''])
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--samples=1000', '--logLevel=critical',
                 ]
         if bed != '':
             cmd += ['--bedFiles', os.path.abspath(os.path.join(tmpDir, 'bed.bed'))]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #20
0
 def test_memoryTest_4(self):
     """ --wigglePairs options should be memory clean
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_4'))
     for maf1, maf2, ref, partner, binlen, valuesDictList in knownValuesWiggles:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--samples=1000', '--logLevel=critical',
                 '--wigglePairs=%s:%s' % (ref, partner),
                 '--wiggleBinLength=%d' % binlen,
                 ]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #21
0
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which("valgrind")
     if valgrind is None:
         return
     shuffledTargets = list(g_targetBlocks)
     for i in xrange(0, 20):
         tmpDir = os.path.abspath(mtt.makeTempDir("memory1"))
         random.shuffle(g_nonTargetBlocks)
         random.shuffle(shuffledTargets)
         shuffledBlocks = list(shuffledTargets)
         lower = 0
         for j in xrange(0, len(g_nonTargetBlocks)):
             # randomly insert the non target blocks, but keep a record
             # of their relative order.
             index = random.randint(lower, len(shuffledBlocks))
             shuffledBlocks.insert(index, g_nonTargetBlocks[j])
             lower = index + 1
         testMaf = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, "test.maf")), "".join(shuffledBlocks), g_headers
         )
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(os.path.abspath(os.path.join(parent, "test", "mafSorter")))
         cmd += ["--maf", os.path.abspath(os.path.join(tmpDir, "test.maf")), "--seq", "hg18.chr7"]
         outpipes = [os.path.abspath(os.path.join(tmpDir, "sorted.maf"))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, "valgrind.xml")))
         mtt.removeDir(tmpDir)
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir('memory1'))
     customOpts = mafval.GenericValidationOptions()
     for reference, inMaf, inFaList, outFa, outMaf  in g_knownData:
         testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')),
                                ''.join(inMaf), g_headers)
         testFaNames = testFasta(os.path.abspath(tmpDir), inFaList)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafToFastaStitcher')), 
                 '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf')),
                 '--seqs', testFaNames,
                 '--breakpointPenalty', '6', '--interstitialSequence', '20',
                 '--outMfa', os.path.abspath(os.path.join(tmpDir, 'out.fa')),
                 '--outMaf', os.path.abspath(os.path.join(tmpDir, 'out.maf')),]
         if reference is not None:
             cmd += ['--reference', reference]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
Example #23
0
 def test_memory_3(self):
     """ mafComparator should be memory clean for known values using --near option
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()        
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_3'))
     for maf1, maf2, near, totalTrue, totalFalse in knownValuesNear:
         testMaf1 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf1.maf')), 
                                 maf1, g_headers)
         testMaf2 = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'maf2.maf')), 
                                 maf2, g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafComparator')),
                 '--maf1', os.path.abspath(os.path.join(tmpDir, 'maf1.maf')),
                 '--maf2', os.path.abspath(os.path.join(tmpDir, 'maf2.maf')),
                 '--out', os.path.abspath(os.path.join(tmpDir, 'output.xml')),
                 '--near=%d' % near, 
                 '--samples=1000', '--logLevel=critical',
                 ]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
         self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #24
0
 def testMemory(self):
     """ sharedMaf.h should be memory clean.
 """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir('allTests'))
     cmd = mtt.genericValgrind(tmpDir)
     cmd.append(os.path.abspath(os.path.join(os.curdir, 'allTests')))
     mtt.runCommandsS([cmd], tmpDir)
     self.assertTrue(
         mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
 def test_CuTestMemory(self):
   """ If valgrind is installed on the system, check for memory related errors in CuTests.
   """
   mtt.makeTempDirParent()
   valgrind = mtt.which('valgrind')
   if valgrind is None:
     return
   tmpDir = os.path.abspath(mtt.makeTempDir('memory_CuTest'))
   parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
   cmd = mtt.genericValgrind(tmpDir)
   cmd.append(os.path.abspath(os.path.join(parent, 'test', 'allTests')))
   outpipes = [os.path.join('/dev', 'null')]
   mtt.recordCommands([cmd], tmpDir)
   mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
   self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
   mtt.removeDir(tmpDir)
 def testMemory_2(self):
     """ the CuTest tests should be memory clean.
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir('memory_2'))
     parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     cmd = mtt.genericValgrind(tmpDir)
     cmd += [
         os.path.abspath(
             os.path.join(parent, 'test', 'mafTransitiveClosure')), '--test'
     ]
     outpipes = [
         os.path.abspath(os.path.join(tmpDir, 'transitiveClosure.maf'))
     ]
     mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
     mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
     passed = mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml'))
     self.assertTrue(passed)
     mtt.removeDir(tmpDir)
Example #27
0
 def testMemory2(self):
     """ If valgrind is installed on the system, check for memory related errors (2).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     global g_header
     for i in xrange(0, len(g_knownExcludes)):
         tmpDir = os.path.abspath(mtt.makeTempDir('memory2'))
         testMafPath, g_header = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')),
                                              g_knownExcludes[i][0], g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafFilter')))
         cmd += ['--maf', testMafPath, '--excludeSeq', '%s' % g_sequenceList]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     tmpDir = os.path.abspath(mtt.makeTempDir('memory1'))
     customOpts = mafval.GenericValidationOptions()
     for reference, inMaf, inFaList, outFa, outMaf in g_knownData:
         testMaf = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, 'test.maf')),
             ''.join(inMaf), g_headers)
         testFaNames = testFasta(os.path.abspath(tmpDir), inFaList)
         parent = os.path.dirname(os.path.dirname(
             os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [
             os.path.abspath(
                 os.path.join(parent, 'test', 'mafToFastaStitcher')),
             '--maf',
             os.path.abspath(os.path.join(tmpDir, 'test.maf')),
             '--seqs',
             testFaNames,
             '--breakpointPenalty',
             '6',
             '--interstitialSequence',
             '20',
             '--outMfa',
             os.path.abspath(os.path.join(tmpDir, 'out.fa')),
             '--outMaf',
             os.path.abspath(os.path.join(tmpDir, 'out.maf')),
         ]
         if reference is not None:
             cmd += ['--reference', reference]
         mtt.recordCommands([cmd], tmpDir)
         mtt.runCommandsS([cmd], tmpDir)
         self.assertTrue(
             mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
     mtt.removeDir(tmpDir)
Example #29
0
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     shuffledTargets = list(g_targetBlocks)
     for i in xrange(0, 20):
         tmpDir = os.path.abspath(mtt.makeTempDir('memory1'))
         random.shuffle(g_nonTargetBlocks)
         random.shuffle(shuffledTargets)
         shuffledBlocks = list(shuffledTargets)
         lower = 0
         for j in xrange(0, len(g_nonTargetBlocks)):
             # randomly insert the non target blocks, but keep a record
             # of their relative order.
             index = random.randint(lower, len(shuffledBlocks))
             shuffledBlocks.insert(index, g_nonTargetBlocks[j])
             lower = index + 1
         testMaf = mtt.testFile(
             os.path.abspath(os.path.join(tmpDir, 'test.maf')),
             ''.join(shuffledBlocks), g_headers)
         parent = os.path.dirname(os.path.dirname(
             os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(
             os.path.abspath(os.path.join(parent, 'test', 'mafSorter')))
         cmd += [
             '--maf',
             os.path.abspath(os.path.join(tmpDir, 'test.maf')), '--seq',
             'hg18.chr7'
         ]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'sorted.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(
             mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
 def testMemory2(self):
     """ If valgrind is installed on the system, check for memory related errors (2).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     for i in xrange(0, 10):
         tmpDir = os.path.abspath(mtt.makeTempDir('memory2'))
         random.shuffle(g_nonDuplicateBlocks)
         testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')),
                                ''.join(g_nonDuplicateBlocks), g_headers)
         expectedOutput = g_nonDuplicateBlocks
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafDuplicateFilter')), 
                '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf'))]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
Example #31
0
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     mtt.makeTempDirParent()
     for i in xrange(0, 10):
         tmpDir = os.path.abspath(mtt.makeTempDir('memory_1'))
         random.shuffle(g_nonOverlappingBlocks)
         testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                                ''.join(g_nonOverlappingBlocks), g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd.append(os.path.abspath(os.path.join(parent, 'test', 'mafExtractor')))
         cmd += ['--maf', os.path.abspath(os.path.join(tmpDir, 'test_%d.maf' % i)),
                 '--seq', g_targetSeq, '--start', '%d' % g_targetRange[0], 
                 '--stop', '%d' % g_targetRange[1],
                 '--soft']
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'extracted.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
 def testMemory1(self):
     """ If valgrind is installed on the system, check for memory related errors (1).
     """
     mtt.makeTempDirParent()
     valgrind = mtt.which('valgrind')
     if valgrind is None:
         return
     for i in xrange(0, 10):
         shuffledBlocks = []
         expectedOutput = []
         tmpDir = os.path.abspath(mtt.makeTempDir('memory1'))
         order = [1] * len(g_duplicateBlocks) + [0] * len(g_nonDuplicateBlocks)
         random.shuffle(order)
         random.shuffle(g_duplicateBlocks)
         random.shuffle(g_nonDuplicateBlocks)
         j, k = 0, 0
         for dupBlock in order:
             if dupBlock:
                 shuffledBlocks.append(g_duplicateBlocks[j][0])
                 expectedOutput.append(g_duplicateBlocks[j][1])
                 j += 1
             else:
                 shuffledBlocks.append(g_nonDuplicateBlocks[k])
                 expectedOutput.append(g_nonDuplicateBlocks[k])
                 k += 1
         testMaf = mtt.testFile(os.path.abspath(os.path.join(tmpDir, 'test.maf')),
                                ''.join(shuffledBlocks), g_headers)
         parent = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
         cmd = mtt.genericValgrind(tmpDir)
         cmd += [os.path.abspath(os.path.join(parent, 'test', 'mafDuplicateFilter')), 
                '--maf', os.path.abspath(os.path.join(tmpDir, 'test.maf'))]
         outpipes = [os.path.abspath(os.path.join(tmpDir, 'filtered.maf'))]
         mtt.recordCommands([cmd], tmpDir, outPipes=outpipes)
         mtt.runCommandsS([cmd], tmpDir, outPipes=outpipes)
         self.assertTrue(mtt.noMemoryErrors(os.path.join(tmpDir, 'valgrind.xml')))
         mtt.removeDir(tmpDir)
Example #33
0
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
'''
GIT = mtt.which('git')


def runCommand(cmd):
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
    pout, perr = p.communicate()
    mtt.handleReturnCode(p.returncode, cmd)
    return pout


def getBranch():
    branchList = runCommand([GIT, 'branch']).split('\n')
    for b in branchList:
        if b.startswith('* '):
            return b[2:]