"""
res = []
for p_name_info in products_infos:
- res.append(self.check_product(p_name_info)
+ res.append(self.check_product(p_name_info))
return res
def check_product(self, p_name_info):
# ask for missing parameters
msg = UTS.label(_("Make substitution in files"))
- msg += "\n" + _("Delimiter") + " = '%s'" % tsettings.delimiter_char)
+ msg += "\n" + _("Delimiter") + " = '%s'" % tsettings.delimiter_char
msg += "\n" + _("Ignore Filters") + "= %s" % ', '.join(tsettings.ignore_filters)
logger.debug(msg)
dico = tsettings.get_parameters(conf_values)
import src.debug as DBG
if self.findLink(idName) is not None:
msg = "appendLink: idname '%s' existing yet" % idName
- DBG.write(msg, self, True)
+ DBG.write(msg, self)
raise Exception(msg)
app = LinkXml(idName)
self._linksXml.append(app)
def setAttribLinkForCommand(cmd, nameAttrib, value):
"""init an attribute value in link of a command in singleton tree"""
+ DBG.write("setAttribLinkForCommand", (cmd.name, nameAttrib, value))
k0 = getLinksXml() # get singleton
kCmd = k0.findLink(cmd.getId())
- kCmd.setAuthAttr(nameAttrib, value)
- # DBG.write("setAttribLinkForCommand", (nameAttrib, value), True)
+ if kCmd is not None:
+ kCmd.setAuthAttr(nameAttrib, value)
+ else: # SatUnittestLogger implies no xml
+ msg = "no links for log command only if logger 'SatUnittestLogger' "
+ DBG.write("warning", msg)
+
def getLinksForXml(idCommand):
"""return list of links of one command from its id"""
from logging.handlers import BufferingHandler
import pprint as PP
+import src.debug as DBG # Easy print stderr (for DEBUG only)
_verbose = False
_name = "loggingSat"
add file handler to logger to set log files
for a salometools command.
when command is known from pyconf/config instance
+ functionality only for
| Example:
| log files names for command prepare
| ~/LOGS/OUT/micro_20180510_140607_clean_lenovo.txt
| etc.
"""
+ if self.name == "SatUnittestLogger":
+ DBG.write("warning", "setFileHandlerForCommand not valid for SatUnittestLogger")
+ return self.idCommandHandlers
+
import src.utilsSat as UTS # needs sys.path.insert(0, satdir)
logger = self
log_dir_jobs = os.path.join(log_dir, "JOBS") # files txt
UTS.ensure_path_exists(log_dir)
UTS.ensure_path_exists(log_dir_out)
- if self.idCommandHandlers == 0:
- datehour = config.VARS.datehour
- self.dateHour = datehour # save dateHour for micro commands
- else:
- datehour = self.dateHour # micro commands have same datehour for naming files
-
- cmd = config.VARS.command
- fullNameCmd = cmdInstance.getFullNameStr()
- hostname = config.VARS.hostname
- nameFileXml = "%s_%03i_%s_%s.xml" % (datehour, self.idCommandHandlers, cmd, hostname)
- nameFileTxt = "%s_%03i_%s_%s.txt" % (datehour, self.idCommandHandlers, cmd, hostname)
- fileXml = os.path.join(log_dir, nameFileXml)
- fileTxt = os.path.join(log_dir_out, nameFileTxt)
+
+ ok = False
+ for ii in range(0, 30): # max simultaneous sat processes launched in same second (unittest....)
+ if self.idCommandHandlers == 0:
+ datehour = config.VARS.datehour
+ self.dateHour = datehour # save dateHour for micro commands
+ else:
+ datehour = self.dateHour # micro commands have same datehour for naming files
+
+ cmd = config.VARS.command
+ fullNameCmd = cmdInstance.getFullNameStr()
+ hostname = config.VARS.hostname
+ nameFileXml = "%s_%02i_%03i_%s_%s.xml" % (datehour, ii, self.idCommandHandlers, cmd, hostname)
+ nameFileTxt = "%s_%02i_%03i_%s_%s.txt" % (datehour, ii, self.idCommandHandlers, cmd, hostname)
+ fileXml = os.path.join(log_dir, nameFileXml)
+ fileTxt = os.path.join(log_dir_out, nameFileTxt)
+ if os.path.exists(fileXml):
+ continue
+ else:
+ ok = True
+ break
+
+ if not ok:
+ raise Exception("max %i simultaneous sat processes launched in same second reached" % ii)
# precaution
lastCmd = cmdInstance.getFullNameList()[-1]
def test_000(self):
# one shot setUp() for this TestCase
- DBG.push_debug(True)
+ DBG.push_debug(False)
# SAT.setNotLocale() # test english
return
self.assertEqual(lgr.name, name)
self.assertIn("trace", dir(lgr))
self.assertIn("TRACE", LOGI._levelNames.keys())
- self.assertIn(lgr._TRACE, LOGI._levelNames.keys())
+ self.assertIn(_TRACE, LOGI._levelNames.keys())
self.assertEqual(LOGI.getLevelName(LOGI.INFO), "INFO")
- self.assertEqual(LOGI.getLevelName(lgr._TRACE), "TRACE")
+ self.assertEqual(LOGI.getLevelName(_TRACE), "TRACE")
# creation d'un handler pour chaque log sur la console
formatter = LOGI.Formatter('%(levelname)-8s :: %(message)s')
cfg.__save__(outStream)
res = outStream.value
- DBG.write("test_120 cfg save", res, True)
+ DBG.write("test_120 cfg save", res)
self.assertNotIn("ERROR", res)
res = DBG.getStrConfigDbg(cfg)
- DBG.write("test_120 cfg debug", res, True)
+ DBG.write("test_120 cfg debug", res)
# no error circular !!!
# self.assertIn("ERROR", res) # no error circular !!!
# self.assertIn("unable to evaluate $cc", res)
# self.assertIn("unable to evaluate $bb", res)
res = cfg.bb
- DBG.write("test_120 cfg.bb debug", res, True)
+ DBG.write("test_120 cfg.bb debug", res)
res = cfg.cc
- DBG.write("test_120 cfg.cc debug", res, True)
+ DBG.write("test_120 cfg.cc debug", res)
def test_999(self):
# one shot tearDown() for this TestCase
class TestCase(unittest.TestCase):
"Test the sat --help commands"""
- logger = LOG.getUnittestLogger()
debug = False
def tearDown(self):
# print "tearDown", __file__
# assure self.logger clear for next test
- logs = self.logger.getLogsAndClear()
+ logger = LOG.getUnittestLogger()
+ logs = logger.getLogsAndClear()
# using assertNotIn() is too much verbose
self.assertFalse("ERROR" in logs)
self.assertFalse("CRITICAL" in logs)
def test_000(self):
+ logger = LOG.getUnittestLogger()
# one shot setUp() for this TestCase
if self.debug: DBG.push_debug(True)
SAT.setNotLocale() # test english
self.assertTrue(" - compile" in out)
def test_011(self):
+ logger = LOG.getUnittestLogger()
cmd = "--help"
- s = SAT.Sat(self.logger)
+ s = SAT.Sat(logger)
returnCode = s.execute_cli(cmd)
self.assertTrue(returnCode.isOk())
- logs = self.logger.getLogs()
+ logs = logger.getLogs()
DBG.write("test_011 logger", logs)
self.assertTrue(" - config" in logs)
self.assertTrue(" - prepare" in logs)
def test_030(self):
cmd = "sat config --help"
- stdout, stderr = SAT.launchSat(cmd)
- DBG.write("test_030 stdout", stdout)
- self.assertEqual(stderr, "")
- self.assertTrue("--value" in stdout)
+ returnCode = SAT.launchSat(cmd)
+ self.assertTrue(returnCode.isOk())
+ out = returnCode.getValue()
+ DBG.write("test_030 stdout", out)
+ self.assertTrue("--value" in out)
def test_031(self):
+ logger = LOG.getUnittestLogger()
cmd = "config --help"
- s = SAT.Sat(self.logger)
+ s = SAT.Sat(logger)
returnCode = s.execute_cli(cmd)
self.assertTrue(returnCode.isOk())
- logs = self.logger.getLogs()
+ logs = logger.getLogs()
DBG.write("test_031 logger", logs)
- self.assertTrue("--value" in logs)
-
+ self.assertTrue("--help" in logs)
+
+ def test_032(self):
+ logger = LOG.getUnittestLogger()
+ cmd = "prepare --help"
+ s = SAT.Sat(logger)
+ returnCode = s.execute_cli(cmd)
+ self.assertTrue(returnCode.isOk())
+ logs = logger.getLogs()
+ DBG.write("test_031 logger", logs)
+ self.assertTrue("--help" in logs)
+
def xxtest_040(self):
cmd = "config --list"
s = SAT.Sat(self.logger)
DBG.write("test_050 getCommandsList", cmds)
for c in cmds:
cmd = "sat %s --help" % c
- stdout, stderr = SAT.launchSat(cmd)
- self.assertEqual(stderr, "")
- DBG.write("test_050 %s stdout" % c, stdout)
- self.assertTrue("The %s command" % c in stdout)
- self.assertTrue("Available options" in stdout)
+ DBG.write("test_050", cmd)
+ returnCode = SAT.launchSat(cmd)
+ if not returnCode.isOk():
+ DBG.write("test_050 %s" % cmd, returnCode.getValue(), True)
+ self.assertTrue(returnCode.isOk())
+ out = returnCode.getValue()
+ DBG.write("test_050 %s stdout" % c, out)
+ self.assertTrue("The %s command" % c in out)
+ self.assertTrue("Available options" in out)
def test_051(self):
+ logger = LOG.getUnittestLogger()
cmds = SAT.getCommandsList()
for c in cmds:
cmd = "%s --help" % c
- s = SAT.Sat(self.logger)
+ DBG.write("test_051", cmd)
+ s = SAT.Sat(logger)
returnCode = s.execute_cli(cmd)
self.assertTrue(returnCode.isOk())
- logs = self.logger.getLogsAndClear()
+ logs = logger.getLogsAndClear()
DBG.write(cmd, logs)
self.assertTrue("The %s command" % c in logs)
self.assertTrue("Available options" in logs)
class TestCase(unittest.TestCase):
"Test the sat commands on APPLI_TEST configuration pyconf etc. files"""
-
- logger = LOG.getUnittestLogger()
+
debug = False
#see test_100, # commands are expected OK
def tearDown(self):
# print "tearDown", __file__
# assure self.logger clear for next test
- logs = self.logger.getLogsAndClear()
+ logger = LOG.getUnittestLogger()
+ logs = logger.getLogsAndClear()
# using assertNotIn() is too much verbose
self.assertFalse("ERROR ::" in logs)
self.assertFalse("CRITICAL ::" in logs)
if self.debug: DBG.pop_debug()
def test_010(self):
+ logger = LOG.getUnittestLogger()
cmd = "config -l"
- s = SAT.Sat(self.logger)
+ s = SAT.Sat(logger)
DBG.write("s.getConfig()", s.getConfig()) #none
DBG.write("s.__dict__", s.__dict__) # have
returnCode = s.execute_cli(cmd)
- DBG.write("test_010 returnCode", returnCode)
- logs = self.logger.getLogs()
+ DBG.write("test_010", returnCode)
+ logs = logger.getLogs()
DBG.write("test_010 logger", logs)
self.assertTrue(returnCode.isOk())
def test_100(self):
# test all satCommands expected OK
- dbg = self.debug # True #
+ logger = LOG.getUnittestLogger()
+ dbg = self.debug
for cmd in self.satCommandsToTestOk:
- s = SAT.Sat(self.logger)
+ s = SAT.Sat(logger)
returnCode = s.execute_cli(cmd)
- DBG.write("test_800 'sat %s' returnCode" % cmd, str(returnCode), True)
- logs = self.logger.getLogsAndClear()
+ DBG.write("test_100 'sat %s'" % cmd, str(returnCode), dbg)
+ logs = logger.getLogsAndClear()
DBG.write("logs", logs, dbg)
# using assertNotIn() is too much verbose
self.assertFalse("ERROR ::" in logs)
def test_110(self):
# test all satCommands expected KO
+ logger = LOG.getUnittestLogger()
dbg = self.debug
for cmd in self.satCommandsToTestKo:
- s = SAT.Sat(self.logger)
+ s = SAT.Sat(logger)
returnCode = s.execute_cli(cmd)
- DBG.write("test_810 'sat %s' returnCode" % cmd, returnCode, dbg)
- logs = self.logger.getLogsAndClear()
+ DBG.write("test_110 'sat %s'" % cmd, returnCode, dbg)
+ logs = logger.getLogsAndClear()
DBG.write("logs", logs, dbg)
def test_120(self):
# test all satCommands expected raise
+ logger = LOG.getUnittestLogger()
dbg = self.debug
for cmd in self.satCommandsToTestRaise:
- s = SAT.Sat(self.logger)
- DBG.write("test_820 'sat %s'" % cmd, "expected raise", dbg)
+ s = SAT.Sat(logger)
+ DBG.write("test_120 'sat %s'" % cmd, "expected raise", dbg)
with self.assertRaises(Exception):
returnCode = s.execute_cli(cmd)
- logs = self.logger.getLogsAndClear()
+ logs = logger.getLogsAndClear()
DBG.write("logs", logs, dbg)