Skip to content

Commit

Permalink
Fixed extraneous "is True" and "is False" conditionals.
Browse files Browse the repository at this point in the history
Removed redundant references using list(keys())
  • Loading branch information
srp3rd committed Sep 19, 2016
1 parent ae0ca21 commit c7bc58c
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 51 deletions.
2 changes: 1 addition & 1 deletion bin.src/dagIdInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
dagNode = sys.argv[1]
filename = sys.argv[2]

if os.path.exists(filename) is False:
if not os.path.exists(filename):
print("file %s not found" % filename)
sys.exit(errno.ENOENT)

Expand Down
2 changes: 1 addition & 1 deletion bin.src/runOrca.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def main():
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
if creator.isVerbose is False:
if not creator.isVerbose:
os.close(0)
os.close(1)
os.close(2)
Expand Down
7 changes: 2 additions & 5 deletions etc/scripts/generateDag.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@

import sys

try:
from shlex import split as cmd_split
except ImportError:
from pipes import split as cmd_split
from shlex import split as cmd_split


def _line_to_args(self, line):
Expand Down Expand Up @@ -154,7 +151,7 @@ def writeDagFile(pipeline, templateFile, infile, workerdir, prescriptFile, runid
# extended input like : visit=887136081 raft=2,2 sensor=0,1
# If there is no space, the dataid is something simple like a skytile id
newData = myData
visit = str(int(count / 100))
visit = str(count // 100)

myDataList.append(myData)
newDataList.append(newData)
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/ctrl/execute/allocationConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class AllocatedPlatformConfig(pexConfig.Config):
dtype=str, default=None)
totalCoresPerNode = pexConfig.Field(doc="the TOTAL number of cores on each node",
dtype=int, default=1)
glideinShutdown = pexConfig.Field(
doc="the number of seconds of inactivity before the glideins are cancelled", dtype=int, default=3600)
glideinShutdown = pexConfig.Field(doc="number of seconds of inactivity before glideins are cancelled",
dtype=int, default=3600)


class AllocationConfig(pexConfig.Config):
Expand Down
8 changes: 4 additions & 4 deletions python/lsst/ctrl/execute/allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, platform, opts, configFileName):
# command and the value of $HOME, respectively.
user_name = None
user_home = None
for name in list(condorInfoConfig.platform.keys()):
for name in condorInfoConfig.platform:
if name == self.platform:
user_name = condorInfoConfig.platform[name].user.name
user_home = condorInfoConfig.platform[name].user.home
Expand Down Expand Up @@ -193,8 +193,8 @@ def loadPbs(self, name):
# This is the TOTAL number of cores in the job, not just the total
# of the cores you intend to use. In other words, the total available
# on a machine, times the number of machines.
self.commandLineDefaults["TOTAL_CORE_COUNT"] = int(
self.opts.nodeCount) * configuration.platform.totalCoresPerNode
totalCoresPerNode = configuration.platform.totalCoresPerNode
self.commandLineDefaults["TOTAL_CORE_COUNT"] = self.opts.nodeCount * totalCoresPerNode

uniqueIdentifier = self.createUniqueIdentifier()

Expand Down Expand Up @@ -321,7 +321,7 @@ def getWallClock(self):

def getParameter(self, value):
"""Accessor for generic value
@return None if value is not set. Otherwise, use the command line ",
@return None if value is not set. Otherwise, use the command line
override (if set), or the default Config value
"""
if value in self.commandLineDefaults:
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ctrl/execute/allocatorParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def parseArgs(self, basename):
Parameters
----------
argv: `list`
argv: `list`
list of strings containing the command line arguments
Returns
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ctrl/execute/condorInfoConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ class CondorInfoConfig(pexConfig.Config):
filename = envString.resolve(filename)
config.load(filename)

for i in list(config.platform.keys()):
for i in config.platform:
print(i)
8 changes: 4 additions & 4 deletions python/lsst/ctrl/execute/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def getSetupPackages(self):
if self.platform == "lsst":
a = a + "setup -j %s %s\\n\\\n" % (name, version)
else:
if version.startswith("LOCAL:") is False:
if not version.startswith("LOCAL:"):
a = a + "setup -j %s %s\\n\\\n" % (name, version)
return a

Expand Down Expand Up @@ -222,7 +222,7 @@ def createConfiguration(self, input):
@return the newly created Orca configuration file
"""
resolvedInputName = envString.resolve(input)
if self.opts.verbose is True:
if self.opts.verbose:
print("creating configuration using ", resolvedInputName)
template = TemplateWriter()
substitutes = self.defaults.copy()
Expand All @@ -234,10 +234,10 @@ def createConfiguration(self, input):
substitutes["CTRL_EXECUTE_SETUP_PACKAGES"] = self.getSetupPackages()

configDir = os.path.join(substitutes["LOCAL_SCRATCH"], "configs")
if os.path.exists(configDir) is False:
if not os.path.exists(configDir):
os.mkdir(configDir)
self.outputFileName = os.path.join(configDir, "%s.config" % (self.runid))
if self.opts.verbose is True:
if self.opts.verbose:
print("writing new configuration to ", self.outputFileName)
template.rewrite(resolvedInputName, self.outputFileName, substitutes)
return self.outputFileName
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/ctrl/execute/seqFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def nextSeq(self):
@return a sequence number
"""
seq = 0
if os.path.exists(self.fileName) is False:
if not os.path.exists(self.fileName):
self.writeSeq(seq)
else:
seq = self.readSeq()
Expand Down
14 changes: 5 additions & 9 deletions tests/testDagIdInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import os
import sys
import unittest
from builtins import bytes
from subprocess import Popen, PIPE
import lsst.utils.tests

Expand All @@ -38,6 +37,7 @@ class TestDagIdInfo(lsst.utils.tests.TestCase):
def executeCommand(self, cmd):
p = Popen(cmd.split(), stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
stdout = stdout.decode()
return stdout

def test1(self):
Expand All @@ -46,21 +46,17 @@ def test1(self):
filename = os.path.join("tests", "testfiles", "test.diamond.dag")

stdout = self.executeCommand("%s %s A1 %s" % (exe, execPath, filename))
stdout = bytes(stdout)
self.assertEqual(stdout, b'run=1033 filter=r camcol=2 field=229\n')
self.assertEqual(stdout, 'run=1033 filter=r camcol=2 field=229\n')

stdout = self.executeCommand("%s %s A3 %s" % (exe, execPath, filename))
stdout = bytes(stdout)
self.assertEqual(stdout, b'run=1033 filter=i camcol=2 field=47\n')
self.assertEqual(stdout, 'run=1033 filter=i camcol=2 field=47\n')

stdout = self.executeCommand("%s %s A17 %s" % (exe, execPath, filename))
stdout = bytes(stdout)
val = b'run=1033 filter=r camcol=2 field=229 run=1033 filter=i camcol=2 field=47\n'
val = 'run=1033 filter=r camcol=2 field=229 run=1033 filter=i camcol=2 field=47\n'
self.assertEqual(stdout, val)

stdout = self.executeCommand("%s %s B1 %s" % (exe, execPath, filename))
stdout = bytes(stdout)
self.assertEqual(stdout, b'')
self.assertEqual(stdout, '')


class TestDagInfoMemoryTest(lsst.utils.tests.MemoryTestCase):
Expand Down
20 changes: 6 additions & 14 deletions tests/testSeqFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from builtins import str
import unittest
import os
import os.path
import pwd
from lsst.ctrl.execute.seqFile import SeqFile
import lsst.utils.tests

Expand All @@ -37,16 +33,12 @@ def setup_module(module):
class TestSeqFile(lsst.utils.tests.TestCase):

def test1(self):
username = pwd.getpwuid(os.geteuid()).pw_name
filename = os.path.join("/tmp", username+"_"+str(os.getpid())+".seq")
if os.path.exists(filename) is True:
os.remove(filename)
sf = SeqFile(filename)
a = sf.nextSeq()
self.assertTrue(a == 0)
a = sf.nextSeq()
self.assertTrue(a == 1)
os.remove(filename)
with lsst.utils.tests.getTempFilePath(".seq") as filename:
sf = SeqFile(filename)
a = sf.nextSeq()
self.assertTrue(a == 0)
a = sf.nextSeq()
self.assertTrue(a == 1)


class TestSeqFileMemoryTest(lsst.utils.tests.MemoryTestCase):
Expand Down
12 changes: 4 additions & 8 deletions tests/testTemplateWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
# see <http://www.lsstcorp.org/LegalNotices/>.
#

from builtins import str
import unittest
import os
import os.path
import filecmp
import pwd
from lsst.ctrl.execute.templateWriter import TemplateWriter
import lsst.utils.tests

Expand All @@ -43,12 +41,10 @@ def test1(self):
pairs["TEST2"] = "Goodbye"
infile = os.path.join("tests", "testfiles", "templateWriter.template")
compare = os.path.join("tests", "testfiles", "templateWriter.txt")
username = pwd.getpwuid(os.geteuid()).pw_name
outfile = os.path.join("/tmp", username+"_"+str(os.getpid())+"_template.txt")
temp = TemplateWriter()
temp.rewrite(infile, outfile, pairs)
self.assertTrue(filecmp.cmp(compare, outfile))
os.remove(outfile)
with lsst.utils.tests.getTempFilePath("_template.txt") as outfile:
temp = TemplateWriter()
temp.rewrite(infile, outfile, pairs)
self.assertTrue(filecmp.cmp(compare, outfile))


class TestTemplateWriterTestCase(lsst.utils.tests.MemoryTestCase):
Expand Down

0 comments on commit c7bc58c

Please sign in to comment.