def test_find_exe_full_path(self):
     """
     find_exe: locates executable file given full path
     """
     full_path = os.path.join(self.test_dir,"test.exe")
     with open(full_path,'wt') as fp:
         fp.write("#!/usr/bin/bash\necho Test")
     os.chmod(full_path,0o755)
     self.assertEqual(find_exe(full_path),full_path)
 def test_find_exe_on_path(self):
     """
     find_exe: locates executable file on PATH
     """
     full_path = os.path.join(self.test_dir,"test.exe")
     with open(full_path,'wt') as fp:
         fp.write("#!/usr/bin/bash\necho Test")
     os.chmod(full_path,0o755)
     os.environ['PATH'] = "%s%s%s" % (os.environ['PATH'],
                                      os.pathsep,
                                      self.test_dir)
     self.assertEqual(find_exe(os.path.basename(full_path)),
                      full_path)
def ensure_bedtools():
    # Globals
    global BEDTOOLS_INSTALL_DIR
    global PATH_NO_BEDTOOLS
    global DESTROY_AT_EXIT
    # Check if bedtools is already available
    if find_exe("bedtools"):
        return
    # Install bedtools in temp directory
    if BEDTOOLS_INSTALL_DIR is None:
        bedtools_install_dir = tempfile.mkdtemp()
        fetch_bedtools(install_dir=bedtools_install_dir,
                       create_install_dir=False)
        BEDTOOLS_INSTALL_DIR = bedtools_install_dir
        print("Installed bedtools in %s" % BEDTOOLS_INSTALL_DIR)
    # Append bedtools to the PATH
    if PATH_NO_BEDTOOLS is None:
        PATH_NO_BEDTOOLS = os.environ['PATH']
        os.environ['PATH'] = "%s%s%s" % (os.environ['PATH'], os.pathsep,
                                         BEDTOOLS_INSTALL_DIR)
    # Remove temporary bedtools install on exit
    if not DESTROY_AT_EXIT:
        atexit.register(remove_bedtools)
        DESTROY_AT_EXIT = True
 def setUp(self):
     ensure_bedtools()
     if not find_exe("bedtools"):
         self.skipTest("bedtools not found")
     self.test_dir = tempfile.mkdtemp()
 def test_find_exe_for_missing_file(self):
     """
     find_exe: returns None if file not found
     """
     self.assertEqual(find_exe("doesntexist"),None)
     self.assertEqual(find_exe("/no/where/doesntexist"),None)