-__all__ = ['src', 'commands', "test", "unittestpy", ]
\ No newline at end of file
+__all__ = ["src", "commands", "tests"]
\ No newline at end of file
-
-"""
-import os
-import gettext
-
-# get path to salomeTools sources
-satdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
-srcdir = os.path.join(satdir, 'src')
-cmdsdir = os.path.join(satdir, 'commands')
-
-# load resources for internationalization
-gettext.install("salomeTools", os.path.join(srcdir, "i18n"))
-
-import application
-import check
-import clean
-import compile
-import config
-import configure
-import doc
-import environ
-import find_duplicates
-import generate
-import init
-import job
-import jobs
-import launcher
-import log
-import make
-import makeinstall
-import package
-import patch
-import prepare
-import profile
-import run
-import script
-import shell
-import source
-import template
-import test
-"""
+from commands import application
+from commands import check
+from commands import clean
+from commands import compile
+from commands import config
+from commands import configure
+from commands import doc
+from commands import environ
+from commands import find_duplicates
+from commands import generate
+from commands import init
+from commands import install
+from commands import job
+from commands import jobs
+from commands import launcher
+from commands import log
+from commands import make
+from commands import makeinstall
+from commands import package
+from commands import patch
+from commands import prepare
+from commands import run
+from commands import script
+from commands import shell
+from commands import source
+from commands import test
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/env python
-#-*- coding:utf-8 -*-
-
-# ToolBox for test framework
-
-import os
-import string
-import subprocess
-
-
-class SatTestError(Exception):
- """
- Exception class for test errors.
- """
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return repr(self.value)
-
-class SatNotApplicableError(Exception):
- """
- Exception class for test errors.
- """
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return repr(self.value)
-
-def ERROR(message):
- print("ERROR", message)
- raise SatTestError(message)
-
-def NOT_APPLICABLE(message):
- print("NOT_APPLICABLE", message)
- raise SatNotApplicableError(message)
-
-def compFloat(f1, f2, tol=10e-10):
- """Compares 2 numbers with tolerance tol."""
- diff = abs(f1 - f2)
- print("|f1-f2| = %s (tol=%s)" % (str(diff), str(tol)))
- if diff <= tol:
- comp = "OK"
- else:
- comp = "KO"
- return comp
-
-def compFiles(f1, f2, tol=0):
- """Compares 2 files."""
- assert os.path.exists(f1), "compFiles: file not found: %s" % f1
- assert os.path.exists(f2), "compFiles: file not found: %s" % f2
- diffLine = os.popen("diff -y --suppress-common-lines %s %s" % (f1, f2))
- diff = len(string.split(diffLine.read(), "\n"))
- diffLine.close()
- print("nb of diff lines = %s (tol=%s)" % (str(diff), str(tol)))
- if diff <= tol:
- comp = "OK"
- else:
- comp = "KO"
- return comp
-
-def mdump_med(med_file, dump_file, options):
- """Uses mdump to dump a med file."""
- assert isinstance(options, list), "Bad options for mdump: %s" % options
- assert len(options) == 3, "Bad options for mdump: %s" % options
- cmd = "mdump %s %s" % (med_file, " ".join(options))
- #print(cmd)
-
- with open(dump_file, "w") as df:
- pdump = subprocess.Popen(cmd, shell=True, stdout=df)
- st = pdump.wait()
- return st
-
-def compMED(file1, file2, tol=0, diff_flags=""):
- """Compares 2 med files by using mdump."""
-
- # local utility method
- def do_dump(med):
- dump = os.path.join(os.environ['TT_TMP_RESULT'], os.path.basename(med) + ".mdump")
- st = mdump_med(med, dump, ["1", "NODALE", "FULL_INTERLACE"])
- if st != 0 or not os.path.exists(dump):
- raise Exception("Error mpdump %s" % med)
-
- # replace file name with "filename"
- with open(dump, "r") as ff:
- lines = ff.readlines()
- with open(dump, "w") as dumpfile:
- for line in lines:
- try:
- line.index('Universal name of mesh')
- continue
- except:
- dumpfile.write(line.replace(med, 'filename'))
- return dump
-
-
- # begin method
- print(""">>>> compMED
- file1: %s
- file2: %s
-""" % (file1, file2))
-
- if not os.path.exists(file1):
- print("compMED: file not found: '%s'" % file1)
- print("<<<< compMED\n")
- return 1
- if not os.path.exists(file2):
- print("compMED: file not found: '%s'" % file2)
- print("<<<< compMED\n")
- return 1
-
- dump1 = do_dump(file1)
- dump2 = do_dump(file2)
-
- diff_cmd = "diff %s %s %s" % (diff_flags, dump1, dump2)
- print(" >" + diff_cmd)
- pdiff = subprocess.Popen(diff_cmd, shell=True, stdout=subprocess.PIPE)
- status = pdiff.wait()
- print(" Diff =", status)
- if status != 0:
- print(pdiff.stdout.read())
-
- print("<<<< compMED\n")
- return status
-
-
-class TOOLS_class(object):
- def __init__(self, base_ressources_dir, tmp_dir, test_ressources_dir):
- self.base_ressources_dir = base_ressources_dir
- self.tmp_dir = tmp_dir
- self.test_ressources_dir = test_ressources_dir
- pass
-
- def init(self):
- self.inFiles = []
-
- def ERROR(self, message):
- # Simulation d'un plantage
- ERROR(message)
-
- def compMED(self, file1, file2, tol=0):
- return compMED(file1, file2, tol, "--ignore-all-space")
-
- def compFloat(self, f1, f2, tol=10e-10):
- return compFloat(f1, f2, tol)
-
- def compFiles(self, f1, f2, tol=0):
- return compFiles(f1, f2, tol)
-
- def get_inFile(self, name=None):
- if not name:
- return self.base_ressources_dir
- self.inFiles.append(name)
- return os.path.join(self.base_ressources_dir, name)
-
- def get_outFile(self, name=None):
- if not name:
- return self.tmp_dir
- return os.path.join(self.tmp_dir, name)
-
- def writeInFiles(self, pylog):
- pylog.write('inFiles=%s\n' % str(self.inFiles))
-
+++ /dev/null
-#!/usr/bin/env python
-#-*- coding:utf-8 -*-
-
-"""
-This script is automatically generated by 'command sat test etc...'
-from ...salomeTools/src/test/scriptTemplate.py
-"""
-
-import os
-import sys
-import traceback
-import os.path
-import time as THEBIGTIME
-
-
-# set path
-toolsWay = r'${toolsWay}'
-resourcesWay = r'${resourcesWay}'
-outWay = r'${sessionDir}'
-tmpDir = r'${tmpDir}'
-
-listTest = ${listTest}
-ignore = ${ignore}
-
-sys.path.append(toolsWay)
-from TOOLS import TOOLS_class
-my_tools = TOOLS_class(resourcesWay, tmpDir, toolsWay)
-
-from TOOLS import SatNotApplicableError
-
-# set environement variables
-os.environ['TT_BASE_RESSOURCES'] = resourcesWay
-sys.path.append(resourcesWay)
-
-__stdout__ = sys.stdout
-__stderr__ = sys.stderr
-
-with open(r'${resultFile}', 'w') as exec_result:
- exec_result.write('Open\n')
- print("wrapper ignore tests: %s" % ignore)
- for test in listTest:
- fileTest = os.path.join(outWay, test)
- # print("test file: %s" % fileTest) # cvw TODO
- with open(os.path.join(outWay, test[:-3] + ".result.py"), "w") as pylog:
- with open(os.path.join(outWay, test[:-3] + ".out.py"), "w") as testout:
- my_tools.init()
- # print("here set sys.stdout")
- sys.stdout = testout
- sys.stderr = testout
-
- # pylog.write('#!/usr/bin/env python\n')
- exec_result.write("Run %s " % test)
- exec_result.flush()
-
- try:
- timeStart = THEBIGTIME.time()
- # cd ..print("begin... %s" % fileTest)
- # execfile(fileTest, globals(), locals()) obsolete python3
- with open(fileTest) as f:
- # compile associates the filename with the code object making debugging a little easier
- code = compile(f.read(), fileTest, 'exec')
- exec(code, globals(), locals())
- timeTest = THEBIGTIME.time() - timeStart
- # print("...done %s" % fileTest)
- timeTest = THEBIGTIME.time() - timeStart
- except SatNotApplicableError as ex:
- # print("here SatNotApplicableError")
- # pylog.write("here SatNotApplicableError")
- status = "NA"
- reason = str(ex)
- exec_result.write("NA\n")
- timeTest = THEBIGTIME.time() - timeStart
- pylog.write('status = "NA"\n')
- pylog.write('time = "' + timeTest.__str__() + '"\n')
- pylog.write('callback = "%s"\n' % reason)
- except Exception as ex:
- # print("here Exception")
- # pylog.write("here Exception pylog\n")
- status = "KO"
- reason = ""
- if test in ignore:
- status = "KF"
- reason = "Known Failure = %s\n\n" % ignore[test]
- exec_result.write("%s\n" % status)
- timeTest = THEBIGTIME.time() - timeStart
- pylog.write('status = "%s" \n' % status)
- pylog.write('time = "' + timeTest.__str__() + '"\n')
- pylog.write('callback="""' + reason)
- exc_type, exc_value, exc_traceback = sys.exc_info()
- traceback.print_exception(exc_type,
- exc_value,
- exc_traceback,
- None,
- file=pylog)
- pylog.write('"""\n')
- else:
- # print("here else")
- # pylog.write("here else pylog")
- exec_result.write("OK\n")
- pylog.write('status = "OK"\n')
- pylog.write('time = "' + timeTest.__str__() + '"\n')
-
- pass
- # print("here testout.flush")
- testout.flush()
- # testout.close()
-
- # print("here restore sys.stdout")
- sys.stdout = __stdout__
- sys.stderr = __stderr__
- my_tools.writeInFiles(pylog)
- pass
- pylog.flush()
- # pylog.close()
-
- exec_result.write('Close\n')
- pass
- # exec_result.close()
-
-if 'PY' not in '${sessionName}':
- import salome_utils
- #killScript = os.path.join(os.environ['KERNEL_ROOT_DIR'],
- # 'bin',
- # 'salome',
- # 'killSalome.py')
- #cmd = '{python} {killScript} {port}'.format(python=os.environ['PYTHONBIN'],
- # killScript=killScript,
- # port=salome_utils.getPortNumber())
- cmd = 'killSalome.py {port}'.format( port=salome_utils.getPortNumber())
- os.system(cmd)
-
+++ /dev/null
-#TODO
-switch pyconf.py 0.3.7.1 -> 0.3.9, here for test
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-
-"""
-to set id_rsa from/to reflexive on local machine:
-
- @is231761/home/wambeke/.ssh>ssh wambeke@is231761
- Password:
- Last login: Thu Jun 7 13:34:07 2018 from is231761.intra.cea.fr
- @is231761/home/wambeke>exit
- déconnexion
-
- @is231761/home/wambeke/.ssh> ssh-keygen
- Generating public/private rsa key pair.
- Enter file in which to save the key (/home/wambeke/.ssh/id_rsa):
- Enter passphrase (empty for no passphrase):
- Enter same passphrase again:
- Your identification has been saved in /home/wambeke/.ssh/id_rsa.
- Your public key has been saved in /home/wambeke/.ssh/id_rsa.pub.
- The key fingerprint is:
- SHA256:V0IU/wkuCRw42rA5bHFgdJlzDx9EIJyWIBrkzkL3GNA wambeke@is231761
- The key's randomart image is:
- +---[RSA 2048]----+
- |ooo.=+o*o=*. |
-
- | |
- +----[SHA256]-----+
-
- @is231761/home/wambeke/.ssh> ls
- id_rsa id_rsa.pub known_hosts
- @is231761/home/wambeke/.ssh> rm known_hosts
- @is231761/home/wambeke/.ssh> ls
- id_rsa id_rsa.pub
-
- @is231761/home/wambeke/.ssh> ssh wambeke@is231761
- The authenticity of host 'is231761 (127.0.0.1)' can't be established.
- ECDSA key fingerprint is SHA256:QvrU7Abrbily0bzMjYbRPeKCxDkXT9rQ6pSpcm+yFN4.
- ECDSA key fingerprint is MD5:6c:95:b7:c7:cd:de:c5:07:8b:3a:9b:14:d1:69:6b:c6.
- Are you sure you want to continue connecting (yes/no)? yes
- Warning: Permanently added 'is231761' (ECDSA) to the list of known hosts.
- Password:
- Last login: Thu Jun 7 13:35:07 2018 from is231761.intra.cea.fr
- @is231761/home/wambeke>exit
- déconnexion
- Connection to is231761 closed.
-
-
- @is231761/home/wambeke/.ssh> lst
- total 124K
- -rw-r--r-- 1 wambeke lgls 170 7 juin 13:36 known_hosts
- drwx------ 2 wambeke lgls 4,0K 7 juin 13:36 .
- -rw-r--r-- 1 wambeke lgls 398 7 juin 13:35 id_rsa.pub
- -rw------- 1 wambeke lgls 1,7K 7 juin 13:35 id_rsa
- drwxr-xr-x 182 wambeke lmpe 104K 6 juin 13:39 ..
-
-
-
- @is231761/home/wambeke/.ssh> ssh-copy-id -i ~/.ssh/id_rsa.pub is231761
- /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/wambeke/.ssh/id_rsa.pub"
- /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
- /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
- Password:
-
- Number of key(s) added: 1
-
- Now try logging into the machine, with: "ssh 'is231761'"
- and check to make sure that only the key(s) you wanted were added.
-
- @is231761/home/wambeke/.ssh> ssh wambeke@is231761
- Last login: Thu Jun 7 13:36:42 2018 from is231761.intra.cea.fr
- @is231761/home/wambeke>exit
- déconnexion
- Connection to is231761 closed.
-
-"""
-
-import os
-import unittest
-import getpass
-
-verbose = False
-
-
-class TestCase(unittest.TestCase):
- "Test a paramiko connection" ""
-
- def setLoggerParamiko(self):
- """to get logs of paramiko, useful if problems"""
- import logging as LOGI
-
- loggerPrmk = LOGI.getLogger("paramiko")
- if len(loggerPrmk.handlers) != 0:
- print("logging.__file__ %s" % LOGI.__file__)
- print("logger paramiko have handler set yet, is a surprise")
- return
- if not verbose:
- # stay as it, null
- return
-
- # set a paramiko logger verbose
- handler = LOGI.StreamHandler()
- msg = "create paramiko logger, with handler on stdout"
-
- # handler = LOGI.MemoryHandler()
- # etc... https://docs.python.org/2/library/logging.handlers.html
- # msg = "create paramiko logger, with handler in memory"
-
- # original frm from paramiko
- # frm = '%(levelname)-.3s [%(asctime)s.%(msecs)03d] thr=%(thread)-3d %(name)s: %(message)s' # noqa
- frm = "%(levelname)-5s :: %(asctime)s :: %(name)s :: %(message)s"
- handler.setFormatter(LOGI.Formatter(frm, "%y%m%d_%H%M%S"))
- loggerPrmk.addHandler(handler)
-
- # logger is not notset but low, handlers needs setlevel greater
- loggerPrmk.setLevel(LOGI.DEBUG)
- handler.setLevel(LOGI.INFO) # LOGI.DEBUG) # may be other one
-
- loggerPrmk.info(msg)
-
- """example from internet
- def fetch_netmask(self, hostname, port=22):
- private_key = os.path.expanduser('~/.ssh/id_rsa')
- connection = open_ssh_connection('wambeke', hostname, port=port, key=private_key)
-
- get_netmask = ("ip -oneline -family inet address show | grep {}").format(hostname)
- stdin, stdout, stderr = connection.exec_command(get_netmask)
- address = parse_address(hostname, stdout)
- connection.close()
- return address
-
- def open_ssh_connection(self, username, hostname, port=22, key=None):
- client = PK.SSHClient()
- client.set_missing_host_key_policy(PK.AutoAddPolicy())
- client.connect(hostname, port=port, timeout=5, username=username, key_filename=key)
- return client
- """
-
- def test_000(self):
- self.setLoggerParamiko()
-
- def test_010(self):
- # http://docs.paramiko.org/en/2.4/api/agent.html
-
- try:
- import paramiko as PK
- except:
- print("\nproblem 'import paramiko', no tests")
- return
-
- # port=22 # useless
- username = getpass.getuser()
- hostname = os.uname()[1]
- aFile = "/tmp/%s_test_paramiko.tmp" % username
- cmd = ("pwd; ls -alt {0}; cat {0}").format(aFile)
-
- # connect
- client = PK.SSHClient()
- client.set_missing_host_key_policy(PK.AutoAddPolicy())
- # client.connect(hostname, username=username, password="xxxxx")
- # client.connect(hostname, username=username, passphrase="yyyy", key_filename="/home/wambeke/.ssh/id_rsa_satjobs_passphrase")
- # client.connect(hostname, username=username)
-
- # timeout in seconds
- client.connect(hostname, username=username, timeout=1.0)
-
- # obtain session
- session = client.get_transport().open_session()
- # Forward local agent
- PK.agent.AgentRequestHandler(session)
- # commands executed after this point will see the forwarded agent on the remote end.
-
- # one api
- session.exec_command("date > %s" % aFile)
- cmd = ("pwd; ls -alt {0}; cat {0} && echo OK").format(aFile)
- # another api
- stdin, stdout, stderr = client.exec_command(cmd)
- output = stdout.read()
- if verbose:
- print("stdout:\n%s" % output)
- self.assertTrue(aFile in output)
- self.assertTrue("OK" in output)
- client.close()
-
-
-if __name__ == "__main__":
- # verbose = True # human eyes
- unittest.main(exit=False)
+++ /dev/null
-theses tests from sat5.0 are obsolete
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-import src.product
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test of the compile command"""
-
- def test_010(self):
- # Test the compile command with '--products' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
-
- sat.clean(appli + " --build --install --product " + product_name, batch=True)
- sat.compile(appli + " --product " + product_name)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the configure command with '--fathers' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
- product_name2 = "PRODUCT_ARCHIVE"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name + "," + product_name2)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
- expected_install_dir2 = src.product.get_product_config(
- sat.cfg, product_name2
- ).install_dir
- expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
-
- sat.clean(
- appli
- + " --build --install --product "
- + product_name
- + ","
- + product_name2,
- batch=True,
- )
- sat.compile(appli + " --with_fathers --product " + product_name)
-
- if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the configure command with '--children' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
- product_name2 = "PRODUCT_ARCHIVE"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name + "," + product_name2)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
- expected_install_dir2 = src.product.get_product_config(
- sat.cfg, product_name2
- ).install_dir
- expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
-
- sat.clean(
- appli
- + " --build --install --product "
- + product_name
- + ","
- + product_name2,
- batch=True,
- )
- sat.compile(appli + " --with_children --product " + product_name2)
-
- if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the configure command with '--clean_all' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
- product_name2 = "PRODUCT_ARCHIVE"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name + "," + product_name2)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
- expected_install_dir2 = src.product.get_product_config(
- sat.cfg, product_name2
- ).install_dir
- expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
-
- sat.compile(appli + " --with_children --product " + product_name2)
-
- sat.compile(
- appli + " --clean_all --with_children --product " + product_name2,
- batch=True,
- )
-
- if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the configure command with '--clean_install' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
- product_name2 = "PRODUCT_ARCHIVE"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name + "," + product_name2)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
- expected_install_dir2 = src.product.get_product_config(
- sat.cfg, product_name2
- ).install_dir
- expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
-
- sat.compile(appli + " --with_children --product " + product_name2)
-
- sat.compile(
- appli + " --clean_install --with_children --product " + product_name2,
- batch=True,
- )
-
- if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test the configure command with '--make_flags' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
-
- sat.clean(appli + " --build --install --product " + product_name, batch=True)
- sat.compile(appli + " --make_flags 3 --product " + product_name)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_070(self):
- # Test the configure command with '--show' option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
-
- sat.clean(appli + " --build --install --product " + product_name, batch=True)
- sat.compile(appli + " --show --product " + product_name)
-
- if not (os.path.exists(expected_file_path)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_080(self):
- # Test the configure command with '--stop_first_fail' option
- OK = "KO"
-
- appli = "appli-test"
-
- sat = Sat()
-
- sat.prepare(appli + " --product PRODUCT_CVS,Python")
- expected_install_dir = src.product.get_product_config(
- sat.cfg, "PRODUCT_CVS"
- ).install_dir
-
- sat.clean(appli + " --build --install --product PRODUCT_CVS", batch=True)
- sat.compile(appli + " --stop_first_fail --product PRODUCT_CVS,Python")
-
- if not (os.path.exists(expected_install_dir)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_090(self):
- # Test the 'sat -h compile' command to get description
-
- OK = "KO"
-
- import compile
-
- if "The compile command constructs the products" in compile.description():
- OK = "OK"
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-import src.product
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test of the configure command"""
-
- def setUp(self):
- print("setUp")
-
- def tearDown(self):
- print("tearDown")
-
- def test_010(self):
- # Test the configure command with a product in cmake
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
- expected_file_path = os.path.join(expected_build_dir, "CMakeCache.txt")
-
- sat.configure(appli + " --product " + product_name)
-
- if os.path.exists(os.path.join(expected_build_dir, expected_file_path)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the configure command with a product in autotools
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_CVS"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
- expected_file_path = os.path.join(expected_build_dir, "config.log")
-
- sat.configure(appli + " --product " + product_name)
-
- if os.path.exists(os.path.join(expected_build_dir, expected_file_path)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the configure command with a product in script mode
- OK = "KO"
-
- appli = "appli-test"
- product_name = "Python"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
-
- sat.configure(appli + " --product " + product_name)
-
- if os.path.exists(expected_build_dir):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the 'sat -h configure'
- OK = "KO"
-
- import configure
-
- if (
- "The configure command executes in the build directory"
- in configure.description()
- ):
- OK = "OK"
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-import src.product
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test of the make command"""
-
- def test_010(self):
- # Test the configure command without any option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
- expected_file_path = os.path.join(expected_build_dir, "hello")
-
- sat.configure(appli + " --product " + product_name)
- sat.make(appli + " --product " + product_name)
-
- if os.path.exists(os.path.join(expected_build_dir, expected_file_path)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the make command with an option
- OK = "KO"
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
- expected_file_path = os.path.join(expected_build_dir, "hello")
-
- sat.configure(appli + " --product " + product_name)
- sat.make(appli + " --product " + product_name + " --option -j3")
-
- if os.path.exists(os.path.join(expected_build_dir, expected_file_path)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the make command with a product in script mode
- OK = "KO"
-
- appli = "appli-test"
- product_name = "Python"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file = "bin/python2.7"
-
- sat.make(appli + " --product " + product_name)
-
- if os.path.exists(os.path.join(expected_install_dir, expected_file)):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the sat -h make
- OK = "KO"
-
- import make
-
- if 'The make command executes the "make" command' in make.description():
- OK = "OK"
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-import src.product
-from src.salomeTools import Sat
-
-
-class TestMakeinstall(unittest.TestCase):
- """Test of the makeinstall command"""
-
- def test_010(self):
- # Test the configure-make-makeinstall command without any option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- sat.prepare(appli + " --product " + product_name)
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_file_path = os.path.join(expected_install_dir, "bin/hello")
-
- sat.configure(appli + " --product " + product_name)
-
- sat.make(appli + " --product " + product_name)
-
- sat.makeinstall(appli + " --product " + product_name)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the sat -h make
- OK = "KO"
-
- import makeinstall
-
- if (
- "The makeinstall command executes the 'make install' command"
- in makeinstall.description()
- ):
- OK = "OK"
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import shutil
-import unittest
-
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test create file .pyconf"""
-
- def test_010(self):
- # Test creation of ~/.salomeTools/salomeTools.pyconf
- print("stupidity HAVE TO NOT touch user ~/.salomeTools")
- return
-
- res = "KO"
- user_dir = os.path.expanduser(os.path.join("~", ".salomeTools"))
- user_dir_save = os.path.expanduser(os.path.join("~", ".salomeTools_save"))
- if os.path.exists(user_dir_save):
- shutil.rmtree(user_dir_save)
- if os.path.exists(user_dir):
- shutil.move(user_dir, user_dir_save)
-
- # The command to test
- sat = Sat("")
- sat.config("-v .")
-
- expected_file = os.path.expanduser(
- os.path.join("~", ".salomeTools", "salomeTools.pyconf")
- )
-
- if os.path.exists(expected_file):
- res = "OK"
-
- shutil.rmtree(user_dir)
- shutil.move(user_dir_save, user_dir)
- self.assertEqual(res, "OK")
-
- def test_020(self):
- # Test override VARS
- OK = "KO"
-
- # The command to test
- sat = Sat("-oVARS.user='user_test'")
- sat.config()
-
- if sat.cfg.VARS.user == "user_test":
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test override INTERNAL
- OK = "KO"
-
- # The command to test
- sat = Sat("-oINTERNAL.sat_version='V0'")
- sat.config()
-
- if sat.cfg.INTERNAL.sat_version == "V0":
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- """
- def test_040(self):
- # Test override SITE
- OK = "KO"
-
- # The command to test
- sat = Sat("-oSITE.jobs.config_path='/tmp'")
- sat.config()
-
- if sat.cfg.SITE.jobs.config_path == '/tmp':
- OK = "OK"
-
- self.assertEqual(OK, "OK")
- """
-
- def test_050(self):
- # Test override APPLICATION
- OK = "KO"
-
- # The command to test
- sat = Sat("-oAPPLICATION.out_dir='/tmp'")
- sat.config("appli-test")
-
- if sat.cfg.APPLICATION.out_dir == "/tmp":
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test override PRODUCTS
- OK = "KO"
-
- # The command to test
- sat = Sat("-oPRODUCTS.PRODUCT_GIT.default.name='test'")
- sat.config("")
-
- if sat.cfg.PRODUCTS.PRODUCT_GIT.default.name == "test":
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """sat config --copy"""
-
- def test_010(self):
- # Test the copy of a pyconf
- res = "KO"
- appli_to_copy = "appli-test"
-
- expected_file = os.path.expanduser(
- os.path.join(
- "~",
- ".salomeTools",
- "Applications",
- "LOCAL_" + appli_to_copy + ".pyconf",
- )
- )
- if os.path.exists(expected_file):
- os.remove(expected_file)
-
- # The command to test
- sat = Sat("")
- sat.config("appli-test -c")
-
- if os.path.exists(expected_file):
- res = "OK"
- os.remove(expected_file)
- self.assertEqual(res, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import threading
-import time
-import unittest
-
-from src.salomeTools import Sat
-from unittestpy.tools import check_proc_existence_and_kill_multi
-
-sleep_time = 2
-
-
-class TestCase(unittest.TestCase):
- """sat config --edit"""
-
- def test_010(self):
- # Test the launch of the editor when invoking the config -e
- OK = "KO"
-
- sat = Sat("-oUSER.editor='cooledit'")
- sat.config()
- cmd_config = threading.Thread(target=sat.config, args=("-e",))
- cmd_config.start()
-
- time.sleep(sleep_time)
-
- editor = sat.cfg.USER.editor
- pid = check_proc_existence_and_kill_multi(
- editor + ".*" + "salomeTools\.pyconf", 10
- )
-
- if pid:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the launch of the editor when invoking the config -e appli-test
- OK = "KO"
-
- sat = Sat("-oUSER.editor='cooledit'")
- sat.config()
- cmd_config = threading.Thread(target=sat.config, args=("appli-test -e",))
- cmd_config.start()
-
- time.sleep(sleep_time)
-
- editor = sat.cfg.USER.editor
- pid = check_proc_existence_and_kill_multi(
- editor + ".*" + "appli-test\.pyconf", 10
- )
-
- if pid:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import platform
-import unittest
-
-from src.salomeTools import Sat
-from unittestpy.tools import outRedirection
-
-
-class TestCase(unittest.TestCase):
- """sat config --value"""
-
- def test_010(self):
- # Test the display of the right value of "sat config -v VARS.hostname"
- OK = "KO"
-
- # output redirection
- my_out = outRedirection()
-
- # The command to test
- sat = Sat()
- sat.config("-v VARS.hostname")
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if platform.node() in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the display of the right value of "sat config -l"
- OK = "KO"
-
- # output redirection
- my_out = outRedirection()
-
- # The command to test
- sat = Sat()
- sat.config("-l")
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- # get results
- if "ERROR" not in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- """
- def test_030(self):
- # Test the exception when salomeTools.pyconf has errors
- OK = "KO"
-
- # The command to test
- sat = Sat()
- sat.config()
-
- salomeToolspyconfPath = os.path.join(sat.cfg.VARS.srcDir, "internal_config", "salomeTools.pyconf")
- salomeToolspyconfPath_save = os.path.join(sat.cfg.VARS.srcDir, "internal_config", "salomeTools.pyconf_save")
- if os.path.exists(salomeToolspyconfPath_save):
- os.remove(salomeToolspyconfPath_save)
- shutil.copyfile(salomeToolspyconfPath, salomeToolspyconfPath_save)
- f_read = open(salomeToolspyconfPath, 'r')
- text = f_read.read()
- f_read.close()
- os.remove(salomeToolspyconfPath)
- f_write = open(salomeToolspyconfPath, 'w')
- f_write.write(text.replace(':', ''))
- f_write.close()
-
- try:
- sat.config()
- except TypeError:
- OK = "OK"
- finally:
- shutil.copyfile(salomeToolspyconfPath_save, salomeToolspyconfPath)
- os.remove(salomeToolspyconfPath_save)
- self.assertEqual(OK, "OK")
- """
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import platform
-import unittest
-
-from src.salomeTools import Sat
-from unittestpy.tools import outRedirection
-
-
-class TestCase(unittest.TestCase):
- """sat config -v VARS.python"""
-
- def test_010(self):
- # Test the display of the right value of 'sat config -v VARS.python'
- OK = "KO"
-
- # output redirection
- my_out = outRedirection()
-
- # The command to test
- sat = Sat("")
- sat.config("-v VARS.python")
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if platform.python_version() in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the display of the right value of 'sat config -s'
- OK = "KO"
-
- # output redirection
- my_out = outRedirection()
-
- # The command to test
- sat = Sat("")
- sat.config("-s")
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "INTERNAL" in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the display of the right value of 'sat config --info'
- application = "appli-test"
- product = "PRODUCT_DEV"
-
- OK = "KO"
-
- # output redirection
- my_out = outRedirection()
-
- # The command to test
- sat = Sat("")
- sat.config(application + " --info " + product)
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "compilation method = cmake" in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-
-
-class TestSource(unittest.TestCase):
- """Test of the environ command"""
-
- def test_010(self):
- # Test the environ command without any option
- OK = "KO"
-
- appli = "appli-test"
-
- file_env_name = "env_launch.sh"
-
- sat = Sat()
- sat.config(appli)
-
- expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
-
- if os.path.exists(expected_file_path):
- os.remove(expected_file_path)
-
- sat.environ(appli)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the environ command with option '--products'
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- file_env_name = "env_launch.sh"
-
- sat = Sat()
- sat.config(appli)
-
- expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
-
- if os.path.exists(expected_file_path):
- os.remove(expected_file_path)
-
- sat.environ(appli + " --products " + product_name)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the environ command with option --target
- OK = "KO"
-
- appli = "appli-test"
-
- file_env_name = "env_launch.sh"
-
- sat = Sat()
- sat.config(appli)
-
- expected_file_path = os.path.join(".", file_env_name)
- expected_file_path2 = os.path.join(".", "env_build.sh")
-
- if os.path.exists(expected_file_path):
- os.remove(expected_file_path)
-
- sat.environ(appli + " --target .")
-
- if os.path.exists(expected_file_path):
- OK = "OK"
-
- if os.path.exists(expected_file_path):
- os.remove(expected_file_path)
- os.remove(expected_file_path2)
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the environ command with option --prefix
- OK = "KO"
-
- appli = "appli-test"
- prefix = "TEST"
- file_env_name = prefix + "_launch.sh"
-
- sat = Sat()
- sat.config(appli)
-
- expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
-
- if os.path.exists(expected_file_path):
- os.remove(expected_file_path)
-
- sat.environ(appli + " --prefix " + prefix)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the environ command with option --shell
- OK = "KO"
-
- appli = "appli-test"
- shell = "bat"
- file_env_name = "env_launch.bat"
-
- sat = Sat()
- sat.config(appli)
-
- expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
-
- if os.path.exists(expected_file_path):
- os.remove(expected_file_path)
-
- sat.environ(appli + " --shell " + shell)
-
- if os.path.exists(expected_file_path):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test the job command"""
-
- def test_010(self):
- # Test the job command
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- sat.job("--jobs_config .test --name Job 1")
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_config = [
- line.replace("\n", "") for line in log_files if "config.xml" in line
- ]
-
- text = open(log_config[0], "r").read()
-
- if "nb_proc" in text:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the job command with a failing command
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- res = sat.job("--jobs_config .test --name Job 4")
-
- if res == 1:
- OK = "OK"
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the job command with a wrong file configuration
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- res = sat.job("--jobs_config NOTEXIST --name Job 4")
-
- if res == 1:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the job command without --jobs_config option
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- res = sat.job("--name Job 4")
-
- if res == 1:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the job command without --jobs_config option
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- res = sat.job("--jobs_config .test --name NOTEXIST")
-
- if res == 1:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test the sat -h job
- OK = "KO"
-
- import job
-
- if (
- "Executes the commands of the job defined in the jobs configuration file"
- in job.description()
- ):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-from unittestpy.tools import outRedirection
-
-
-class TestCase(unittest.TestCase):
- "Test the jobs command" ""
-
- def test_010(self):
- # Test the jobs command
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the jobs command
- sat.jobs("--name .test --publish")
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_jobs = [line.replace("\n", "") for line in log_files if "jobs.xml" in line]
-
- text = open(log_jobs[0], "r").read()
-
- expected_res = [
- "Establishing connection with all the machines",
- "Executing the jobs",
- "Results for job",
- ]
-
- res = 0
- for exp_res in expected_res:
- if exp_res not in text:
- res += 1
-
- if res == 0:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the jobs command with option --only_jobs
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the jobs command
- sat.jobs("--name .test --publish --only_jobs Job 1")
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_jobs = [line.replace("\n", "") for line in log_files if "jobs.xml" in line]
-
- text = open(log_jobs[0], "r").read()
-
- expected_res = [
- "Establishing connection with all the machines",
- "Executing the jobs",
- "Results for job",
- ]
-
- res = 0
- for exp_res in expected_res:
- if exp_res not in text:
- res += 1
-
- if res == 0:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the jobs command without --name option
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- res = sat.jobs()
-
- if res == 1:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the jobs command with a wrong file configuration
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- res = sat.jobs("--name NOTEXIST")
-
- if res == 1:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the display of the right value of 'sat jobs --list'
- OK = "KO"
-
- # output redirection
- my_out = outRedirection()
-
- # The command to test
- sat = Sat()
- sat.jobs("--list")
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- # get results
- if "ERROR" not in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test the sat -h jobs
- OK = "KO"
-
- import jobs
-
- if (
- "The jobs command launches maintenances that are described in the dedicated jobs configuration file."
- in jobs.description()
- ):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import sys
-import threading
-import time
-import shutil
-import io
-import unittest
-
-from src.salomeTools import Sat
-from unittestpy.tools import check_proc_existence_and_kill_multi
-
-sleep_time = 2
-
-
-class TestCase(unittest.TestCase):
- """Test of log command: launch of browser"""
-
- def test_010(self):
- # Test the write of xml log when invoking a command
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
- sat.config("appli-test -v USER.browser")
-
- # get log file path
- logDir = sat.cfg.USER.log_dir
- logPath = os.path.join(
- logDir, sat.cfg.VARS.datehour + "_" + sat.cfg.VARS.command + ".xml"
- )
-
- if os.path.exists(logPath):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the terminal option without application
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- one = u"1"
- sys.stdin = io.StringIO(one)
-
- try:
- sat.log("-t")
- OK = "OK"
- sys.stdin = sys.__stdin__
- except:
- sys.stdin = sys.__stdin__
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the terminal option with application
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("appli-test -v VARS.python")
-
- one = u"1"
- sys.stdin = io.StringIO(one)
-
- try:
- sat.log("appli-test -t --last")
- OK = "OK"
- sys.stdin = sys.__stdin__
- except:
- pass
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the terminal option with 0 as input
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("appli-test -v VARS.python")
-
- zero = u"0\n1"
- sys.stdin = io.StringIO(zero)
-
- try:
- sat.log("--terminal")
- OK = "OK"
- finally:
- sys.stdin = sys.__stdin__
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the terminal option with input bigger than the number of logs
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("appli-test -v VARS.python")
-
- nb_logs = len(os.listdir(sat.cfg.USER.log_dir))
-
- nb_logs_u = unicode(str(nb_logs) + "\n1")
- sys.stdin = io.StringIO(nb_logs_u)
-
- try:
- sat.log("--terminal")
- OK = "OK"
- finally:
- sys.stdin = sys.__stdin__
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test the terminal option with input return
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("appli-test -v VARS.python")
-
- ret = unicode("\n0")
- sys.stdin = io.StringIO(ret)
-
- try:
- sat.log("--terminal")
- OK = "OK"
- finally:
- sys.stdin = sys.__stdin__
- self.assertEqual(OK, "OK")
-
- def test_070(self):
- # Test the terminal option with input not int
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("appli-test -v VARS.python")
-
- ret = unicode("blabla\n0")
- sys.stdin = io.StringIO(ret)
-
- try:
- sat.log("--terminal")
- OK = "OK"
- finally:
- sys.stdin = sys.__stdin__
- self.assertEqual(OK, "OK")
-
- def test_080(self):
- # Test the terminal option and option last
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- try:
- sat.log("--terminal --last")
- OK = "OK"
- finally:
- sys.stdin = sys.__stdin__
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, "OK")
-
- def test_090(self):
- # Test the option --last
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat("-oUSER.browser='konqueror'")
-
- sat.config("appli-test -v VARS.python")
-
- time.sleep(sleep_time)
- cmd_log = threading.Thread(target=sat.log, args=("appli-test --last",))
- cmd_log.start()
-
- time.sleep(sleep_time)
-
- browser = sat.cfg.USER.browser
- pid = check_proc_existence_and_kill_multi(browser + ".*" + "xml", 10)
-
- if pid:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_100(self):
- # Test the option --clean
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("-v VARS.user")
-
- nb_logs_t0 = len(os.listdir(sat.cfg.USER.log_dir))
-
- sat.log("--clean 1")
-
- nb_logs_t1 = len(os.listdir(sat.cfg.USER.log_dir))
-
- if nb_logs_t1 - nb_logs_t0 == 0:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_120(self):
- # Test the option --clean with big number of files to clean
- OK = "KO"
-
- # launch the command that will write a log
- sat = Sat()
-
- sat.config("-v VARS.user")
-
- len(os.listdir(sat.cfg.USER.log_dir))
-
- if os.path.exists(sat.cfg.USER.log_dir + "_save"):
- shutil.rmtree(sat.cfg.USER.log_dir + "_save")
- print(
- "TODO: risky !!!copytree!!!",
- sat.cfg.USER.log_dir,
- sat.cfg.USER.log_dir + "_save",
- )
- """
- shutil.copytree(sat.cfg.USER.log_dir,sat.cfg.USER.log_dir + "_save")
-
- sat.log('--clean ' + str(nb_logs_t0))
-
- nb_logs_t1 = len(os.listdir(sat.cfg.USER.log_dir))
-
- shutil.rmtree(sat.cfg.USER.log_dir)
- shutil.move(sat.cfg.USER.log_dir + "_save", sat.cfg.USER.log_dir)
-
- if nb_logs_t0-nb_logs_t1 > 10:
- OK = "OK"
- """
- self.assertEqual(OK, "OK")
-
- """
- def test_130(self):
- # Test the option --full
- OK = "KO"
-
- sat = Sat("-oUSER.browser='konqueror'")
- time.sleep(sleep_time)
- cmd_log = threading.Thread(target=sat.log, args=('--full',))
- cmd_log.start()
-
- time.sleep(sleep_time)
-
- browser = sat.cfg.USER.browser
- check_proc_existence_and_kill_multi(browser + ".*" + "hat\.xml", 10)
-
- # Read and check the hat.xml file contains at least one log file corresponding to log
- hatFilePath = os.path.join(sat.cfg.USER.log_dir, "hat.xml")
- xmlHatFile = src.xmlManager.ReadXmlFile(hatFilePath)
- for field in xmlHatFile.xmlroot:
- if field.attrib[b'cmd'] == b'log':
- OK = "OK"
- break
- self.assertEqual(OK, "OK")
- """
-
- def test_140(self):
- # Test the sat -h log
- OK = "KO"
-
- import log
-
- if "Gives access to the logs produced" in log.description():
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import threading
-import time
-import unittest
-
-from src.salomeTools import Sat
-from unittestpy.tools import check_proc_existence_and_kill_multi
-
-sleep_time = 2
-
-
-class TestCase(unittest.TestCase):
- """Test of log command: launch of browser"""
-
- def test_010(self):
- # Test the launch of browser when invoking the log command
- OK = "KO"
-
- sat = Sat("-oUSER.browser='konqueror'")
- time.sleep(sleep_time)
- cmd_log = threading.Thread(target=sat.log, args=("",))
- cmd_log.start()
-
- time.sleep(sleep_time)
-
- sat.config("")
- browser = sat.cfg.USER.browser
- pid = check_proc_existence_and_kill_multi(browser + ".*" + "hat\.xml", 10)
-
- if pid:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-import src.product
-from unittestpy.tools import outRedirection
-
-
-class TestCase(unittest.TestCase):
- """Test of the clean command"""
-
- def test_010(self):
- # Test the clean command with no arguments (nothing to clean)
- OK = "KO"
-
- appli = "appli-test"
-
- sat = Sat()
-
- # output redirection
- my_out = outRedirection()
-
- sat.clean(appli)
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "Nothing to suppress" in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the clean of sources
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- # Make sure the sources exist
- sat.prepare(appli + " -p " + product_name)
-
- # Call the command
- sat.clean(appli + " -p " + product_name + " --sources", batch=True)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
-
- if not os.path.exists(expected_src_dir):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the clean of build
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- # Make sure the build exists
- sat.prepare(appli + " -p " + product_name)
- sat.configure(appli + " -p " + product_name)
-
- # Call the command
- sat.clean(appli + " -p " + product_name + " --build", batch=True)
-
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
-
- if not os.path.exists(expected_build_dir):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the clean of install
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- # Make sure the build exists
- sat.prepare(appli + " -p " + product_name)
- sat.configure(appli + " -p " + product_name)
-
- # Call the command
- sat.clean(appli + " -p " + product_name + " --install", batch=True)
-
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
-
- if not os.path.exists(expected_install_dir):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the clean of all (build, src, install)
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
-
- # Make sure the build exists
- sat.prepare(appli + " -p " + product_name)
- sat.compile(appli + " -p " + product_name)
-
- # Call the command
- sat.clean(appli + " -p " + product_name + " --all", batch=True)
-
- expected_install_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
- expected_build_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).build_dir
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
-
- if (
- not os.path.exists(expected_install_dir)
- and not os.path.exists(expected_build_dir)
- and not os.path.exists(expected_src_dir)
- ):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test the clean with sources_without_dev option
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
- product_name2 = "PRODUCT_DEV"
-
- sat = Sat()
-
- # Make sure the build exists
- sat.prepare(appli + " -p " + product_name + "," + product_name2)
-
- # Call the command
- sat.clean(appli + " -p " + product_name + " --sources_without_dev", batch=True)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_src_dir2 = src.product.get_product_config(
- sat.cfg, product_name2
- ).source_dir
-
- if not os.path.exists(expected_src_dir) and os.path.exists(expected_src_dir2):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_070(self):
- # Test the sat -h clean
- OK = "KO"
-
- import clean
-
- if (
- "The clean command suppress the source, build, or install"
- in clean.description()
- ):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import shutil
-import unittest
-
-from src.salomeTools import Sat
-import src.product
-from unittestpy.tools import outRedirection
-
-
-class TestCase(unittest.TestCase):
- """Test of the patch command"""
-
- def test_010(self):
- # Test the patch command with a product in dev mode
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_DEV"
-
- sat = Sat("-oUSER.output_level=2")
-
- sat.config(appli)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_file_path = os.path.join(expected_src_dir, "my_test_file.txt")
- expected_text = "HELLO WORLD\n"
-
- if os.path.exists(expected_src_dir):
- shutil.rmtree(expected_src_dir)
-
- sat.source(appli + " --product " + product_name)
-
- f = open(expected_file_path, "r")
- text = f.readlines()[0]
- OK1 = "KO"
- if text == expected_text:
- OK1 = "OK"
-
- sat.patch(appli + " --product " + product_name)
-
- new_expected_text = "HELLO WORLD MODIFIED\n"
- f = open(expected_file_path, "r")
- text = f.readlines()[0]
-
- OK2 = "KO"
- if text == new_expected_text:
- OK2 = "OK"
-
- if (OK1, OK2) == ("OK", "OK"):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the patch command with a product with no sources found
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_DEV"
-
- sat = Sat("")
- sat.config(appli)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
-
- if os.path.exists(expected_src_dir):
- shutil.rmtree(expected_src_dir)
-
- # output redirection
- my_out = outRedirection()
-
- sat.patch(appli + " --product " + product_name)
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "No sources found for the " + product_name + " product" in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the patch command with a product without patch
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_ARCHIVE"
-
- sat = Sat("-v4")
-
- sat.source(appli + " --product " + product_name)
-
- # output redirection
- my_out = outRedirection()
-
- sat.patch(appli + " --product " + product_name)
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "No patch for the " + product_name + " product" in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the patch command with a product with a not valid patch
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_DEV"
-
- sat = Sat("-oPRODUCTS.PRODUCT_DEV.default.patches=['/']")
-
- sat.source(appli + " --product " + product_name)
-
- # output redirection
- my_out = outRedirection()
-
- sat.patch(appli + " --product " + product_name)
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "Not a valid patch" in res:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_050(self):
- # Test the sat -h patch
- OK = "KO"
-
- import patch
-
- if (
- "The patch command apply the patches on the sources of"
- in patch.description()
- ):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import shutil
-import unittest
-
-import src
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test of the prepare command"""
-
- def test_010(self):
- # Test the prepare command with a product in dev mode
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_DEV"
-
- sat = Sat()
-
- sat.config(appli)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_file_path = os.path.join(expected_src_dir, "my_test_file.txt")
- expected_text = "HELLO WORLD\n"
-
- if os.path.exists(expected_src_dir):
- shutil.rmtree(expected_src_dir)
-
- sat.prepare(appli + " --product " + product_name)
-
- f = open(expected_file_path, "r")
- text = f.readlines()[0]
- if text == expected_text:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the prepare command with all products
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_DEV"
-
- sat = Sat()
- sat.config(appli)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_file_path = os.path.join(expected_src_dir, "my_test_file.txt")
- expected_text = "HELLO WORLD\n"
-
- if os.path.exists(expected_src_dir):
- shutil.rmtree(expected_src_dir)
-
- sat.prepare(appli)
-
- f = open(expected_file_path, "r")
- text = f.readlines()[0]
- if text == expected_text:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the prepare command with all products
- OK = "KO"
-
- appli = "appli-test"
-
- sat = Sat()
- sat.config(appli)
-
- try:
- sat.prepare(appli + " --force --force_patch")
- OK = "OK"
- except:
- pass
- self.assertEqual(OK, "OK")
-
- def test_040(self):
- # Test the sat -h prepare
- OK = "KO"
-
- import prepare
-
- if "The prepare command gets the sources" in prepare.description():
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-import src.product
-from unittestpy.tools import outRedirection
-
-
-class TestCase(unittest.TestCase):
- """Test of the source command"""
-
- def test_010(self):
- # Test the source command with archive product
- appli = "appli-test"
- product_name = "PRODUCT_ARCHIVE"
-
- sat = Sat()
- sat.source(appli + " --product " + product_name)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_file_path = os.path.join(expected_src_dir, "my_test_file.txt")
- expected_text = "HELLO WORLD\n"
-
- f = open(expected_file_path, "r")
- text = f.read()
- self.assertEqual(text, expected_text)
-
- def test_020(self):
- # Test the source command with git product
- appli = "appli-test"
- product_name = "PRODUCT_GIT"
-
- sat = Sat()
- sat.source(appli + " --product " + product_name)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_file_path = os.path.join(expected_src_dir, "my_test_file.txt")
- expected_text = "HELLO WORLD\n"
-
- f = open(expected_file_path, "r")
- text = f.read()
- self.assertEqual(text, expected_text)
-
- def test_030(self):
- # Test the source command with cvs product
- appli = "appli-test"
- product_name = "PRODUCT_CVS"
-
- sat = Sat()
- sat.source(appli + " --product " + product_name)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).source_dir
- expected_file_path = os.path.join(expected_src_dir, "README.FIRST.txt")
- expected_text = "Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE\n"
-
- f = open(expected_file_path, "r")
- text = f.readlines()[0]
-
- # pyunit method to compare 2 str
- self.assertEqual(text, expected_text)
-
- """
- def test_040(self):
- # Test the source command with svn product
- OK = 'KO'
-
- appli = 'appli-test'
- product_name = 'PRODUCT_SVN'
-
- sat = Sat()
- sat.source(appli + ' --product ' + product_name)
-
- expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
- expected_file_path = os.path.join(expected_src_dir, 'scripts', 'README')
- expected_text = 'this directory contains scripts used by salomeTool'
-
- f = open(expected_file_path, 'r')
- text = f.readlines()[0]
-
- if expected_text in text:
- OK = 'OK'
-
- # pyunit method to compare 2 str
- self.assertEqual(OK, 'OK')
- """
-
- def test_050(self):
- # Test the source command with native product
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_NATIVE"
-
- sat = Sat()
- sat.source(appli + " --product " + product_name)
-
- expected_src_dir = os.path.join(
- sat.cfg.APPLICATION.workdir, "SOURCES", product_name
- )
- if not os.path.exists(expected_src_dir):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_060(self):
- # Test the source command with fixed product
- OK = "KO"
-
- appli = "appli-test"
- product_name = "PRODUCT_FIXED"
-
- sat = Sat()
- sat.source(appli + " --product " + product_name)
-
- expected_src_dir = src.product.get_product_config(
- sat.cfg, product_name
- ).install_dir
-
- if os.path.exists(expected_src_dir):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- """
- def test_070(self):
- # Test the source command with unknown product
- OK = 'KO'
-
- # output redirection
- my_out = outRedirection()
-
- appli = 'appli-test'
- product_name = 'PRODUCT_UNKNOWN'
-
- sat = Sat()
- sat.source(appli + ' --product ' + product_name)
-
- # stop output redirection
- my_out.end_redirection()
-
- # get results
- res = my_out.read_results()
-
- if "Unknown get source method" in res:
- OK = 'OK'
- self.assertEqual(OK, 'OK')
- """
-
- def test_080(self):
- # Test the sat -h source
- OK = "KO"
-
- import source
-
- if "gets the sources of the application" in source.description():
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env bash
-#-*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-echo "TODO: SAT5.1 OBSOLETE: to set as python script, may be"
-echo "Begin date:"
-date
-echo
-echo "Remove old results ... "
-rm -rf .coverage htmlcov
-echo "Done"
-echo
-echo "****************************"
-coverage run --source=../commands/config.py config/option_value.py > test_res.html
-coverage run --source=../commands/config.py -a config/option_value_2.py >> test_res.html
-coverage run --source=../commands/config.py -a config/create_user_pyconf.py >> test_res.html
-coverage run --source=../commands/config.py -a config/option_copy.py >> test_res.html
-coverage run --source=../commands/config.py -a config/option_edit.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager.py,../src/logger.py -a log/launch_browser.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager.py,../src/logger.py -a log/launch_browser2.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py -a prepare/test_source.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py -a prepare/test_patch.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py -a prepare/test_prepare.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../commands/clean.py -a prepare/test_clean.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/environ.py -a environ/test_environ.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/configure.py,../commands/environ.py -a compilation/test_configure.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/make.py,../commands/environ.py -a compilation/test_make.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/makeinstall.py,../commands/environ.py -a compilation/test_makeinstall.py >> test_res.html
-coverage run --source=../commands/config.py,../commands/compile.py,../commands/configure.py,../commands/make.py,../commands/makeinstall.py,../commands/environ.py -a compilation/test_compilation.py >> test_res.html
-coverage run --source=../commands/shell.py -a shell/test_shell.py >> test_res.html
-coverage run --source=../commands/job.py -a job/test_job.py >> test_res.html
-coverage run --source=../commands/jobs.py -a jobs/test_jobs.py >> test_res.html
-coverage run --source=../commands/test.py,../src/test_module.py,../src/fork.py -a test/test_command.py >> test_res.html
-echo "****************************"
-echo
-echo "building html coverage"
-coverage html
-echo "Done"
-echo
-echo "End date:"
-date
-echo
-
-#firefox test_res.html htmlcov/index.html
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-
-
-class TestCase(unittest.TestCase):
- """Test of the shell command"""
-
- def test_010(self):
- # Test the shell command with the --command option
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- sat.config()
- sat_way = sat.cfg.VARS.salometoolsway
-
- # Execute the shell command
- sat.shell("--command ls " + sat_way)
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_files = [line.replace("\n", "") for line in log_files]
-
- text = open(log_files[2], "r").read()
-
- if "salomeTools.py" in text:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the shell command with the --command option with a failing command
- OK = "KO"
- tmp_file = "/tmp/test.txt"
-
- sat = Sat("-l " + tmp_file)
-
- sat.config()
-
- # Execute the shell command
- res = sat.shell("--command i_fail")
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_files = [line.replace("\n", "") for line in log_files]
-
- text = open(log_files[2], "r").read()
-
- if "i_fail" in text and res == 1:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the sat -h shell
- OK = "KO"
-
- import shell
-
- if "Executes the shell command passed as argument" in shell.description():
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding:utf-8 -*-
-
-# Copyright (C) 2010-2018 CEA/DEN
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-import os
-import unittest
-
-from src.salomeTools import Sat
-
-
-class TestTest(unittest.TestCase):
- """Test of the test command"""
-
- def test_010(self):
- # Test the test command
- OK = "KO"
- tmp_file = "/tmp/test.txt"
- application = "SALOME-7.8.0"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- sat.test(application + " --grid GEOM --session light")
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_testboard = [
- line.replace("\n", "") for line in log_files if "testboard.xml" in line
- ]
-
- text = open(log_testboard[0], "r").read()
-
- if '<session name="light">' in text:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_020(self):
- # Test the test command with PY type
- OK = "KO"
- tmp_file = "/tmp/test.txt"
- application = "SALOME-7.8.0"
-
- sat = Sat("-l " + tmp_file)
-
- # Execute the job command
- sat.test(application + " --grid MED --session PY_test_withKernel")
-
- ff = open(tmp_file, "r")
- log_files = ff.readlines()
- ff.close()
- os.remove(tmp_file)
- log_testboard = [
- line.replace("\n", "") for line in log_files if "testboard.xml" in line
- ]
-
- text = open(log_testboard[0], "r").read()
-
- if '<session name="PY_test_withKernel">' in text:
- OK = "OK"
- self.assertEqual(OK, "OK")
-
- def test_030(self):
- # Test the sat -h test
- OK = "KO"
-
- import test
-
- if (
- "The test command runs a test base on a SALOME installation"
- in test.description()
- ):
- OK = "OK"
- self.assertEqual(OK, "OK")
-
-
-# test launch
-if __name__ == "__main__":
- unittest.main()
+++ /dev/null
-"""
-A TestRunner for use with the Python unit testing framework. It
-generates a HTML report to show the result at a glance.
-
-The simplest way to use this is to invoke its main method. E.g.
-
- import unittest
- import HTMLTestRunner
-
- ... define your tests ...
-
- if __name__ == '__main__':
- HTMLTestRunner.main()
-
-
-For more customization options, instantiates a HTMLTestRunner object.
-HTMLTestRunner is a counterpart to unittest's TextTestRunner. E.g.
-
- # output to a file
- fp = file('my_report.html', 'wb')
- runner = HTMLTestRunner.HTMLTestRunner(
- stream=fp,
- title='My unit test',
- description='This demonstrates the report output by HTMLTestRunner.'
- )
-
- # Use an external stylesheet.
- # See the Template_mixin class for more customizable options
- runner.STYLESHEET_TMPL = '<link rel="stylesheet" href="my_stylesheet.css" type="text/css">'
-
- # run the test
- runner.run(my_test_suite)
-
-
-------------------------------------------------------------------------
-Copyright (c) 2004-2007, Wai Yip Tung
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-* Neither the name Wai Yip Tung nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
-IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
-PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
-OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-"""
-
-# URL: http://tungwaiyip.info/software/HTMLTestRunner.html
-
-__author__ = "Wai Yip Tung"
-__version__ = "0.8.2"
-
-
-"""
-Change History
-
-Version 0.8.2
-* Show output inline instead of popup window (Viorel Lupu).
-
-Version in 0.8.1
-* Validated XHTML (Wolfgang Borgert).
-* Added description of test classes and test cases.
-
-Version in 0.8.0
-* Define Template_mixin class for customization.
-* Workaround a IE 6 bug that it does not treat <script> block as CDATA.
-
-Version in 0.7.1
-* Back port to Python 2.3 (Frank Horowitz).
-* Fix missing scroll bars in detail log (Podi).
-"""
-
-# TODO: color stderr
-# TODO: simplify javascript using ,ore than 1 class in the class attribute?
-
-import datetime
-import StringIO
-import sys
-import time
-import unittest
-from xml.sax import saxutils
-
-
-# ------------------------------------------------------------------------
-# The redirectors below are used to capture output during testing. Output
-# sent to sys.stdout and sys.stderr are automatically captured. However
-# in some cases sys.stdout is already cached before HTMLTestRunner is
-# invoked (e.g. calling logging.basicConfig). In order to capture those
-# output, use the redirectors for the cached stream.
-#
-# e.g.
-# >>> logging.basicConfig(stream=HTMLTestRunner.stdout_redirector)
-# >>>
-
-class OutputRedirector(object):
- """ Wrapper to redirect stdout or stderr """
- def __init__(self, fp):
- self.fp = fp
-
- def write(self, s):
- self.fp.write(s)
-
- def writelines(self, lines):
- self.fp.writelines(lines)
-
- def flush(self):
- self.fp.flush()
-
-stdout_redirector = OutputRedirector(sys.stdout)
-stderr_redirector = OutputRedirector(sys.stderr)
-
-
-
-# ----------------------------------------------------------------------
-# Template
-
-class Template_mixin(object):
- """
- Define a HTML template for report customerization and generation.
-
- Overall structure of an HTML report
-
- HTML
- +------------------------+
- |<html> |
- | <head> |
- | |
- | STYLESHEET |
- | +----------------+ |
- | | | |
- | +----------------+ |
- | |
- | </head> |
- | |
- | <body> |
- | |
- | HEADING |
- | +----------------+ |
- | | | |
- | +----------------+ |
- | |
- | REPORT |
- | +----------------+ |
- | | | |
- | +----------------+ |
- | |
- | ENDING |
- | +----------------+ |
- | | | |
- | +----------------+ |
- | |
- | </body> |
- |</html> |
- +------------------------+
- """
-
- STATUS = {
- 0: 'pass',
- 1: 'fail',
- 2: 'error',
- }
-
- DEFAULT_TITLE = 'Unit Test Report'
- DEFAULT_DESCRIPTION = ''
-
- # ------------------------------------------------------------------------
- # HTML Template
-
- HTML_TMPL = r"""<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
- <title>%(title)s</title>
- <meta name="generator" content="%(generator)s"/>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
- %(stylesheet)s
-</head>
-<body>
-<script language="javascript" type="text/javascript"><!--
-output_list = Array();
-
-/* level - 0:Summary; 1:Failed; 2:All */
-function showCase(level) {
- trs = document.getElementsByTagName("tr");
- for (var i = 0; i < trs.length; i++) {
- tr = trs[i];
- id = tr.id;
- if (id.substr(0,2) == 'ft') {
- if (level < 1) {
- tr.className = 'hiddenRow';
- }
- else {
- tr.className = '';
- }
- }
- if (id.substr(0,2) == 'pt') {
- if (level > 1) {
- tr.className = '';
- }
- else {
- tr.className = 'hiddenRow';
- }
- }
- }
-}
-
-
-function showClassDetail(cid, count) {
- var id_list = Array(count);
- var toHide = 1;
- for (var i = 0; i < count; i++) {
- tid0 = 't' + cid.substr(1) + '.' + (i+1);
- tid = 'f' + tid0;
- tr = document.getElementById(tid);
- if (!tr) {
- tid = 'p' + tid0;
- tr = document.getElementById(tid);
- }
- id_list[i] = tid;
- if (tr.className) {
- toHide = 0;
- }
- }
- for (var i = 0; i < count; i++) {
- tid = id_list[i];
- if (toHide) {
- document.getElementById('div_'+tid).style.display = 'none'
- document.getElementById(tid).className = 'hiddenRow';
- }
- else {
- document.getElementById(tid).className = '';
- }
- }
-}
-
-
-function showTestDetail(div_id){
- var details_div = document.getElementById(div_id)
- var displayState = details_div.style.display
- // alert(displayState)
- if (displayState != 'block' ) {
- displayState = 'block'
- details_div.style.display = 'block'
- }
- else {
- details_div.style.display = 'none'
- }
-}
-
-
-function html_escape(s) {
- s = s.replace(/&/g,'&');
- s = s.replace(/</g,'<');
- s = s.replace(/>/g,'>');
- return s;
-}
-
-/* obsoleted by detail in <div>
-function showOutput(id, name) {
- var w = window.open("", //url
- name,
- "resizable,scrollbars,status,width=800,height=450");
- d = w.document;
- d.write("<pre>");
- d.write(html_escape(output_list[id]));
- d.write("\n");
- d.write("<a href='javascript:window.close()'>close</a>\n");
- d.write("</pre>\n");
- d.close();
-}
-*/
---></script>
-
-%(heading)s
-%(report)s
-%(ending)s
-
-</body>
-</html>
-"""
- # variables: (title, generator, stylesheet, heading, report, ending)
-
-
- # ------------------------------------------------------------------------
- # Stylesheet
- #
- # alternatively use a <link> for external style sheet, e.g.
- # <link rel="stylesheet" href="$url" type="text/css">
-
- STYLESHEET_TMPL = """
-<style type="text/css" media="screen">
-body { font-family: verdana, arial, helvetica, sans-serif; font-size: 80%; }
-table { font-size: 100%; }
-pre { }
-
-/* -- heading ---------------------------------------------------------------------- */
-h1 {
- font-size: 16pt;
- color: gray;
-}
-.heading {
- margin-top: 0ex;
- margin-bottom: 1ex;
-}
-
-.heading .attribute {
- margin-top: 1ex;
- margin-bottom: 0;
-}
-
-.heading .description {
- margin-top: 4ex;
- margin-bottom: 6ex;
-}
-
-/* -- css div popup ------------------------------------------------------------------------ */
-a.popup_link {
-}
-
-a.popup_link:hover {
- color: red;
-}
-
-.popup_window {
- display: none;
- position: relative;
- left: 0px;
- top: 0px;
- /*border: solid #627173 1px; */
- padding: 10px;
- background-color: #E6E6D6;
- font-family: "Lucida Console", "Courier New", Courier, monospace;
- text-align: left;
- font-size: 8pt;
- width: 500px;
-}
-
-}
-/* -- report ------------------------------------------------------------------------ */
-#show_detail_line {
- margin-top: 3ex;
- margin-bottom: 1ex;
-}
-#result_table {
- width: 80%;
- border-collapse: collapse;
- border: 1px solid #777;
-}
-#header_row {
- font-weight: bold;
- color: white;
- background-color: #777;
-}
-#result_table td {
- border: 1px solid #777;
- padding: 2px;
-}
-#total_row { font-weight: bold; }
-.passClass { background-color: #6c6; }
-.failClass { background-color: #c60; }
-.errorClass { background-color: #c00; }
-.passCase { color: #6c6; }
-.failCase { color: #c60; font-weight: bold; }
-.errorCase { color: #c00; font-weight: bold; }
-.hiddenRow { display: none; }
-.testcase { margin-left: 2em; }
-
-
-/* -- ending ---------------------------------------------------------------------- */
-#ending {
-}
-
-</style>
-"""
-
-
-
- # ------------------------------------------------------------------------
- # Heading
- #
-
- HEADING_TMPL = """<div class='heading'>
-<h1>%(title)s</h1>
-%(parameters)s
-<p class='description'>%(description)s</p>
-</div>
-
-""" # variables: (title, parameters, description)
-
- HEADING_ATTRIBUTE_TMPL = """<p class='attribute'><strong>%(name)s:</strong> %(value)s</p>
-""" # variables: (name, value)
-
-
-
- # ------------------------------------------------------------------------
- # Report
- #
-
- REPORT_TMPL = """
-<p id='show_detail_line'>Show
-<a href='javascript:showCase(0)'>Summary</a>
-<a href='javascript:showCase(1)'>Failed</a>
-<a href='javascript:showCase(2)'>All</a>
-</p>
-<table id='result_table'>
-<colgroup>
-<col align='left' />
-<col align='right' />
-<col align='right' />
-<col align='right' />
-<col align='right' />
-<col align='right' />
-</colgroup>
-<tr id='header_row'>
- <td>Test Group/Test case</td>
- <td>Count</td>
- <td>Pass</td>
- <td>Fail</td>
- <td>Error</td>
- <td>View</td>
-</tr>
-%(test_list)s
-<tr id='total_row'>
- <td>Total</td>
- <td>%(count)s</td>
- <td>%(Pass)s</td>
- <td>%(fail)s</td>
- <td>%(error)s</td>
- <td> </td>
-</tr>
-</table>
-""" # variables: (test_list, count, Pass, fail, error)
-
- REPORT_CLASS_TMPL = r"""
-<tr class='%(style)s'>
- <td>%(desc)s</td>
- <td>%(count)s</td>
- <td>%(Pass)s</td>
- <td>%(fail)s</td>
- <td>%(error)s</td>
- <td><a href="javascript:showClassDetail('%(cid)s',%(count)s)">Detail</a></td>
-</tr>
-""" # variables: (style, desc, count, Pass, fail, error, cid)
-
-
- REPORT_TEST_WITH_OUTPUT_TMPL = r"""
-<tr id='%(tid)s' class='%(Class)s'>
- <td class='%(style)s'><div class='testcase'>%(desc)s</div></td>
- <td colspan='5' align='center'>
-
- <!--css div popup start-->
- <a class="popup_link" onfocus='this.blur();' href="javascript:showTestDetail('div_%(tid)s')" >
- %(status)s</a>
-
- <div id='div_%(tid)s' class="popup_window">
- <div style='text-align: right; color:red;cursor:pointer'>
- <a onfocus='this.blur();' onclick="document.getElementById('div_%(tid)s').style.display = 'none' " >
- [x]</a>
- </div>
- <pre>
- %(script)s
- </pre>
- </div>
- <!--css div popup end-->
-
- </td>
-</tr>
-""" # variables: (tid, Class, style, desc, status)
-
-
- REPORT_TEST_NO_OUTPUT_TMPL = r"""
-<tr id='%(tid)s' class='%(Class)s'>
- <td class='%(style)s'><div class='testcase'>%(desc)s</div></td>
- <td colspan='5' align='center'>%(status)s</td>
-</tr>
-""" # variables: (tid, Class, style, desc, status)
-
-
- REPORT_TEST_OUTPUT_TMPL = r"""
-%(id)s: %(output)s
-""" # variables: (id, output)
-
-
-
- # ------------------------------------------------------------------------
- # ENDING
- #
-
- ENDING_TMPL = """<div id='ending'> </div>"""
-
-# -------------------- The end of the Template class -------------------
-
-
-TestResult = unittest.TestResult
-
-class _TestResult(TestResult):
- # note: _TestResult is a pure representation of results.
- # It lacks the output and reporting ability compares to unittest._TextTestResult.
-
- def __init__(self, verbosity=1):
- TestResult.__init__(self)
- self.stdout0 = None
- self.stderr0 = None
- self.success_count = 0
- self.failure_count = 0
- self.error_count = 0
- self.verbosity = verbosity
-
- # result is a list of result in 4 tuple
- # (
- # result code (0: success; 1: fail; 2: error),
- # TestCase object,
- # Test output (byte string),
- # stack trace,
- # )
- self.result = []
-
-
- def startTest(self, test):
- TestResult.startTest(self, test)
- # just one buffer for both stdout and stderr
- self.outputBuffer = StringIO.StringIO()
- stdout_redirector.fp = self.outputBuffer
- stderr_redirector.fp = self.outputBuffer
- self.stdout0 = sys.stdout
- self.stderr0 = sys.stderr
- sys.stdout = stdout_redirector
- sys.stderr = stderr_redirector
-
-
- def complete_output(self):
- """
- Disconnect output redirection and return buffer.
- Safe to call multiple times.
- """
- if self.stdout0:
- sys.stdout = self.stdout0
- sys.stderr = self.stderr0
- self.stdout0 = None
- self.stderr0 = None
- return self.outputBuffer.getvalue()
-
-
- def stopTest(self, test):
- # Usually one of addSuccess, addError or addFailure would have been called.
- # But there are some path in unittest that would bypass this.
- # We must disconnect stdout in stopTest(), which is guaranteed to be called.
- self.complete_output()
-
-
- def addSuccess(self, test):
- self.success_count += 1
- TestResult.addSuccess(self, test)
- output = self.complete_output()
- self.result.append((0, test, output, ''))
- if self.verbosity > 1:
- sys.stderr.write('ok ')
- sys.stderr.write(str(test))
- sys.stderr.write('\n')
- else:
- sys.stderr.write('.')
-
- def addError(self, test, err):
- self.error_count += 1
- TestResult.addError(self, test, err)
- _, _exc_str = self.errors[-1]
- output = self.complete_output()
- self.result.append((2, test, output, _exc_str))
- if self.verbosity > 1:
- sys.stderr.write('E ')
- sys.stderr.write(str(test))
- sys.stderr.write('\n')
- else:
- sys.stderr.write('E')
-
- def addFailure(self, test, err):
- self.failure_count += 1
- TestResult.addFailure(self, test, err)
- _, _exc_str = self.failures[-1]
- output = self.complete_output()
- self.result.append((1, test, output, _exc_str))
- if self.verbosity > 1:
- sys.stderr.write('F ')
- sys.stderr.write(str(test))
- sys.stderr.write('\n')
- else:
- sys.stderr.write('F')
-
-
-class HTMLTestRunner(Template_mixin):
- """
- """
- def __init__(self, stream=sys.stdout, verbosity=1, title=None, description=None):
- self.stream = stream
- self.verbosity = verbosity
- if title is None:
- self.title = self.DEFAULT_TITLE
- else:
- self.title = title
- if description is None:
- self.description = self.DEFAULT_DESCRIPTION
- else:
- self.description = description
-
- self.startTime = datetime.datetime.now()
-
-
- def run(self, test):
- "Run the given test case or test suite."
- result = _TestResult(self.verbosity)
- test(result)
- self.stopTime = datetime.datetime.now()
- self.generateReport(test, result)
- print >>sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)
- return result
-
-
- def sortResult(self, result_list):
- # unittest does not seems to run in any particular order.
- # Here at least we want to group them together by class.
- rmap = {}
- classes = []
- for n,t,o,e in result_list:
- cls = t.__class__
- if not cls in rmap:
- rmap[cls] = []
- classes.append(cls)
- rmap[cls].append((n,t,o,e))
- r = [(cls, rmap[cls]) for cls in classes]
- return r
-
-
- def getReportAttributes(self, result):
- """
- Return report attributes as a list of (name, value).
- Override this to add custom attributes.
- """
- startTime = str(self.startTime)[:19]
- duration = str(self.stopTime - self.startTime)
- status = []
- if result.success_count: status.append('Pass %s' % result.success_count)
- if result.failure_count: status.append('Failure %s' % result.failure_count)
- if result.error_count: status.append('Error %s' % result.error_count )
- if status:
- status = ' '.join(status)
- else:
- status = 'none'
- return [
- ('Start Time', startTime),
- ('Duration', duration),
- ('Status', status),
- ]
-
-
- def generateReport(self, test, result):
- report_attrs = self.getReportAttributes(result)
- generator = 'HTMLTestRunner %s' % __version__
- stylesheet = self._generate_stylesheet()
- heading = self._generate_heading(report_attrs)
- report = self._generate_report(result)
- ending = self._generate_ending()
- output = self.HTML_TMPL % dict(
- title = saxutils.escape(self.title),
- generator = generator,
- stylesheet = stylesheet,
- heading = heading,
- report = report,
- ending = ending,
- )
- self.stream.write(output.encode('utf8'))
-
-
- def _generate_stylesheet(self):
- return self.STYLESHEET_TMPL
-
-
- def _generate_heading(self, report_attrs):
- a_lines = []
- for name, value in report_attrs:
- line = self.HEADING_ATTRIBUTE_TMPL % dict(
- name = saxutils.escape(name),
- value = saxutils.escape(value),
- )
- a_lines.append(line)
- heading = self.HEADING_TMPL % dict(
- title = saxutils.escape(self.title),
- parameters = ''.join(a_lines),
- description = saxutils.escape(self.description),
- )
- return heading
-
-
- def _generate_report(self, result):
- rows = []
- sortedResult = self.sortResult(result.result)
- for cid, (cls, cls_results) in enumerate(sortedResult):
- # subtotal for a class
- np = nf = ne = 0
- for n,t,o,e in cls_results:
- if n == 0: np += 1
- elif n == 1: nf += 1
- else: ne += 1
-
- # format class description
- if cls.__module__ == "__main__":
- name = cls.__name__
- else:
- name = "%s.%s" % (cls.__module__, cls.__name__)
- doc = cls.__doc__ and cls.__doc__.split("\n")[0] or ""
- desc = doc and '%s: %s' % (name, doc) or name
-
- row = self.REPORT_CLASS_TMPL % dict(
- style = ne > 0 and 'errorClass' or nf > 0 and 'failClass' or 'passClass',
- desc = desc,
- count = np+nf+ne,
- Pass = np,
- fail = nf,
- error = ne,
- cid = 'c%s' % (cid+1),
- )
- rows.append(row)
-
- for tid, (n,t,o,e) in enumerate(cls_results):
- self._generate_report_test(rows, cid, tid, n, t, o, e)
-
- report = self.REPORT_TMPL % dict(
- test_list = ''.join(rows),
- count = str(result.success_count+result.failure_count+result.error_count),
- Pass = str(result.success_count),
- fail = str(result.failure_count),
- error = str(result.error_count),
- )
- return report
-
-
- def _generate_report_test(self, rows, cid, tid, n, t, o, e):
- # e.g. 'pt1.1', 'ft1.1', etc
- has_output = bool(o or e)
- tid = (n == 0 and 'p' or 'f') + 't%s.%s' % (cid+1,tid+1)
- name = t.id().split('.')[-1]
- doc = t.shortDescription() or ""
- desc = doc and ('%s: %s' % (name, doc)) or name
- tmpl = has_output and self.REPORT_TEST_WITH_OUTPUT_TMPL or self.REPORT_TEST_NO_OUTPUT_TMPL
-
- # o and e should be byte string because they are collected from stdout and stderr?
- if isinstance(o,str):
- # TODO: some problem with 'string_escape': it escape \n and mess up formating
- # uo = unicode(o.encode('string_escape'))
- uo = o.decode('latin-1')
- else:
- uo = o
- if isinstance(e,str):
- # TODO: some problem with 'string_escape': it escape \n and mess up formating
- # ue = unicode(e.encode('string_escape'))
- ue = e.decode('latin-1')
- else:
- ue = e
-
- script = self.REPORT_TEST_OUTPUT_TMPL % dict(
- id = tid,
- output = saxutils.escape(uo+ue),
- )
-
- row = tmpl % dict(
- tid = tid,
- Class = (n == 0 and 'hiddenRow' or 'none'),
- style = n == 2 and 'errorCase' or (n == 1 and 'failCase' or 'none'),
- desc = desc,
- script = script,
- status = self.STATUS[n],
- )
- rows.append(row)
- if not has_output:
- return
-
- def _generate_ending(self):
- return self.ENDING_TMPL
-
-
-##############################################################################
-# Facilities for running tests from the command line
-##############################################################################
-
-# Note: Reuse unittest.TestProgram to launch test. In the future we may
-# build our own launcher to support more specific command line
-# parameters like test title, CSS, etc.
-class TestProgram(unittest.TestProgram):
- """
- A variation of the unittest.TestProgram. Please refer to the base
- class for command line parameters.
- """
- def runTests(self):
- # Pick HTMLTestRunner as the default test runner.
- # base class's testRunner parameter is not useful because it means
- # we have to instantiate HTMLTestRunner before we know self.verbosity.
- if self.testRunner is None:
- self.testRunner = HTMLTestRunner(verbosity=self.verbosity)
- unittest.TestProgram.runTests(self)
-
-main = TestProgram
-
-##############################################################################
-# Executing this module from the command line
-##############################################################################
-
-if __name__ == "__main__":
- main(module=None)