From d704b7600c3b40545205f60f9ef4cb3fd689ee73 Mon Sep 17 00:00:00 2001 From: Gbkng Date: Wed, 14 Feb 2024 20:05:06 +0100 Subject: [PATCH] style(test): format with black --- test/initializeTest.py | 34 +- test/test_020_debug.py | 134 +++---- test/test_021_versionMinorMajorPatch.py | 379 ++++++++++-------- test/test_024_logging.py | 185 +++++---- test/test_035_pyconf.py | 323 ++++++++------- test/test_100_satHelp.py | 234 +++++------ test/test_500_APPLI_TEST.py | 203 +++++----- test/test_501_paramiko.py | 175 ++++---- .../compilation/test_compilation.py | 293 ++++++++------ .../test_sat5_0/compilation/test_configure.py | 89 ++-- test/test_sat5_0/compilation/test_make.py | 92 +++-- .../compilation/test_makeinstall.py | 47 ++- .../config/test_create_user_pyconf.py | 45 ++- test/test_sat5_0/config/test_option_copy.py | 23 +- test/test_sat5_0/config/test_option_edit.py | 22 +- test/test_sat5_0/config/test_option_value.py | 18 +- .../test_sat5_0/config/test_option_value_2.py | 59 ++- test/test_sat5_0/environ/test_environ.py | 100 ++--- test/test_sat5_0/job/test_job.py | 72 ++-- test/test_sat5_0/jobs/test_jobs.py | 91 +++-- test/test_sat5_0/log/test_launch_browser.py | 154 +++---- test/test_sat5_0/log/test_launch_browser2.py | 10 +- test/test_sat5_0/prepare/test_clean.py | 126 +++--- test/test_sat5_0/prepare/test_patch.py | 151 +++---- test/test_sat5_0/prepare/test_prepare.py | 78 ++-- test/test_sat5_0/prepare/test_source.py | 98 +++-- test/test_sat5_0/shell/test_shell.py | 32 +- test/test_sat5_0/test/test_command.py | 45 ++- 28 files changed, 1758 insertions(+), 1554 deletions(-) diff --git a/test/initializeTest.py b/test/initializeTest.py index 14a3ff7..a54f6dd 100755 --- a/test/initializeTest.py +++ b/test/initializeTest.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -43,19 +43,23 @@ satdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # sys.stderr.write("INFO : initializeTest needs '%s' in sys.path:\n%s\n" % (satdir, PP.pformat(sys.path))) if satdir not in sys.path: - # get path to salomeTools sources FIRST as prepend - # Make the src & commands package accessible from all test code - sys.path.insert(0, satdir) - sys.stderr.write("""\ + # get path to salomeTools sources FIRST as prepend + # Make the src & commands package accessible from all test code + sys.path.insert(0, satdir) + sys.stderr.write( + """\ WARNING : sys.path not set for salomeTools, fixed for you: sys.path prepend '%s' - sys.path:\n%s\n""" % (satdir, PP.pformat(sys.path))) - # os.environ PATH is not set... - # supposedly useful only for subprocess launch from sat - # see https://docs.python.org/2/library/os.html - # On some platforms, including FreeBSD and Mac OS X, - # setting environ may cause memory leaks. - # sys.stderr.write("os.environ PATH:\n%s\n" % PP.pformat(os.environ["PATH"].split(":"))) - sys.stderr.write("INFO : to fix this message type:\n 'export PYTHONPATH=%s:${PYTHONPATH}'\n" % satdir) - - + sys.path:\n%s\n""" + % (satdir, PP.pformat(sys.path)) + ) + # os.environ PATH is not set... + # supposedly useful only for subprocess launch from sat + # see https://docs.python.org/2/library/os.html + # On some platforms, including FreeBSD and Mac OS X, + # setting environ may cause memory leaks. + # sys.stderr.write("os.environ PATH:\n%s\n" % PP.pformat(os.environ["PATH"].split(":"))) + sys.stderr.write( + "INFO : to fix this message type:\n 'export PYTHONPATH=%s:${PYTHONPATH}'\n" + % satdir + ) diff --git a/test/test_020_debug.py b/test/test_020_debug.py index ead64c5..9d09ca8 100755 --- a/test/test_020_debug.py +++ b/test/test_020_debug.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -21,13 +21,13 @@ import os import sys import unittest -import initializeTest # set PATH etc for test +import initializeTest # set PATH etc for test -import src.debug as DBG # Easy print stderr (for DEBUG only) -import src.pyconf as PYF # 0.3.7 +import src.debug as DBG # Easy print stderr (for DEBUG only) +import src.pyconf as PYF # 0.3.7 _EXAMPLES = { -1 : """\ + 1: """\ messages: [ { @@ -47,84 +47,78 @@ _EXAMPLES = { } ] """, - -2 : """\ + 2: """\ aa: 111 bb: $aa + 222 """, - -3 : """\ + 3: """\ aa: Yves bb: "Herve" # avoid Hervé -> 'utf8' codec can't decode byte """, - -4 : """\ + 4: """\ aa: Yves bb: "Hervé" # avoid Hervé -> 'utf8' codec can't decode byte """, - - } class TestCase(unittest.TestCase): - "Test the debug.py""" - - def test_000(self): - # one shot setUp() for this TestCase - # DBG.push_debug(True) - # SAT.setNotLocale() # test english - return - - def test_005(self): - res = DBG.getLocalEnv() - self.assertTrue(len(res.split()) > 0) - self.assertTrue("USER :" in res) - self.assertTrue("LANG :" in res) - - def test_010(self): - inStream = DBG.InStream(_EXAMPLES[1]) - self.assertEqual(inStream.getvalue(), _EXAMPLES[1]) - cfg = PYF.Config(inStream) - self.assertEqual(len(cfg.messages), 3) - outStream = DBG.OutStream() - DBG.saveConfigStd(cfg, outStream) - res = outStream.value - DBG.write("test_010 cfg std", res) - self.assertTrue("messages :" in res) - self.assertTrue("'sys.stderr'" in res) - - def test_020(self): - inStream = DBG.InStream(_EXAMPLES[2]) - cfg = PYF.Config(inStream) - res = DBG.getStrConfigDbg(cfg) - DBG.write("test_020 cfg dbg", res) - ress = res.split("\n") - self.assertTrue(".aa" in ress[0]) - self.assertTrue(": '111'" in ress[0]) - self.assertTrue(".bb" in ress[1]) - self.assertTrue(": $aa + 222 " in ress[1]) - self.assertTrue("--> '333'" in ress[1]) - - def test_025(self): - inStream = DBG.InStream(_EXAMPLES[1]) - cfg = PYF.Config(inStream) - outStream = DBG.OutStream() - DBG.saveConfigDbg(cfg, outStream) - res = outStream.value - DBG.write("test_025 cfg dbg", res) - for i in range(len(cfg.messages)): - self.assertTrue("messages[%i].name" % i in res) - self.assertTrue("--> 'HELLO sys.stderr'" in res) + "Test the debug.py" "" + + def test_000(self): + # one shot setUp() for this TestCase + # DBG.push_debug(True) + # SAT.setNotLocale() # test english + return + + def test_005(self): + res = DBG.getLocalEnv() + self.assertTrue(len(res.split()) > 0) + self.assertTrue("USER :" in res) + self.assertTrue("LANG :" in res) - - def test_999(self): - # one shot tearDown() for this TestCase - # SAT.setLocale() # end test english - # DBG.pop_debug() - return - -if __name__ == '__main__': + def test_010(self): + inStream = DBG.InStream(_EXAMPLES[1]) + self.assertEqual(inStream.getvalue(), _EXAMPLES[1]) + cfg = PYF.Config(inStream) + self.assertEqual(len(cfg.messages), 3) + outStream = DBG.OutStream() + DBG.saveConfigStd(cfg, outStream) + res = outStream.value + DBG.write("test_010 cfg std", res) + self.assertTrue("messages :" in res) + self.assertTrue("'sys.stderr'" in res) + + def test_020(self): + inStream = DBG.InStream(_EXAMPLES[2]) + cfg = PYF.Config(inStream) + res = DBG.getStrConfigDbg(cfg) + DBG.write("test_020 cfg dbg", res) + ress = res.split("\n") + self.assertTrue(".aa" in ress[0]) + self.assertTrue(": '111'" in ress[0]) + self.assertTrue(".bb" in ress[1]) + self.assertTrue(": $aa + 222 " in ress[1]) + self.assertTrue("--> '333'" in ress[1]) + + def test_025(self): + inStream = DBG.InStream(_EXAMPLES[1]) + cfg = PYF.Config(inStream) + outStream = DBG.OutStream() + DBG.saveConfigDbg(cfg, outStream) + res = outStream.value + DBG.write("test_025 cfg dbg", res) + for i in range(len(cfg.messages)): + self.assertTrue("messages[%i].name" % i in res) + self.assertTrue("--> 'HELLO sys.stderr'" in res) + + def test_999(self): + # one shot tearDown() for this TestCase + # SAT.setLocale() # end test english + # DBG.pop_debug() + return + + +if __name__ == "__main__": unittest.main(exit=False) pass - diff --git a/test/test_021_versionMinorMajorPatch.py b/test/test_021_versionMinorMajorPatch.py index b4953f4..0da8c69 100755 --- a/test/test_021_versionMinorMajorPatch.py +++ b/test/test_021_versionMinorMajorPatch.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -35,191 +35,224 @@ import sys import unittest import pprint as PP -import initializeTest # set PATH etc for test +import initializeTest # set PATH etc for test import src.versionMinorMajorPatch as VMMP -verbose = False # True +verbose = False # True + class TestCase(unittest.TestCase): - "Test the versionMajorMinorPatch.py""" - - def test_010(self): - if verbose: print(PP.pformat(dir(self))) - self.assertTrue(VMMP.only_numbers("") is None) - self.assertEqual(VMMP.only_numbers("1.2.3"), "123") - self.assertEqual(VMMP.only_numbers("\n11.12.13\n"), "111213") - self.assertEqual(VMMP.only_numbers(" \n 11.\t\n\t..12.13-rc2\n"), "1112132") - - def test_015(self): - res = "a_b_c" - self.assertEqual(VMMP.remove_startswith("version_a_b_c", "version_".split()), res) - self.assertEqual(VMMP.remove_startswith("v_a_b_c", "version_ v_".split()), res) - self.assertEqual(VMMP.remove_startswith("va_b_c", "version_ v_ v".split()), res) - - ini = "version_a_b_c" - self.assertEqual(VMMP.remove_startswith(ini, "V".split()), ini) - self.assertEqual(VMMP.remove_startswith(ini, "_".split()), ini) - self.assertEqual(VMMP.remove_startswith(ini, "a_b_c".split()), ini) - self.assertEqual(VMMP.remove_startswith(ini, "VERSION".split()), ini) - - - def test_020(self): - res = [11, 222, 3333] - self.assertEqual(VMMP.toList_majorMinorPatch("11.222.3333"), res) - self.assertEqual(VMMP.toList_majorMinorPatch("11_222_3333"), res) - self.assertEqual(VMMP.toList_majorMinorPatch("11.222_3333"), res) - self.assertEqual(VMMP.toList_majorMinorPatch(" 11. 222 . 3333 "), res) - self.assertEqual(VMMP.toList_majorMinorPatch("\n 11 . 222 . 3333 \n"), res) - self.assertEqual(VMMP.toList_majorMinorPatch(" \n11.\t222.\r3333\n "), res) # could be tricky - - self.assertEqual(VMMP.toList_majorMinorPatch("V11.222.3333"), res) - self.assertEqual(VMMP.toList_majorMinorPatch("Version11_222_3333"), res) - self.assertEqual(VMMP.toList_majorMinorPatch("Version_11_222_3333"), res) - - - self.assertEqual(VMMP.toList_majorMinorPatch("11"), [11, 0, 0]) - self.assertEqual(VMMP.toList_majorMinorPatch("11.0"), [11, 0, 0]) - self.assertEqual(VMMP.toList_majorMinorPatch("11.2"), [11, 2, 0]) - self.assertEqual(VMMP.toList_majorMinorPatch("\n1 . 2 \n"), [1, 2, 0]) - - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch("") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch("11.") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch("11.2.") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch("11.2.3.") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch(".11") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch("1_2_3_4") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch("_1_2_3_") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch(" \n 11...22.333-rc2\n") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch(" \n 11...22.333-rc2\n") - with self.assertRaises(Exception): VMMP.toList_majorMinorPatch(" \n 11...22.333-rc2\n") - - - def test_040(self): - MMP = VMMP.MinorMajorPatch - v = [1, 2, 3] - self.assertEqual(MMP(v).__str__(), "1.2.3") - self.assertEqual(MMP(v).__str__(sep="_"), "1_2_3") - self.assertEqual(str(MMP(v)), "1.2.3") - - self.assertEqual(MMP(v).__repr__(), "version_1_2_3") - self.assertEqual(MMP(v).__repr__(sep="."), "version_1.2.3") - - self.assertEqual(MMP(v).strSalome(), "1_2_3") - self.assertEqual(MMP(v).strClassic(), "1.2.3") - - self.assertEqual(MMP([' 123 \n', 2, 10]).strClassic(), "123.2.10") - self.assertEqual(MMP([' 123 \n', 2, 10]).strSalome(), "123_2_10") - - with self.assertRaises(Exception): MMP([-5, 2, 10]) - with self.assertRaises(Exception): MMP([5, -2, 10]) - with self.assertRaises(Exception): MMP([5, 2, -10]) - with self.assertRaises(Exception): MMP(['-123', 2, 10]) - - def test_050(self): - MMP = VMMP.MinorMajorPatch - v000 = MMP("0.0.0") - v010 = MMP("0.1.0") - v100 = MMP("1.0.0") - v101 = MMP("1.0.1") - - va = v000 - vb = MMP("0.0.0") - self.assertTrue(va == vb) - self.assertTrue(va >= vb) - self.assertTrue(va <= vb) - self.assertFalse(va != vb) - self.assertFalse(va > vb) - self.assertFalse(va < vb) - - va = v000 - vb = v010 - self.assertFalse(va == vb) - self.assertFalse(va >= vb) - self.assertTrue(va <= vb) - self.assertTrue(va != vb) - self.assertFalse(va > vb) - self.assertTrue(va < vb) - - va = v101 - vb = v100 - self.assertFalse(va == vb) - self.assertTrue(va >= vb) - self.assertFalse(va <= vb) - self.assertTrue(va != vb) - self.assertTrue(va > vb) - self.assertFalse(va < vb) - - def test_060(self): - MMP = VMMP.MinorMajorPatch - v0 = MMP("0") - v1 = MMP("1") - v2 = MMP("2") - v123 = MMP("1.2.3") - v456 = MMP("4.5.6") - - tests = """\ + "Test the versionMajorMinorPatch.py" "" + + def test_010(self): + if verbose: + print(PP.pformat(dir(self))) + self.assertTrue(VMMP.only_numbers("") is None) + self.assertEqual(VMMP.only_numbers("1.2.3"), "123") + self.assertEqual(VMMP.only_numbers("\n11.12.13\n"), "111213") + self.assertEqual(VMMP.only_numbers(" \n 11.\t\n\t..12.13-rc2\n"), "1112132") + + def test_015(self): + res = "a_b_c" + self.assertEqual( + VMMP.remove_startswith("version_a_b_c", "version_".split()), res + ) + self.assertEqual(VMMP.remove_startswith("v_a_b_c", "version_ v_".split()), res) + self.assertEqual(VMMP.remove_startswith("va_b_c", "version_ v_ v".split()), res) + + ini = "version_a_b_c" + self.assertEqual(VMMP.remove_startswith(ini, "V".split()), ini) + self.assertEqual(VMMP.remove_startswith(ini, "_".split()), ini) + self.assertEqual(VMMP.remove_startswith(ini, "a_b_c".split()), ini) + self.assertEqual(VMMP.remove_startswith(ini, "VERSION".split()), ini) + + def test_020(self): + res = [11, 222, 3333] + self.assertEqual(VMMP.toList_majorMinorPatch("11.222.3333"), res) + self.assertEqual(VMMP.toList_majorMinorPatch("11_222_3333"), res) + self.assertEqual(VMMP.toList_majorMinorPatch("11.222_3333"), res) + self.assertEqual(VMMP.toList_majorMinorPatch(" 11. 222 . 3333 "), res) + self.assertEqual( + VMMP.toList_majorMinorPatch("\n 11 . 222 . 3333 \n"), res + ) + self.assertEqual( + VMMP.toList_majorMinorPatch(" \n11.\t222.\r3333\n "), res + ) # could be tricky + + self.assertEqual(VMMP.toList_majorMinorPatch("V11.222.3333"), res) + self.assertEqual(VMMP.toList_majorMinorPatch("Version11_222_3333"), res) + self.assertEqual(VMMP.toList_majorMinorPatch("Version_11_222_3333"), res) + + self.assertEqual(VMMP.toList_majorMinorPatch("11"), [11, 0, 0]) + self.assertEqual(VMMP.toList_majorMinorPatch("11.0"), [11, 0, 0]) + self.assertEqual(VMMP.toList_majorMinorPatch("11.2"), [11, 2, 0]) + self.assertEqual(VMMP.toList_majorMinorPatch("\n1 . 2 \n"), [1, 2, 0]) + + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch("") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch("11.") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch("11.2.") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch("11.2.3.") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch(".11") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch("1_2_3_4") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch("_1_2_3_") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch(" \n 11...22.333-rc2\n") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch(" \n 11...22.333-rc2\n") + with self.assertRaises(Exception): + VMMP.toList_majorMinorPatch(" \n 11...22.333-rc2\n") + + def test_040(self): + MMP = VMMP.MinorMajorPatch + v = [1, 2, 3] + self.assertEqual(MMP(v).__str__(), "1.2.3") + self.assertEqual(MMP(v).__str__(sep="_"), "1_2_3") + self.assertEqual(str(MMP(v)), "1.2.3") + + self.assertEqual(MMP(v).__repr__(), "version_1_2_3") + self.assertEqual(MMP(v).__repr__(sep="."), "version_1.2.3") + + self.assertEqual(MMP(v).strSalome(), "1_2_3") + self.assertEqual(MMP(v).strClassic(), "1.2.3") + + self.assertEqual(MMP([" 123 \n", 2, 10]).strClassic(), "123.2.10") + self.assertEqual(MMP([" 123 \n", 2, 10]).strSalome(), "123_2_10") + + with self.assertRaises(Exception): + MMP([-5, 2, 10]) + with self.assertRaises(Exception): + MMP([5, -2, 10]) + with self.assertRaises(Exception): + MMP([5, 2, -10]) + with self.assertRaises(Exception): + MMP(["-123", 2, 10]) + + def test_050(self): + MMP = VMMP.MinorMajorPatch + v000 = MMP("0.0.0") + v010 = MMP("0.1.0") + v100 = MMP("1.0.0") + v101 = MMP("1.0.1") + + va = v000 + vb = MMP("0.0.0") + self.assertTrue(va == vb) + self.assertTrue(va >= vb) + self.assertTrue(va <= vb) + self.assertFalse(va != vb) + self.assertFalse(va > vb) + self.assertFalse(va < vb) + + va = v000 + vb = v010 + self.assertFalse(va == vb) + self.assertFalse(va >= vb) + self.assertTrue(va <= vb) + self.assertTrue(va != vb) + self.assertFalse(va > vb) + self.assertTrue(va < vb) + + va = v101 + vb = v100 + self.assertFalse(va == vb) + self.assertTrue(va >= vb) + self.assertFalse(va <= vb) + self.assertTrue(va != vb) + self.assertTrue(va > vb) + self.assertFalse(va < vb) + + def test_060(self): + MMP = VMMP.MinorMajorPatch + v0 = MMP("0") + v1 = MMP("1") + v2 = MMP("2") + v123 = MMP("1.2.3") + v456 = MMP("4.5.6") + + tests = """\ toto_from_1_to_2 _from_1.0.0_to_2.0.0 _from_1_0. 0_to_ 2.0_0 _from_V1.0.0_to_2.0.0 _from_version_1.0.0_to_2.0.0 version_1.0.0_to_2.0.0 -VERSION_1.0.0_to_2.0.0""".split("\n") - - for a in tests: - # print("test '%s'" % a) - r1, r2 = VMMP.getRange_majorMinorPatch(a) - self.assertEqual(r1, v1) - self.assertEqual(r2, v2) - - a = "toto_to_2" - r1, r2 = VMMP.getRange_majorMinorPatch(a) - self.assertEqual(r1, v0) - self.assertEqual(r2, v2) - - a = "toto_to_Version2" - r1, r2 = VMMP.getRange_majorMinorPatch(a) - self.assertEqual(r1, v0) - self.assertEqual(r2, v2) - - a = "toto_from_1.2.3_to_Version4_5_6" - r1, r2 = VMMP.getRange_majorMinorPatch(a) - self.assertEqual(r1, v123) - self.assertEqual(r2, v456) - - a = "toto_from_1.2.3_to_Version1_2_3" - r1, r2 = VMMP.getRange_majorMinorPatch(a) - self.assertEqual(r1, v123) - self.assertEqual(r2, v123) - - # _from_ without _to_ does not matter - tests = """\ +VERSION_1.0.0_to_2.0.0""".split( + "\n" + ) + + for a in tests: + # print("test '%s'" % a) + r1, r2 = VMMP.getRange_majorMinorPatch(a) + self.assertEqual(r1, v1) + self.assertEqual(r2, v2) + + a = "toto_to_2" + r1, r2 = VMMP.getRange_majorMinorPatch(a) + self.assertEqual(r1, v0) + self.assertEqual(r2, v2) + + a = "toto_to_Version2" + r1, r2 = VMMP.getRange_majorMinorPatch(a) + self.assertEqual(r1, v0) + self.assertEqual(r2, v2) + + a = "toto_from_1.2.3_to_Version4_5_6" + r1, r2 = VMMP.getRange_majorMinorPatch(a) + self.assertEqual(r1, v123) + self.assertEqual(r2, v456) + + a = "toto_from_1.2.3_to_Version1_2_3" + r1, r2 = VMMP.getRange_majorMinorPatch(a) + self.assertEqual(r1, v123) + self.assertEqual(r2, v123) + + # _from_ without _to_ does not matter + tests = """\ toto from to _from_ -toto_from_2""".split("\n") - - for a in tests: - rx = VMMP.getRange_majorMinorPatch(a, verbose=False) - self.assertEqual(rx, None) - - # _to_ without _from_ does not matter, as implicit _from_ '0.0.0' - # empty _to_ raise error - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_to_") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_from_to_") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_from__to_") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("toto_from__to_") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("toto_from_123_to_") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("version_123_to_") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("version_to_") - - # min > max does matter - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_from_3_to_2") - with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_from_3.2.5_to_V2_1_1") - -if __name__ == '__main__': - unittest.main(exit=False) - pass +toto_from_2""".split( + "\n" + ) + + for a in tests: + rx = VMMP.getRange_majorMinorPatch(a, verbose=False) + self.assertEqual(rx, None) + + # _to_ without _from_ does not matter, as implicit _from_ '0.0.0' + # empty _to_ raise error + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("_to_") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("_from_to_") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("_from__to_") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("toto_from__to_") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("toto_from_123_to_") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("version_123_to_") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("version_to_") + + # min > max does matter + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("_from_3_to_2") + with self.assertRaises(Exception): + VMMP.getRange_majorMinorPatch("_from_3.2.5_to_V2_1_1") + + +if __name__ == "__main__": + unittest.main(exit=False) + pass diff --git a/test/test_024_logging.py b/test/test_024_logging.py index 37e132a..3d4d0c1 100755 --- a/test/test_024_logging.py +++ b/test/test_024_logging.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -55,106 +55,105 @@ from logging.handlers import BufferingHandler import src.debug as DBG -verbose = False #True +verbose = False # True + +_TRACE = LOGI.INFO - 2 # just below info -_TRACE = LOGI.INFO - 2 # just below info class LoggerSat(LOGI.Logger): - """ - Elementary prototype for logger sat - add a level TRACE as log.trace(msg) - below log.info(msg) - above log.debug(msg) - to assume store long log asci in files txt under/outside files xml - - see: /usr/lib64/python2.7/logging/xxx__init__.py etc. - """ - - def __init__(self, name, level=LOGI.INFO): - """ - Initialize the logger with a name and an optional level. """ - super(LoggerSat, self).__init__(name, level) - LOGI.addLevelName(_TRACE, "TRACE") - # LOGI.TRACE = _TRACE # only for coherency, - - def trace(self, msg, *args, **kwargs): + Elementary prototype for logger sat + add a level TRACE as log.trace(msg) + below log.info(msg) + above log.debug(msg) + to assume store long log asci in files txt under/outside files xml + + see: /usr/lib64/python2.7/logging/xxx__init__.py etc. """ - Log 'msg % args' with severity '_TRACE'. - To pass exception information, use the keyword argument exc_info with - a true value, e.g. + def __init__(self, name, level=LOGI.INFO): + """ + Initialize the logger with a name and an optional level. + """ + super(LoggerSat, self).__init__(name, level) + LOGI.addLevelName(_TRACE, "TRACE") + # LOGI.TRACE = _TRACE # only for coherency, + + def trace(self, msg, *args, **kwargs): + """ + Log 'msg % args' with severity '_TRACE'. + + To pass exception information, use the keyword argument exc_info with + a true value, e.g. + + logger.trace("Houston, we have a %s", "long trace to follow") + """ + if self.isEnabledFor(_TRACE): + self._log(_TRACE, msg, args, **kwargs) - logger.trace("Houston, we have a %s", "long trace to follow") - """ - if self.isEnabledFor(_TRACE): - self._log(_TRACE, msg, args, **kwargs) class TestCase(unittest.TestCase): - "Test the debug.py""" - - initialLoggerClass = [] # to keep clean module logging - - def test_000(self): - # one shot setUp() for this TestCase - self.initialLoggerClass.append(LOGI._loggerClass) - LOGI.setLoggerClass(LoggerSat) - if verbose: - DBG.push_debug(True) - # DBG.write("assert unittest", [a for a in dir(self) if "assert" in a]) - pass - - def test_999(self): - # one shot tearDown() for this TestCase - if verbose: - DBG.pop_debug() - LOGI.setLoggerClass(self.initialLoggerClass[0]) - return - - def test_010(self): - # LOGI.setLoggerClass(LoggerSat) # done once in test_000 - name = "testLogging" - lgr = LOGI.getLogger(name) # create it - lgr.setLevel("DEBUG") - self.assertEqual(lgr.__class__, LoggerSat) - self.assertEqual(lgr.name, name) - self.assertIn("trace", dir(lgr)) - self.assertIn("TRACE", LOGI._levelNames.keys()) - self.assertIn(_TRACE, LOGI._levelNames.keys()) - self.assertEqual(LOGI.getLevelName(LOGI.INFO), "INFO") - self.assertEqual(LOGI.getLevelName(_TRACE), "TRACE") - - # creation d'un handler pour chaque log sur la console - formatter = LOGI.Formatter('%(levelname)-8s :: %(message)s') - # stream_handler = LOGI.handlers.StreamHandler() # log outputs in console - stream_handler = LOGI.handlers.BufferingHandler(1000) # log outputs in memory - stream_handler.setLevel(LOGI.DEBUG) - stream_handler.setFormatter(formatter) - lgr.addHandler(stream_handler) - # print # skip one line if outputs in console - lgr.warning("!!! test warning") - lgr.info("!!! test info") - lgr.trace("!!! test trace") - lgr.debug("!!! test debug") - self.assertEqual(len(stream_handler.buffer), 4) - rec = stream_handler.buffer[-1] - self.assertEqual(rec.levelname, "DEBUG") - self.assertEqual(rec.msg, "!!! test debug") - self.assertEqual(stream_handler.get_name(), None) # what to serve ? - - def test_020(self): - # LOGI.setLoggerClass(LoggerSat) - name = "testLogging" - lgr = LOGI.getLogger(name) # find it as created yet in test_010 - stream_handler = lgr.handlers[0] - rec = stream_handler.buffer[-1] - self.assertEqual(rec.levelname, "DEBUG") - self.assertEqual(rec.msg, "!!! test debug") - - - - -if __name__ == '__main__': + "Test the debug.py" "" + + initialLoggerClass = [] # to keep clean module logging + + def test_000(self): + # one shot setUp() for this TestCase + self.initialLoggerClass.append(LOGI._loggerClass) + LOGI.setLoggerClass(LoggerSat) + if verbose: + DBG.push_debug(True) + # DBG.write("assert unittest", [a for a in dir(self) if "assert" in a]) + pass + + def test_999(self): + # one shot tearDown() for this TestCase + if verbose: + DBG.pop_debug() + LOGI.setLoggerClass(self.initialLoggerClass[0]) + return + + def test_010(self): + # LOGI.setLoggerClass(LoggerSat) # done once in test_000 + name = "testLogging" + lgr = LOGI.getLogger(name) # create it + lgr.setLevel("DEBUG") + self.assertEqual(lgr.__class__, LoggerSat) + self.assertEqual(lgr.name, name) + self.assertIn("trace", dir(lgr)) + self.assertIn("TRACE", LOGI._levelNames.keys()) + self.assertIn(_TRACE, LOGI._levelNames.keys()) + self.assertEqual(LOGI.getLevelName(LOGI.INFO), "INFO") + self.assertEqual(LOGI.getLevelName(_TRACE), "TRACE") + + # creation d'un handler pour chaque log sur la console + formatter = LOGI.Formatter("%(levelname)-8s :: %(message)s") + # stream_handler = LOGI.handlers.StreamHandler() # log outputs in console + stream_handler = LOGI.handlers.BufferingHandler(1000) # log outputs in memory + stream_handler.setLevel(LOGI.DEBUG) + stream_handler.setFormatter(formatter) + lgr.addHandler(stream_handler) + # print # skip one line if outputs in console + lgr.warning("!!! test warning") + lgr.info("!!! test info") + lgr.trace("!!! test trace") + lgr.debug("!!! test debug") + self.assertEqual(len(stream_handler.buffer), 4) + rec = stream_handler.buffer[-1] + self.assertEqual(rec.levelname, "DEBUG") + self.assertEqual(rec.msg, "!!! test debug") + self.assertEqual(stream_handler.get_name(), None) # what to serve ? + + def test_020(self): + # LOGI.setLoggerClass(LoggerSat) + name = "testLogging" + lgr = LOGI.getLogger(name) # find it as created yet in test_010 + stream_handler = lgr.handlers[0] + rec = stream_handler.buffer[-1] + self.assertEqual(rec.levelname, "DEBUG") + self.assertEqual(rec.msg, "!!! test debug") + + +if __name__ == "__main__": unittest.main(exit=False) pass - diff --git a/test/test_035_pyconf.py b/test/test_035_pyconf.py index a87dc7f..a62f149 100755 --- a/test/test_035_pyconf.py +++ b/test/test_035_pyconf.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -21,13 +21,13 @@ import os import sys import unittest -import initializeTest # set PATH etc for test +import initializeTest # set PATH etc for test -import src.debug as DBG # Easy print stderr (for DEBUG only) -import src.pyconf as PYF # 0.3.7 +import src.debug as DBG # Easy print stderr (for DEBUG only) +import src.pyconf as PYF # 0.3.7 _EXAMPLES = { -1 : """\ + 1: """\ messages: [ { @@ -47,23 +47,19 @@ _EXAMPLES = { } ] """, - -2 : """\ + 2: """\ aa: 111 bb: $aa + 222 """, - -3 : """\ + 3: """\ aa: Yves bb: "Herve" # avoid Hervé -> 'utf8' codec can't decode byte """, - -4 : """\ + 4: """\ aa: Yves bb: "Hervé" # avoid Hervé -> 'utf8' codec can't decode byte """, - -5 : """\ + 5: """\ aa: Yves bb: "Herve" cc: [ @@ -79,15 +75,13 @@ _EXAMPLES = { d4 : $bb + " bye" } """, - -# error circular -6 : """\ + # error circular + 6: """\ aa: Yves bb: $cc cc: $bb """, - -7 : """\ + 7: """\ aa: Yves bb: $cc cc: [ @@ -95,8 +89,7 @@ _EXAMPLES = { $bb ] """, - -8 : """\ + 8: """\ aa: Yves bb: $cc cc: { @@ -104,163 +97,163 @@ _EXAMPLES = { cc2: $bb } """, - } class TestCase(unittest.TestCase): - "Test the pyconf.py""" - - def test_000(self): - # one shot setUp() for this TestCase - # DBG.push_debug(True) - # SAT.setNotLocale() # test english - return + "Test the pyconf.py" "" + + def test_000(self): + # one shot setUp() for this TestCase + # DBG.push_debug(True) + # SAT.setNotLocale() # test english + return - def test_010(self): - # pyconf.py doc example 0.3.7 - # https://www.red-dove.com/config-doc/ is 0.3.9 ! - # which, when run, would yield the console output: + def test_010(self): + # pyconf.py doc example 0.3.7 + # https://www.red-dove.com/config-doc/ is 0.3.9 ! + # which, when run, would yield the console output: - expected = """\ + expected = """\ Welcome, Harry Welkom, Ruud Bienvenue, Yves """ - inStream = DBG.InStream(_EXAMPLES[1]) - cfg = PYF.Config(inStream) - res = '' - for m in cfg.messages: - res += '%s, %s\n' % (m.message, m.name) - self.assertEqual(res, expected) - outStream = DBG.OutStream() - cfg.__save__(outStream) # sat renamed save() in __save__() - res = outStream.value - DBG.write("test_010 cfg", res) - self.assertTrue("name : 'Harry'" in res) - self.assertTrue("name : 'Ruud'" in res) - self.assertTrue("name : 'Yves'" in res) - - def test_020(self): - cfg = PYF.Config() - self.assertEqual(str(cfg), '{}') - self.assertEqual(cfg.__repr__(), '{}') - cfg.aa = "1111" - self.assertEqual(str(cfg), "{'aa': '1111'}") - cfg.bb = 2222 - self.assertTrue("'bb': 2222" in str(cfg)) - self.assertTrue("'aa': '1111'" in str(cfg)) - cfg.cc = 3333. - self.assertTrue("'cc': 3333." in str(cfg)) - - def test_030(self): - inStream = DBG.InStream(_EXAMPLES[2]) - cfg = PYF.Config(inStream) - self.assertEqual(str(cfg), "{'aa': 111, 'bb': $aa + 222}") - self.assertEqual(cfg.aa, 111) - self.assertEqual(cfg.bb, 333) - - def test_040(self): - inStream = DBG.InStream(_EXAMPLES[3]) - cfg = PYF.Config(inStream) - self.assertEqual(cfg.aa, "Yves") - self.assertEqual(cfg.bb, "Herve") - self.assertEqual(type(cfg.bb), str) - cfg.bb = "Hervé" # try this - self.assertEqual(type(cfg.bb), str) - self.assertEqual(cfg.bb, "Hervé") - - def test_045(self): - # make Hervé valid only with pyconf.py as 0.3.9 - inStream = DBG.InStream(_EXAMPLES[4]) - outStream = DBG.OutStream() - with self.assertRaises(Exception): - cfg = PYF.Config(inStream) + inStream = DBG.InStream(_EXAMPLES[1]) + cfg = PYF.Config(inStream) + res = "" + for m in cfg.messages: + res += "%s, %s\n" % (m.message, m.name) + self.assertEqual(res, expected) + outStream = DBG.OutStream() + cfg.__save__(outStream) # sat renamed save() in __save__() + res = outStream.value + DBG.write("test_010 cfg", res) + self.assertTrue("name : 'Harry'" in res) + self.assertTrue("name : 'Ruud'" in res) + self.assertTrue("name : 'Yves'" in res) + + def test_020(self): + cfg = PYF.Config() + self.assertEqual(str(cfg), "{}") + self.assertEqual(cfg.__repr__(), "{}") + cfg.aa = "1111" + self.assertEqual(str(cfg), "{'aa': '1111'}") + cfg.bb = 2222 + self.assertTrue("'bb': 2222" in str(cfg)) + self.assertTrue("'aa': '1111'" in str(cfg)) + cfg.cc = 3333.0 + self.assertTrue("'cc': 3333." in str(cfg)) + + def test_030(self): + inStream = DBG.InStream(_EXAMPLES[2]) + cfg = PYF.Config(inStream) + self.assertEqual(str(cfg), "{'aa': 111, 'bb': $aa + 222}") + self.assertEqual(cfg.aa, 111) + self.assertEqual(cfg.bb, 333) + + def test_040(self): + inStream = DBG.InStream(_EXAMPLES[3]) + cfg = PYF.Config(inStream) + self.assertEqual(cfg.aa, "Yves") + self.assertEqual(cfg.bb, "Herve") + self.assertEqual(type(cfg.bb), str) + cfg.bb = "Hervé" # try this + self.assertEqual(type(cfg.bb), str) + self.assertEqual(cfg.bb, "Hervé") + + def test_045(self): + # make Hervé valid only with pyconf.py as 0.3.9 + inStream = DBG.InStream(_EXAMPLES[4]) + outStream = DBG.OutStream() + with self.assertRaises(Exception): + cfg = PYF.Config(inStream) + + return # TODO only with pyconf.py as 0.3.9 + cfg.save(outStream) # OK + # TODO: cfg = PYF.Config(inStream) + # cfg.__save__(outStream) # KO and sat renamed save() in __save__() + res = outStream.value + DBG.write("test_045 cfg", res) + self.assertTrue("aa : 'Yves'" in res) + self.assertTrue(r"bb : 'Herv\xc3\xa9'" in res) + self.assertEqual(cfg.bb, "Hervé") + + def test_100(self): + inStream = DBG.InStream(_EXAMPLES[5]) + outStream = DBG.OutStream() + cfg = PYF.Config(inStream) # KO + cfg.__save__(outStream) # sat renamed save() in __save__() + res = outStream.value + DBG.write("test_100 cfg save", res) + DBG.write("test_100 cfg debug", cfg) + DBG.write("test_100 cfg.cc debug", cfg.cc) + + cc = cfg.cc + # DBG.write("test_100 type cc[3]", dir(cc), True) + DBG.write("test_100 cc", [cc.data[i] for i in range(len(cc))]) + + def test_100(self): + inStream = DBG.InStream(_EXAMPLES[5]) + outStream = DBG.OutStream() + cfg = PYF.Config(inStream) # KO + cfg.__save__(outStream) # sat renamed save() in __save__() + res = outStream.value + DBG.write("test_100 cfg save", res) + DBG.write("test_100 cfg debug", cfg) + DBG.write("test_100 cfg.cc debug", cfg.cc) + + cc = cfg.cc + # DBG.write("test_100 type cc[3]", dir(cc), True) + DBG.write("test_100 cc", [cc.data[i] for i in range(len(cc))]) + + def test_110(self): + inStream = DBG.InStream(_EXAMPLES[6]) + outStream = DBG.OutStream() + cfg = PYF.Config(inStream) + cfg.__save__(outStream) + + res = outStream.value + DBG.write("test_110 cfg save", res) + self.assertNotIn("ERROR", res) + + res = DBG.getStrConfigDbg(cfg) + DBG.write("test_110 cfg debug", res) + self.assertIn("ERROR", res) + self.assertIn("unable to evaluate $cc", res) + self.assertIn("unable to evaluate $bb", res) + + def test_120(self): + for ii in [7, 8]: + inStream = DBG.InStream(_EXAMPLES[ii]) + outStream = DBG.OutStream() + cfg = PYF.Config(inStream) + cfg.__save__(outStream) + + res = outStream.value + DBG.write("test_120 cfg save", res) + self.assertNotIn("ERROR", res) + + res = DBG.getStrConfigDbg(cfg) + + DBG.write("test_120 cfg debug", res) + # no error circular !!! + # self.assertIn("ERROR", res) # no error circular !!! + # self.assertIn("unable to evaluate $cc", res) + # self.assertIn("unable to evaluate $bb", res) + res = cfg.bb + DBG.write("test_120 cfg.bb debug", res) + + res = cfg.cc + DBG.write("test_120 cfg.cc debug", res) - return # TODO only with pyconf.py as 0.3.9 - cfg.save(outStream) # OK - # TODO: cfg = PYF.Config(inStream) - # cfg.__save__(outStream) # KO and sat renamed save() in __save__() - res = outStream.value - DBG.write("test_045 cfg", res) - self.assertTrue("aa : 'Yves'" in res) - self.assertTrue(r"bb : 'Herv\xc3\xa9'" in res) - self.assertEqual(cfg.bb, "Hervé") - - def test_100(self): - inStream = DBG.InStream(_EXAMPLES[5]) - outStream = DBG.OutStream() - cfg = PYF.Config(inStream) # KO - cfg.__save__(outStream) # sat renamed save() in __save__() - res = outStream.value - DBG.write("test_100 cfg save", res) - DBG.write("test_100 cfg debug", cfg) - DBG.write("test_100 cfg.cc debug", cfg.cc) - - cc = cfg.cc - # DBG.write("test_100 type cc[3]", dir(cc), True) - DBG.write("test_100 cc", [cc.data[i] for i in range(len(cc))]) - - def test_100(self): - inStream = DBG.InStream(_EXAMPLES[5]) - outStream = DBG.OutStream() - cfg = PYF.Config(inStream) # KO - cfg.__save__(outStream) # sat renamed save() in __save__() - res = outStream.value - DBG.write("test_100 cfg save", res) - DBG.write("test_100 cfg debug", cfg) - DBG.write("test_100 cfg.cc debug", cfg.cc) - - cc = cfg.cc - # DBG.write("test_100 type cc[3]", dir(cc), True) - DBG.write("test_100 cc", [cc.data[i] for i in range(len(cc))]) - - def test_110(self): - inStream = DBG.InStream(_EXAMPLES[6]) - outStream = DBG.OutStream() - cfg = PYF.Config(inStream) - cfg.__save__(outStream) - - res = outStream.value - DBG.write("test_110 cfg save", res) - self.assertNotIn("ERROR", res) - - res = DBG.getStrConfigDbg(cfg) - DBG.write("test_110 cfg debug", res) - self.assertIn("ERROR", res) - self.assertIn("unable to evaluate $cc", res) - self.assertIn("unable to evaluate $bb", res) - - def test_120(self): - for ii in [7, 8]: - inStream = DBG.InStream(_EXAMPLES[ii]) - outStream = DBG.OutStream() - cfg = PYF.Config(inStream) - cfg.__save__(outStream) - - res = outStream.value - DBG.write("test_120 cfg save", res) - self.assertNotIn("ERROR", res) - - res = DBG.getStrConfigDbg(cfg) + def test_999(self): + # one shot tearDown() for this TestCase + # SAT.setLocale() # end test english + # DBG.pop_debug() + return - DBG.write("test_120 cfg debug", res) - # no error circular !!! - # self.assertIn("ERROR", res) # no error circular !!! - # self.assertIn("unable to evaluate $cc", res) - # self.assertIn("unable to evaluate $bb", res) - res = cfg.bb - DBG.write("test_120 cfg.bb debug", res) - res = cfg.cc - DBG.write("test_120 cfg.cc debug", res) - - def test_999(self): - # one shot tearDown() for this TestCase - # SAT.setLocale() # end test english - # DBG.pop_debug() - return - -if __name__ == '__main__': +if __name__ == "__main__": unittest.main(exit=False) pass diff --git a/test/test_100_satHelp.py b/test/test_100_satHelp.py index f11b9f3..d092136 100755 --- a/test/test_100_satHelp.py +++ b/test/test_100_satHelp.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -21,124 +21,128 @@ import os import sys import unittest -import initializeTest # set PATH etc for test +import initializeTest # set PATH etc for test import src.salomeTools as SAT -import src.debug as DBG # Easy print stderr (for DEBUG only) +import src.debug as DBG # Easy print stderr (for DEBUG only) import src.loggingSimple as LOG + class TestCase(unittest.TestCase): - "Test the sat --help commands""" - - debug = False - - def tearDown(self): - # print "tearDown", __file__ - # assure self.logger clear for next test - logger = LOG.getUnittestLogger() - logs = logger.getLogsAndClear() - # using assertNotIn() is too much verbose - self.assertFalse("ERROR" in logs) - self.assertFalse("CRITICAL" in logs) - - def test_000(self): - logger = LOG.getUnittestLogger() - # one shot setUp() for this TestCase - if self.debug: DBG.push_debug(True) - SAT.setNotLocale() # test english - - def test_999(self): - # one shot tearDown() for this TestCase - SAT.setLocale() # end test english - if self.debug: DBG.pop_debug() - - def test_010(self): # TODO fix logger unittest - cmd = "sat --help" - res = SAT.launchSat(cmd) - self.assertTrue(res.isOk()) - out = res.getValue() - self.assertTrue(" - config" in out) - self.assertTrue(" - prepare" in out) - self.assertTrue(" - compile" in out) - - def test_011(self): - logger = LOG.getUnittestLogger() - cmd = "--help" - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - self.assertTrue(returnCode.isOk()) - logs = logger.getLogs() - DBG.write("test_011 logger", logs) - self.assertTrue(" - config" in logs) - self.assertTrue(" - prepare" in logs) - self.assertTrue(" - compile" in logs) - - def test_030(self): - cmd = "sat config --help" - returnCode = SAT.launchSat(cmd) - self.assertTrue(returnCode.isOk()) - out = returnCode.getValue() - DBG.write("test_030 stdout", out) - self.assertTrue("--value" in out) - - def test_031(self): - logger = LOG.getUnittestLogger() - cmd = "config --help" - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - self.assertTrue(returnCode.isOk()) - logs = logger.getLogs() - DBG.write("test_031 logger", logs) - self.assertTrue("--help" in logs) - - def test_032(self): - logger = LOG.getUnittestLogger() - cmd = "prepare --help" - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - self.assertTrue(returnCode.isOk()) - logs = logger.getLogs() - DBG.write("test_031 logger", logs) - self.assertTrue("--help" in logs) - - def test_040(self): - logger = LOG.getUnittestLogger() - cmd = "config --list" - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - self.assertTrue(returnCode.isOk()) - logs = logger.getLogs() - self.assertTrue("Applications" in logs) - - def test_050(self): - cmds = SAT.getCommandsList() - DBG.write("test_050 getCommandsList", cmds) - for c in cmds: - cmd = "sat %s --help" % c - DBG.write("test_050", cmd) - returnCode = SAT.launchSat(cmd) - if not returnCode.isOk(): - DBG.write("test_050 %s" % cmd, returnCode.getValue(), True) - self.assertTrue(returnCode.isOk()) - out = returnCode.getValue() - DBG.write("test_050 %s stdout" % c, out) - self.assertTrue("The %s command" % c in out) - self.assertTrue("Available options" in out) - - def test_051(self): - logger = LOG.getUnittestLogger() - cmds = SAT.getCommandsList() - for c in cmds: - cmd = "%s --help" % c - DBG.write("test_051", cmd) - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - self.assertTrue(returnCode.isOk()) - logs = logger.getLogsAndClear() - DBG.write(cmd, logs) - self.assertTrue("The %s command" % c in logs) - self.assertTrue("Available options" in logs) - -if __name__ == '__main__': + "Test the sat --help commands" "" + + debug = False + + def tearDown(self): + # print "tearDown", __file__ + # assure self.logger clear for next test + logger = LOG.getUnittestLogger() + logs = logger.getLogsAndClear() + # using assertNotIn() is too much verbose + self.assertFalse("ERROR" in logs) + self.assertFalse("CRITICAL" in logs) + + def test_000(self): + logger = LOG.getUnittestLogger() + # one shot setUp() for this TestCase + if self.debug: + DBG.push_debug(True) + SAT.setNotLocale() # test english + + def test_999(self): + # one shot tearDown() for this TestCase + SAT.setLocale() # end test english + if self.debug: + DBG.pop_debug() + + def test_010(self): # TODO fix logger unittest + cmd = "sat --help" + res = SAT.launchSat(cmd) + self.assertTrue(res.isOk()) + out = res.getValue() + self.assertTrue(" - config" in out) + self.assertTrue(" - prepare" in out) + self.assertTrue(" - compile" in out) + + def test_011(self): + logger = LOG.getUnittestLogger() + cmd = "--help" + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + self.assertTrue(returnCode.isOk()) + logs = logger.getLogs() + DBG.write("test_011 logger", logs) + self.assertTrue(" - config" in logs) + self.assertTrue(" - prepare" in logs) + self.assertTrue(" - compile" in logs) + + def test_030(self): + cmd = "sat config --help" + returnCode = SAT.launchSat(cmd) + self.assertTrue(returnCode.isOk()) + out = returnCode.getValue() + DBG.write("test_030 stdout", out) + self.assertTrue("--value" in out) + + def test_031(self): + logger = LOG.getUnittestLogger() + cmd = "config --help" + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + self.assertTrue(returnCode.isOk()) + logs = logger.getLogs() + DBG.write("test_031 logger", logs) + self.assertTrue("--help" in logs) + + def test_032(self): + logger = LOG.getUnittestLogger() + cmd = "prepare --help" + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + self.assertTrue(returnCode.isOk()) + logs = logger.getLogs() + DBG.write("test_031 logger", logs) + self.assertTrue("--help" in logs) + + def test_040(self): + logger = LOG.getUnittestLogger() + cmd = "config --list" + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + self.assertTrue(returnCode.isOk()) + logs = logger.getLogs() + self.assertTrue("Applications" in logs) + + def test_050(self): + cmds = SAT.getCommandsList() + DBG.write("test_050 getCommandsList", cmds) + for c in cmds: + cmd = "sat %s --help" % c + DBG.write("test_050", cmd) + returnCode = SAT.launchSat(cmd) + if not returnCode.isOk(): + DBG.write("test_050 %s" % cmd, returnCode.getValue(), True) + self.assertTrue(returnCode.isOk()) + out = returnCode.getValue() + DBG.write("test_050 %s stdout" % c, out) + self.assertTrue("The %s command" % c in out) + self.assertTrue("Available options" in out) + + def test_051(self): + logger = LOG.getUnittestLogger() + cmds = SAT.getCommandsList() + for c in cmds: + cmd = "%s --help" % c + DBG.write("test_051", cmd) + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + self.assertTrue(returnCode.isOk()) + logs = logger.getLogsAndClear() + DBG.write(cmd, logs) + self.assertTrue("The %s command" % c in logs) + self.assertTrue("Available options" in logs) + + +if __name__ == "__main__": unittest.main(exit=False) pass diff --git a/test/test_500_APPLI_TEST.py b/test/test_500_APPLI_TEST.py index a2a8dd1..8c246fb 100755 --- a/test/test_500_APPLI_TEST.py +++ b/test/test_500_APPLI_TEST.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -21,110 +21,113 @@ import os import sys import unittest -import initializeTest # set PATH etc for test +import initializeTest # set PATH etc for test import src.salomeTools as SAT -import src.debug as DBG # Easy print stderr (for DEBUG only) +import src.debug as DBG # Easy print stderr (for DEBUG only) import src.loggingSimple as LOG + class TestCase(unittest.TestCase): - "Test the sat commands on APPLI_TEST configuration pyconf etc. files""" - - debug = False - - # see test_100, # commands are expected OK - TRG = "APPLI_TEST" # "SALOME-8.4.0" - satCommandsToTestOk = [ - "config -l", - "config -v .", - "config -g .", - "config %s --value ." % TRG, - "config %s --debug ." % TRG, - "config %s --info KERNEL" % TRG, - "config %s --show_patchs" % TRG, - ] - # see test_110, # commands are expected KO - satCommandsToTestKo = [ - "config %s --info oops" % TRG, - "config --oops", - ] - # see test_120, # commands are expected Raise, - # but if fixed go to satCommandsToTestKo - satCommandsToTestRaise = [ - "oopsconfig --oops .", - ] - - def tearDown(self): - # print "tearDown", __file__ - # assure self.logger clear for next test - logger = LOG.getUnittestLogger() - logs = logger.getLogsAndClear() - # using assertNotIn() is too much verbose - self.assertFalse("ERROR ::" in logs) - self.assertFalse("CRITICAL ::" in logs) - - def test_000(self): - logger = LOG.getUnittestLogger() - # one shot setUp() for this TestCase - if self.debug: DBG.push_debug(True) - SAT.setNotLocale() # test english - - def test_999(self): - # one shot tearDown() for this TestCase - SAT.setLocale() # end test english - if self.debug: DBG.pop_debug() - - def test_010(self): - logger = LOG.getUnittestLogger() - DBG.write("test_010 logger", logger.name) - cmd = "config -l" - s = SAT.Sat(logger) - DBG.write("s.getConfig()", s.getConfig()) #none - DBG.write("s.__dict__", s.__dict__) # have - returnCode = s.execute_cli(cmd) - DBG.write("test_010", returnCode) - logs = logger.getLogs() - DBG.write("test_010 logger", logs) - self.assertTrue(returnCode.isOk()) - - def xtest_100(self): # TODO - # test all satCommands expected OK - logger = LOG.getUnittestLogger() - dbg = self.debug - for cmd in self.satCommandsToTestOk: - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - DBG.write("test_100 'sat %s'" % cmd, str(returnCode), dbg) - logs = logger.getLogsAndClear() - DBG.write("logs", logs, dbg) - # using assertNotIn() is too much verbose - self.assertFalse("ERROR ::" in logs) - self.assertFalse("CRITICAL ::" in logs) - - def test_110(self): - # test all satCommands expected KO - logger = LOG.getUnittestLogger() - dbg = self.debug - for cmd in self.satCommandsToTestKo: - s = SAT.Sat(logger) - returnCode = s.execute_cli(cmd) - DBG.write("test_110 'sat %s'" % cmd, returnCode, dbg) - logs = logger.getLogsAndClear() - DBG.write("logs", logs, dbg) - - def test_120(self): - # test all satCommands expected raise - logger = LOG.getUnittestLogger() - dbg = self.debug - for cmd in self.satCommandsToTestRaise: - s = SAT.Sat(logger) - DBG.write("test_120 'sat %s'" % cmd, "expected raise", dbg) - with self.assertRaises(Exception): + "Test the sat commands on APPLI_TEST configuration pyconf etc. files" "" + + debug = False + + # see test_100, # commands are expected OK + TRG = "APPLI_TEST" # "SALOME-8.4.0" + satCommandsToTestOk = [ + "config -l", + "config -v .", + "config -g .", + "config %s --value ." % TRG, + "config %s --debug ." % TRG, + "config %s --info KERNEL" % TRG, + "config %s --show_patchs" % TRG, + ] + # see test_110, # commands are expected KO + satCommandsToTestKo = [ + "config %s --info oops" % TRG, + "config --oops", + ] + # see test_120, # commands are expected Raise, + # but if fixed go to satCommandsToTestKo + satCommandsToTestRaise = [ + "oopsconfig --oops .", + ] + + def tearDown(self): + # print "tearDown", __file__ + # assure self.logger clear for next test + logger = LOG.getUnittestLogger() + logs = logger.getLogsAndClear() + # using assertNotIn() is too much verbose + self.assertFalse("ERROR ::" in logs) + self.assertFalse("CRITICAL ::" in logs) + + def test_000(self): + logger = LOG.getUnittestLogger() + # one shot setUp() for this TestCase + if self.debug: + DBG.push_debug(True) + SAT.setNotLocale() # test english + + def test_999(self): + # one shot tearDown() for this TestCase + SAT.setLocale() # end test english + if self.debug: + DBG.pop_debug() + + def test_010(self): + logger = LOG.getUnittestLogger() + DBG.write("test_010 logger", logger.name) + cmd = "config -l" + s = SAT.Sat(logger) + DBG.write("s.getConfig()", s.getConfig()) # none + DBG.write("s.__dict__", s.__dict__) # have returnCode = s.execute_cli(cmd) - logs = logger.getLogsAndClear() - DBG.write("logs", logs, dbg) - - -if __name__ == '__main__': + DBG.write("test_010", returnCode) + logs = logger.getLogs() + DBG.write("test_010 logger", logs) + self.assertTrue(returnCode.isOk()) + + def xtest_100(self): # TODO + # test all satCommands expected OK + logger = LOG.getUnittestLogger() + dbg = self.debug + for cmd in self.satCommandsToTestOk: + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + DBG.write("test_100 'sat %s'" % cmd, str(returnCode), dbg) + logs = logger.getLogsAndClear() + DBG.write("logs", logs, dbg) + # using assertNotIn() is too much verbose + self.assertFalse("ERROR ::" in logs) + self.assertFalse("CRITICAL ::" in logs) + + def test_110(self): + # test all satCommands expected KO + logger = LOG.getUnittestLogger() + dbg = self.debug + for cmd in self.satCommandsToTestKo: + s = SAT.Sat(logger) + returnCode = s.execute_cli(cmd) + DBG.write("test_110 'sat %s'" % cmd, returnCode, dbg) + logs = logger.getLogsAndClear() + DBG.write("logs", logs, dbg) + + def test_120(self): + # test all satCommands expected raise + logger = LOG.getUnittestLogger() + dbg = self.debug + for cmd in self.satCommandsToTestRaise: + s = SAT.Sat(logger) + DBG.write("test_120 'sat %s'" % cmd, "expected raise", dbg) + with self.assertRaises(Exception): + returnCode = s.execute_cli(cmd) + logs = logger.getLogsAndClear() + DBG.write("logs", logs, dbg) + + +if __name__ == "__main__": unittest.main(exit=False) pass diff --git a/test/test_501_paramiko.py b/test/test_501_paramiko.py index ab5f92b..9e2308f 100755 --- a/test/test_501_paramiko.py +++ b/test/test_501_paramiko.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -98,43 +98,44 @@ 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 + "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) @@ -150,56 +151,56 @@ class TestCase(unittest.TestCase): 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.) - - # 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__': + """ + + 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) pass diff --git a/test/test_sat5_0/compilation/test_compilation.py b/test/test_sat5_0/compilation/test_compilation.py index 79192ad..807b1d7 100755 --- a/test/test_sat5_0/compilation/test_compilation.py +++ b/test/test_sat5_0/compilation/test_compilation.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -24,204 +24,249 @@ 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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_020(self): # Test the configure command with '--fathers' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' - product_name2 = 'PRODUCT_ARCHIVE' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') - + self.assertEqual(OK, "OK") + def test_030(self): # Test the configure command with '--children' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' - product_name2 = 'PRODUCT_ARCHIVE' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_040(self): # Test the configure command with '--clean_all' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' - product_name2 = 'PRODUCT_ARCHIVE' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_050(self): # Test the configure command with '--clean_install' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' - product_name2 = 'PRODUCT_ARCHIVE' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_060(self): # Test the configure command with '--make_flags' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_070(self): # Test the configure command with '--show' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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' + + 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') + self.assertEqual(OK, "OK") def test_080(self): # Test the configure command with '--stop_first_fail' option - OK = 'KO' + OK = "KO" - appli = 'appli-test' + 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' + + 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') + self.assertEqual(OK, "OK") def test_090(self): - # Test the 'sat -h compile' command to get description + # 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__': +if __name__ == "__main__": unittest.main() pass - diff --git a/test/test_sat5_0/compilation/test_configure.py b/test/test_sat5_0/compilation/test_configure.py index 9d995a2..c9ac3d7 100755 --- a/test/test_sat5_0/compilation/test_configure.py +++ b/test/test_sat5_0/compilation/test_configure.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -24,6 +24,7 @@ import unittest import src.product from src.salomeTools import Sat + class TestCase(unittest.TestCase): """Test of the configure command""" @@ -35,76 +36,86 @@ class TestCase(unittest.TestCase): def test_010(self): # Test the configure command with a product in cmake - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_020(self): # Test the configure command with a product in autotools - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_CVS' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_030(self): # Test the configure command with a product in script mode - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'Python' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + 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(): + + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/compilation/test_make.py b/test/test_sat5_0/compilation/test_make.py index c956965..b00fd8d 100755 --- a/test/test_sat5_0/compilation/test_make.py +++ b/test/test_sat5_0/compilation/test_make.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -24,83 +24,91 @@ 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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_020(self): # Test the make command with an option - OK = 'KO' - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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') - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_030(self): # Test the make command with a product in script mode - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'Python' + 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 + + 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) - + + sat.make(appli + " --product " + product_name) + if os.path.exists(os.path.join(expected_install_dir, expected_file)): - OK = 'OK' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_040(self): - # Test the sat -h make + # Test the sat -h make OK = "KO" import make - - if "The make command executes the \"make\" command" in make.description(): + + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/compilation/test_makeinstall.py b/test/test_sat5_0/compilation/test_makeinstall.py index 62aba79..6793b0a 100755 --- a/test/test_sat5_0/compilation/test_makeinstall.py +++ b/test/test_sat5_0/compilation/test_makeinstall.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -24,46 +24,53 @@ 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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_GIT' + 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) - + + 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' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + 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(): + + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/config/test_create_user_pyconf.py b/test/test_sat5_0/config/test_create_user_pyconf.py index 882124a..79e717d 100755 --- a/test/test_sat5_0/config/test_create_user_pyconf.py +++ b/test/test_sat5_0/config/test_create_user_pyconf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -24,27 +23,30 @@ 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" + 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')) + 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 .') + sat = Sat("") + sat.config("-v .") - expected_file = os.path.expanduser(os.path.join('~','.salomeTools', 'salomeTools.pyconf')) + expected_file = os.path.expanduser( + os.path.join("~", ".salomeTools", "salomeTools.pyconf") + ) if os.path.exists(expected_file): res = "OK" @@ -56,24 +58,24 @@ class TestCase(unittest.TestCase): 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': + 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': + if sat.cfg.INTERNAL.sat_version == "V0": OK = "OK" self.assertEqual(OK, "OK") @@ -95,28 +97,29 @@ class TestCase(unittest.TestCase): def test_050(self): # Test override APPLICATION OK = "KO" - + # The command to test sat = Sat("-oAPPLICATION.out_dir='/tmp'") - sat.config('appli-test') + sat.config("appli-test") - if sat.cfg.APPLICATION.out_dir == '/tmp': + 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('') + sat.config("") - if sat.cfg.PRODUCTS.PRODUCT_GIT.default.name == 'test': + if sat.cfg.PRODUCTS.PRODUCT_GIT.default.name == "test": OK = "OK" self.assertEqual(OK, "OK") + # test launch -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/config/test_option_copy.py b/test/test_sat5_0/config/test_option_copy.py index bb7fe0b..08b4f5d 100755 --- a/test/test_sat5_0/config/test_option_copy.py +++ b/test/test_sat5_0/config/test_option_copy.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -23,28 +23,37 @@ 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')) + 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') + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/config/test_option_edit.py b/test/test_sat5_0/config/test_option_edit.py index c6674e9..b7e2653 100755 --- a/test/test_sat5_0/config/test_option_edit.py +++ b/test/test_sat5_0/config/test_option_edit.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -28,22 +28,25 @@ 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 = 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) + pid = check_proc_existence_and_kill_multi( + editor + ".*" + "salomeTools\.pyconf", 10 + ) if pid: OK = "OK" @@ -55,19 +58,22 @@ class TestCase(unittest.TestCase): sat = Sat("-oUSER.editor='cooledit'") sat.config() - cmd_config = threading.Thread(target=sat.config, args=('appli-test -e',)) + 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) + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/config/test_option_value.py b/test/test_sat5_0/config/test_option_value.py index 50a7d84..5557fc0 100755 --- a/test/test_sat5_0/config/test_option_value.py +++ b/test/test_sat5_0/config/test_option_value.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -25,9 +25,10 @@ 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" @@ -37,7 +38,7 @@ class TestCase(unittest.TestCase): # The command to test sat = Sat() - sat.config('-v VARS.hostname') + sat.config("-v VARS.hostname") # stop output redirection my_out.end_redirection() @@ -58,7 +59,7 @@ class TestCase(unittest.TestCase): # The command to test sat = Sat() - sat.config('-l') + sat.config("-l") # stop output redirection my_out.end_redirection() @@ -70,7 +71,7 @@ class TestCase(unittest.TestCase): if "ERROR" not in res: OK = "OK" self.assertEqual(OK, "OK") - + """ def test_030(self): # Test the exception when salomeTools.pyconf has errors @@ -101,9 +102,10 @@ class TestCase(unittest.TestCase): shutil.copyfile(salomeToolspyconfPath_save, salomeToolspyconfPath) os.remove(salomeToolspyconfPath_save) self.assertEqual(OK, "OK") - """ - + """ + + # test launch -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/config/test_option_value_2.py b/test/test_sat5_0/config/test_option_value_2.py index c11fee1..cf7119d 100755 --- a/test/test_sat5_0/config/test_option_value_2.py +++ b/test/test_sat5_0/config/test_option_value_2.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -25,79 +25,78 @@ 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' + OK = "KO" # output redirection my_out = outRedirection() # The command to test - sat = Sat('') - sat.config('-v VARS.python') + 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') + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the display of the right value of 'sat config -s' - OK = 'KO' + OK = "KO" # output redirection my_out = outRedirection() # The command to test - sat = Sat('') - sat.config('-s') + 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') - + + 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' + application = "appli-test" + product = "PRODUCT_DEV" + + OK = "KO" # output redirection my_out = outRedirection() # The command to test - sat = Sat('') - sat.config(application + ' --info ' + product) + 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') + + if "compilation method = cmake" in res: + OK = "OK" + self.assertEqual(OK, "OK") + # test launch -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/environ/test_environ.py b/test/test_sat5_0/environ/test_environ.py index 3a63fd5..8689574 100755 --- a/test/test_sat5_0/environ/test_environ.py +++ b/test/test_sat5_0/environ/test_environ.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -23,17 +23,18 @@ 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' + OK = "KO" + + appli = "appli-test" + + file_env_name = "env_launch.sh" - file_env_name = 'env_launch.sh' - sat = Sat() sat.config(appli) @@ -45,18 +46,18 @@ class TestSource(unittest.TestCase): sat.environ(appli) if os.path.exists(expected_file_path): - OK = 'OK' - self.assertEqual(OK, 'OK') + 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' - + OK = "KO" + + appli = "appli-test" + product_name = "PRODUCT_GIT" + + file_env_name = "env_launch.sh" + sat = Sat() sat.config(appli) @@ -65,49 +66,49 @@ class TestSource(unittest.TestCase): if os.path.exists(expected_file_path): os.remove(expected_file_path) - sat.environ(appli + ' --products ' + product_name) + sat.environ(appli + " --products " + product_name) if os.path.exists(expected_file_path): - OK = 'OK' - self.assertEqual(OK, 'OK') + 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' - + 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') + 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 .') + sat.environ(appli + " --target .") if os.path.exists(expected_file_path): - OK = 'OK' + 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') + 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' - + OK = "KO" + + appli = "appli-test" + prefix = "TEST" + file_env_name = prefix + "_launch.sh" + sat = Sat() sat.config(appli) @@ -116,20 +117,20 @@ class TestSource(unittest.TestCase): if os.path.exists(expected_file_path): os.remove(expected_file_path) - sat.environ(appli + ' --prefix ' + prefix) + sat.environ(appli + " --prefix " + prefix) if os.path.exists(expected_file_path): - OK = 'OK' - self.assertEqual(OK, 'OK') + 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' - + OK = "KO" + + appli = "appli-test" + shell = "bat" + file_env_name = "env_launch.bat" + sat = Sat() sat.config(appli) @@ -138,13 +139,14 @@ class TestSource(unittest.TestCase): if os.path.exists(expected_file_path): os.remove(expected_file_path) - sat.environ(appli + ' --shell ' + shell) + sat.environ(appli + " --shell " + shell) if os.path.exists(expected_file_path): - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") + # test launch -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/job/test_job.py b/test/test_sat5_0/job/test_job.py index fc23191..d255fd0 100755 --- a/test/test_sat5_0/job/test_job.py +++ b/test/test_sat5_0/job/test_job.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -23,100 +23,106 @@ 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' + OK = "KO" tmp_file = "/tmp/test.txt" sat = Sat("-l " + tmp_file) - + # Execute the job command - sat.job("--jobs_config .test --name Job 1" ) + 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] - + 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') - + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the job command with a failing command - OK = 'KO' + 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" ) + res = sat.job("--jobs_config .test --name Job 4") if res == 1: - OK = 'OK' + OK = "OK" # pyunit method to compare 2 str - self.assertEqual(OK, 'OK') + self.assertEqual(OK, "OK") def test_030(self): # Test the job command with a wrong file configuration - OK = 'KO' + 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" ) + res = sat.job("--jobs_config NOTEXIST --name Job 4") if res == 1: - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") def test_040(self): # Test the job command without --jobs_config option - OK = 'KO' + OK = "KO" tmp_file = "/tmp/test.txt" sat = Sat("-l " + tmp_file) - + # Execute the job command - res = sat.job("--name Job 4" ) + res = sat.job("--name Job 4") if res == 1: - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") def test_050(self): # Test the job command without --jobs_config option - OK = 'KO' + OK = "KO" tmp_file = "/tmp/test.txt" sat = Sat("-l " + tmp_file) - + # Execute the job command - res = sat.job("--jobs_config .test --name NOTEXIST" ) + res = sat.job("--jobs_config .test --name NOTEXIST") if res == 1: - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") def test_060(self): - # Test the sat -h job + # 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(): + + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/jobs/test_jobs.py b/test/test_sat5_0/jobs/test_jobs.py index 1b22378..aa2f1ad 100755 --- a/test/test_sat5_0/jobs/test_jobs.py +++ b/test/test_sat5_0/jobs/test_jobs.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -24,102 +24,103 @@ import unittest from src.salomeTools import Sat from unittestpy.tools import outRedirection + class TestCase(unittest.TestCase): - "Test the jobs command""" + "Test the jobs command" "" def test_010(self): # Test the jobs command - OK = 'KO' + OK = "KO" tmp_file = "/tmp/test.txt" sat = Sat("-l " + tmp_file) - + # Execute the jobs command - sat.jobs("--name .test --publish" ) + 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] - + 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" + "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') + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the jobs command with option --only_jobs - OK = 'KO' + 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" ) + 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] - + 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" + "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') + OK = "OK" + self.assertEqual(OK, "OK") def test_030(self): # Test the jobs command without --name option - OK = 'KO' + 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') - + OK = "OK" + self.assertEqual(OK, "OK") + def test_040(self): # Test the jobs command with a wrong file configuration - OK = 'KO' + OK = "KO" tmp_file = "/tmp/test.txt" sat = Sat("-l " + tmp_file) - + # Execute the job command - res = sat.jobs("--name NOTEXIST" ) + res = sat.jobs("--name NOTEXIST") if res == 1: - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") def test_050(self): # Test the display of the right value of 'sat jobs --list' @@ -130,7 +131,7 @@ class TestCase(unittest.TestCase): # The command to test sat = Sat() - sat.jobs('--list') + sat.jobs("--list") # stop output redirection my_out.end_redirection() @@ -144,16 +145,20 @@ class TestCase(unittest.TestCase): self.assertEqual(OK, "OK") def test_060(self): - # Test the sat -h jobs + # 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(): + + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/log/test_launch_browser.py b/test/test_sat5_0/log/test_launch_browser.py index a9c8be4..2a45cd0 100755 --- a/test/test_sat5_0/log/test_launch_browser.py +++ b/test/test_sat5_0/log/test_launch_browser.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -30,21 +30,24 @@ 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') - + 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") - + 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") @@ -52,16 +55,15 @@ class TestCase(unittest.TestCase): 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') + sat.log("-t") OK = "OK" sys.stdin = sys.__stdin__ except: @@ -71,17 +73,17 @@ class TestCase(unittest.TestCase): 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') - + + sat.config("appli-test -v VARS.python") + one = u"1" sys.stdin = io.StringIO(one) - + try: - sat.log('appli-test -t --last') + sat.log("appli-test -t --last") OK = "OK" sys.stdin = sys.__stdin__ except: @@ -91,17 +93,17 @@ class TestCase(unittest.TestCase): 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') - + + sat.config("appli-test -v VARS.python") + zero = u"0\n1" sys.stdin = io.StringIO(zero) - + try: - sat.log('--terminal') + sat.log("--terminal") OK = "OK" finally: sys.stdin = sys.__stdin__ @@ -110,19 +112,19 @@ class TestCase(unittest.TestCase): 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') - + + 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') + sat.log("--terminal") OK = "OK" finally: sys.stdin = sys.__stdin__ @@ -131,17 +133,17 @@ class TestCase(unittest.TestCase): 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') - + + sat.config("appli-test -v VARS.python") + ret = unicode("\n0") sys.stdin = io.StringIO(ret) - + try: - sat.log('--terminal') + sat.log("--terminal") OK = "OK" finally: sys.stdin = sys.__stdin__ @@ -150,17 +152,17 @@ class TestCase(unittest.TestCase): 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') - + + sat.config("appli-test -v VARS.python") + ret = unicode("blabla\n0") sys.stdin = io.StringIO(ret) - + try: - sat.log('--terminal') + sat.log("--terminal") OK = "OK" finally: sys.stdin = sys.__stdin__ @@ -169,75 +171,78 @@ class TestCase(unittest.TestCase): 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') + 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') - - + + sat.config("appli-test -v VARS.python") + time.sleep(sleep_time) - cmd_log = threading.Thread(target=sat.log, args=('appli-test --last',)) + 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') - + + sat.config("-v VARS.user") + nb_logs_t0 = len(os.listdir(sat.cfg.USER.log_dir)) - sat.log('--clean 1') - + sat.log("--clean 1") + nb_logs_t1 = len(os.listdir(sat.cfg.USER.log_dir)) - - if nb_logs_t1-nb_logs_t0 == 0: + + 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') - + + sat.config("-v VARS.user") + nb_logs_t0 = 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") + 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") @@ -252,7 +257,7 @@ class TestCase(unittest.TestCase): OK = "OK" """ self.assertEqual(OK, "OK") - + """ def test_130(self): # Test the option --full @@ -283,12 +288,13 @@ class TestCase(unittest.TestCase): 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/log/test_launch_browser2.py b/test/test_sat5_0/log/test_launch_browser2.py index 38a6184..76b7b51 100755 --- a/test/test_sat5_0/log/test_launch_browser2.py +++ b/test/test_sat5_0/log/test_launch_browser2.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -28,6 +28,7 @@ from unittestpy.tools import check_proc_existence_and_kill_multi sleep_time = 2 + class TestCase(unittest.TestCase): """Test of log command: launch of browser""" @@ -37,11 +38,11 @@ class TestCase(unittest.TestCase): sat = Sat("-oUSER.browser='konqueror'") time.sleep(sleep_time) - cmd_log = threading.Thread(target=sat.log, args=('',)) + 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) @@ -50,7 +51,8 @@ class TestCase(unittest.TestCase): OK = "OK" self.assertEqual(OK, "OK") + # test launch -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/prepare/test_clean.py b/test/test_sat5_0/prepare/test_clean.py index 08bb54f..3203654 100755 --- a/test/test_sat5_0/prepare/test_clean.py +++ b/test/test_sat5_0/prepare/test_clean.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -25,49 +25,52 @@ 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' + OK = "KO" - appli = 'appli-test' + 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') + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the clean of sources OK = "KO" - appli = 'appli-test' + appli = "appli-test" product_name = "PRODUCT_GIT" - sat = Sat() - + 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 - + + 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") @@ -76,20 +79,22 @@ class TestCase(unittest.TestCase): # Test the clean of build OK = "KO" - appli = 'appli-test' + appli = "appli-test" product_name = "PRODUCT_GIT" - sat = Sat() - + 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 - + + 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") @@ -98,20 +103,22 @@ class TestCase(unittest.TestCase): # Test the clean of install OK = "KO" - appli = 'appli-test' + appli = "appli-test" product_name = "PRODUCT_GIT" - sat = Sat() - + 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 - + + 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") @@ -120,23 +127,33 @@ class TestCase(unittest.TestCase): # Test the clean of all (build, src, install) OK = "KO" - appli = 'appli-test' + appli = "appli-test" product_name = "PRODUCT_GIT" - sat = Sat() - + 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): + + 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") @@ -144,37 +161,44 @@ class TestCase(unittest.TestCase): # Test the clean with sources_without_dev option OK = "KO" - appli = 'appli-test' + appli = "appli-test" product_name = "PRODUCT_GIT" product_name2 = "PRODUCT_DEV" - sat = Sat() - + 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 - + + 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(): + + if ( + "The clean command suppress the source, build, or install" + in clean.description() + ): OK = "OK" self.assertEqual(OK, "OK") + # test launch -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/prepare/test_patch.py b/test/test_sat5_0/prepare/test_patch.py index 1dc24d4..af7a375 100755 --- a/test/test_sat5_0/prepare/test_patch.py +++ b/test/test_sat5_0/prepare/test_patch.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -26,142 +26,151 @@ 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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_DEV' + 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' - + + 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') + + sat.source(appli + " --product " + product_name) + + f = open(expected_file_path, "r") text = f.readlines()[0] - OK1 = 'KO' + 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') + 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' + + OK2 = "KO" if text == new_expected_text: - OK2 = 'OK' + OK2 = "OK" - if (OK1, OK2)==('OK', 'OK'): - OK = 'OK' - self.assertEqual(OK, '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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_DEV' + appli = "appli-test" + product_name = "PRODUCT_DEV" - sat = Sat('') + sat = Sat("") sat.config(appli) - - expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir - + + 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) - + + 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') + + 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' + OK = "KO" + + appli = "appli-test" + product_name = "PRODUCT_ARCHIVE" - appli = 'appli-test' - product_name = 'PRODUCT_ARCHIVE' + sat = Sat("-v4") + + sat.source(appli + " --product " + product_name) - sat = Sat('-v4') - - sat.source(appli + ' --product ' + product_name) - # output redirection my_out = outRedirection() - - sat.patch(appli + ' --product ' + product_name) - + + 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') + + 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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_DEV' + appli = "appli-test" + product_name = "PRODUCT_DEV" sat = Sat("-oPRODUCTS.PRODUCT_DEV.default.patches=['/']") - - sat.source(appli + ' --product ' + product_name) - + + sat.source(appli + " --product " + product_name) + # output redirection my_out = outRedirection() - - sat.patch(appli + ' --product ' + product_name) - + + 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') + 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(): + + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/prepare/test_prepare.py b/test/test_sat5_0/prepare/test_prepare.py index 3340547..92f5e04 100755 --- a/test/test_sat5_0/prepare/test_prepare.py +++ b/test/test_sat5_0/prepare/test_prepare.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -25,87 +25,93 @@ 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' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_DEV' + 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' - + + 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') + + 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') + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the prepare command with all products - OK = 'KO' + OK = "KO" - appli = 'appli-test' - product_name = 'PRODUCT_DEV' + 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' - + + 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') + + f = open(expected_file_path, "r") text = f.readlines()[0] if text == expected_text: - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") def test_030(self): # Test the prepare command with all products - OK = 'KO' + OK = "KO" - appli = 'appli-test' + appli = "appli-test" sat = Sat() sat.config(appli) - + try: sat.prepare(appli + " --force --force_patch") - OK = 'OK' + OK = "OK" except: pass - self.assertEqual(OK, 'OK') + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/prepare/test_source.py b/test/test_sat5_0/prepare/test_source.py index f7a053d..ac09fe3 100755 --- a/test/test_sat5_0/prepare/test_source.py +++ b/test/test_sat5_0/prepare/test_source.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -25,59 +25,66 @@ 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' + appli = "appli-test" + product_name = "PRODUCT_ARCHIVE" sat = Sat() - sat.source(appli + ' --product ' + product_name) + 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' + 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') + 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' + appli = "appli-test" + product_name = "PRODUCT_GIT" sat = Sat() - sat.source(appli + ' --product ' + product_name) + 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' + 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') + 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' + appli = "appli-test" + product_name = "PRODUCT_CVS" sat = Sat() - sat.source(appli + ' --product ' + product_name) + 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' + 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') + 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 @@ -105,34 +112,38 @@ class TestCase(unittest.TestCase): def test_050(self): # Test the source command with native product - OK = 'KO' - - appli = 'appli-test' - product_name = 'PRODUCT_NATIVE' + OK = "KO" + + appli = "appli-test" + product_name = "PRODUCT_NATIVE" sat = Sat() - sat.source(appli + ' --product ' + product_name) + sat.source(appli + " --product " + product_name) - expected_src_dir = os.path.join(sat.cfg.APPLICATION.workdir, 'SOURCES', 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') + 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' + OK = "KO" + + appli = "appli-test" + product_name = "PRODUCT_FIXED" sat = Sat() - sat.source(appli + ' --product ' + product_name) + sat.source(appli + " --product " + product_name) - expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + 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') + OK = "OK" + self.assertEqual(OK, "OK") """ def test_070(self): @@ -164,12 +175,13 @@ class TestCase(unittest.TestCase): 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/shell/test_shell.py b/test/test_sat5_0/shell/test_shell.py index 80f579e..65521be 100755 --- a/test/test_sat5_0/shell/test_shell.py +++ b/test/test_sat5_0/shell/test_shell.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -23,19 +23,20 @@ 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' + 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) @@ -44,22 +45,22 @@ class TestCase(unittest.TestCase): 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') + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the shell command with the --command option with a failing command - OK = 'KO' + OK = "KO" tmp_file = "/tmp/test.txt" sat = Sat("-l " + tmp_file) - + sat.config() - + # Execute the shell command res = sat.shell("--command i_fail") @@ -68,24 +69,25 @@ class TestCase(unittest.TestCase): 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') + 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__': +if __name__ == "__main__": unittest.main() pass diff --git a/test/test_sat5_0/test/test_command.py b/test/test_sat5_0/test/test_command.py index 136df62..8ea743f 100755 --- a/test/test_sat5_0/test/test_command.py +++ b/test/test_sat5_0/test/test_command.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -#-*- coding:utf-8 -*- +# -*- coding:utf-8 -*- # Copyright (C) 2010-2018 CEA/DEN # @@ -23,66 +23,75 @@ 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' + 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" ) + 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] - + log_testboard = [ + line.replace("\n", "") for line in log_files if "testboard.xml" in line + ] + text = open(log_testboard[0], "r").read() if '' in text: - OK = 'OK' - self.assertEqual(OK, 'OK') + OK = "OK" + self.assertEqual(OK, "OK") def test_020(self): # Test the test command with PY type - OK = 'KO' + 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" ) + 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] - + log_testboard = [ + line.replace("\n", "") for line in log_files if "testboard.xml" in line + ] + text = open(log_testboard[0], "r").read() if '' in text: - OK = 'OK' - self.assertEqual(OK, 'OK') + 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(): + + 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__': +if __name__ == "__main__": unittest.main() pass -- 2.39.2