Skip to content

Commit

Permalink
Merge pull request #112 from fls-bioinformatics-core/python3-fix-inva…
Browse files Browse the repository at this point in the history
…lid-octal-representations

Fix leading zeroes on octal numbers for Python3 compatibility
  • Loading branch information
pjbriggs committed Sep 6, 2019
2 parents d35979b + 71d57cb commit 5a5e720
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions QC-pipeline/fastq_strand.py
Expand Up @@ -169,14 +169,14 @@ def _make_mock_star(self,path,unmapped_output=False):
python -c "import sys ; from fastq_strand import mockSTAR ; mockSTAR(sys.argv[1:],unmapped_output=%s)" $@
exit $?
""" % (os.path.dirname(__file__),unmapped_output))
os.chmod(path,0775)
os.chmod(path,0o775)
def _make_failing_mock_star(self,path):
# Make a failing mock STAR executable
with io.open(path,'wt') as fp:
fp.write(u"""#!/bin/bash
exit 1
""")
os.chmod(path,0775)
os.chmod(path,0o775)
def test_fastq_strand_one_genome_index_SE(self):
"""
fastq_strand: test with single genome index (SE)
Expand Down
2 changes: 1 addition & 1 deletion bcftbx/JobRunner.py
Expand Up @@ -498,7 +498,7 @@ def run(self,name,working_dir,script,args):
mv {job_dir}/__exit_code.tmp {job_dir}/__exit_code
exit $exit_code
""".format(shell=self.__shell,job_dir=job_dir,cmd=cmd))
os.chmod(job_script,0755)
os.chmod(job_script,0o755)
# Sanitize name for GE by replacing invalid characters
# (colon, asterisk...)
ge_name = self.__ge_name(name)
Expand Down
4 changes: 2 additions & 2 deletions bcftbx/mockGE.py
Expand Up @@ -213,7 +213,7 @@ def _start_job(self,job_id):
exit_code=$?
echo "$exit_code" > %s/__exit_code.%d
""" % (self._shell,queue,command,self._database_dir,job_id))
os.chmod(script_file,0775)
os.chmod(script_file,0o775)
# Run the command
p = subprocess.Popen(script_file,
cwd=working_dir,
Expand Down Expand Up @@ -651,7 +651,7 @@ def _make_mock_GE_exe(path,f,database_dir=None,debug=None,
from bcftbx.mockGE import MockGE
sys.exit(MockGE(%s).%s(sys.argv[1:]))
""" % (','.join(args),f))
os.chmod(path,0775)
os.chmod(path,0o775)

def setup_mock_GE(bindir=None,database_dir=None,debug=None,
qsub_delay=None,qacct_delay=None):
Expand Down
50 changes: 25 additions & 25 deletions bcftbx/test/test_utils.py
Expand Up @@ -178,22 +178,22 @@ def setUp(self):
self.example_dir.add_file("group_unreadable.txt")
self.example_dir.add_file("group_unwritable.txt")
self.example_dir.add_file("program.exe")
os.chmod(self.example_dir.path("spider.txt"),0664)
os.chmod(self.example_dir.path("web"),0775)
os.chmod(self.example_dir.path("unreadable.txt"),0044)
os.chmod(self.example_dir.path("group_unreadable.txt"),0624)
os.chmod(self.example_dir.path("group_unwritable.txt"),0644)
os.chmod(self.example_dir.path("program.exe"),0755)
os.chmod(self.example_dir.path("spider.txt"),0o664)
os.chmod(self.example_dir.path("web"),0o775)
os.chmod(self.example_dir.path("unreadable.txt"),0o044)
os.chmod(self.example_dir.path("group_unreadable.txt"),0o624)
os.chmod(self.example_dir.path("group_unwritable.txt"),0o644)
os.chmod(self.example_dir.path("program.exe"),0o755)
self.example_dir.add_link("program","program.exe")

def tearDown(self):
"""Remove directory with test data
"""
os.chmod(self.example_dir.path("unreadable.txt"),0644)
os.chmod(self.example_dir.path("group_unreadable.txt"),0644)
os.chmod(self.example_dir.path("group_unwritable.txt"),0644)
os.chmod(self.example_dir.path("program.exe"),0644)
os.chmod(self.example_dir.path("unreadable.txt"),0o644)
os.chmod(self.example_dir.path("group_unreadable.txt"),0o644)
os.chmod(self.example_dir.path("group_unwritable.txt"),0o644)
os.chmod(self.example_dir.path("program.exe"),0o644)
self.example_dir.delete_directory()

def test_path(self):
Expand Down Expand Up @@ -378,7 +378,7 @@ def test_chown_user(self):
"""
path = PathInfo(self.example_dir.path("spider.txt"))
# Ensure file can be removed by anyone i.e. write permission for all
os.chmod(self.example_dir.path("spider.txt"),0666)
os.chmod(self.example_dir.path("spider.txt"),0o666)
# Will always fail for non-root user?
current_user = pwd.getpwuid(os.getuid()).pw_name
if current_user != "root":
Expand Down Expand Up @@ -654,9 +654,9 @@ def test_mkdir_chmod(self):
"""
new_dir = os.path.join(self.test_dir,"new_dir")
self.assertFalse(os.path.exists(new_dir))
mkdir(new_dir,mode=0644)
mkdir(new_dir,mode=0o644)
self.assertTrue(os.path.exists(new_dir))
self.assertEqual(stat.S_IMODE(os.lstat(new_dir).st_mode),0644)
self.assertEqual(stat.S_IMODE(os.lstat(new_dir).st_mode),0o644)

def test_mkdir_dir_already_exists(self):
"""mkdir: try to make a subdirectory that already exists
Expand Down Expand Up @@ -706,20 +706,20 @@ def test_chmod_for_file(self):
"""
test_file = os.path.join(self.test_dir,'test.txt')
io.open(test_file,'wt').write(u"Some random text")
chmod(test_file,0644)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0644)
chmod(test_file,0755)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0755)
chmod(test_file,0o644)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0o644)
chmod(test_file,0o755)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0o755)

def test_chmod_for_directory(self):
"""Check chmod works on a directory
"""
test_dir = os.path.join(self.test_dir,'test')
os.mkdir(test_dir)
chmod(test_dir,0755)
self.assertEqual(stat.S_IMODE(os.lstat(test_dir).st_mode),0755)
chmod(test_dir,0777)
self.assertEqual(stat.S_IMODE(os.lstat(test_dir).st_mode),0777)
chmod(test_dir,0o755)
self.assertEqual(stat.S_IMODE(os.lstat(test_dir).st_mode),0o755)
chmod(test_dir,0o777)
self.assertEqual(stat.S_IMODE(os.lstat(test_dir).st_mode),0o777)

def test_chmod_doesnt_follow_link(self):
"""Check chmod doesn't follow symbolic links
Expand All @@ -728,11 +728,11 @@ def test_chmod_doesnt_follow_link(self):
io.open(test_file,'w').write(u"Some random text")
test_link = os.path.join(self.test_dir,'test.lnk')
os.symlink(test_file,test_link)
chmod(test_file,0644)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0644)
chmod(test_link,0755)
chmod(test_file,0o644)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0o644)
chmod(test_link,0o755)
# Target should be unaffected
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0644)
self.assertEqual(stat.S_IMODE(os.lstat(test_file).st_mode),0o644)

class TestTouchFunction(unittest.TestCase):
"""Unit tests for the 'touch' function
Expand Down

0 comments on commit 5a5e720

Please sign in to comment.