From e4207d11a1f491082e7bdd18b100a63db74dd4a4 Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Wed, 24 Jun 2020 16:39:16 +0200 Subject: [PATCH 1/7] pytest without coverage --- .github/workflows/basic.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 21febce9efd..348b18141f8 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -12,10 +12,10 @@ jobs: fail-fast: False matrix: command: - - pytest - - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest - - pytest Core/Security/test - - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest Core/Security/test + - pytest --no-cov + - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov + - pytest --no-cov Core/Security/test + - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov Core/Security/test - tests/checkDocs.sh # TODO This should cover more than just tests/CI # Excluded codes related to sourcing files From 6b995e99dab365ac3edd1d847fd533626e8d2968 Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Wed, 24 Jun 2020 21:00:37 +0200 Subject: [PATCH 2/7] no --no-cov fir general pytest --- .github/workflows/basic.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 348b18141f8..9bcc0f00cf9 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -12,8 +12,8 @@ jobs: fail-fast: False matrix: command: - - pytest --no-cov - - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov + - pytest + - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest - pytest --no-cov Core/Security/test - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov Core/Security/test - tests/checkDocs.sh From c08871db85ecf7ece4069aad3100d76d5397c72f Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Thu, 25 Jun 2020 09:26:22 +0200 Subject: [PATCH 3/7] once again --- .github/workflows/basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 9bcc0f00cf9..7d70c7d623b 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -12,7 +12,7 @@ jobs: fail-fast: False matrix: command: - - pytest + - pytest --no-cov - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest - pytest --no-cov Core/Security/test - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov Core/Security/test From ebc8639fa65732f1dfb355227181190ccfca9ea6 Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Thu, 25 Jun 2020 10:38:50 +0200 Subject: [PATCH 4/7] test adapted for --no-cov pytest running --- .../PilotAgent/test/Test_Pilot.py | 67 ++++++------------- 1 file changed, 22 insertions(+), 45 deletions(-) diff --git a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py index 8e986940958..dc8468c991c 100644 --- a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py +++ b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py @@ -2,54 +2,31 @@ """ # imports -import unittest import json import os +import sys + +if "--no-cov" in sys.argv: + del sys.argv[sys.argv.index( '--no-cov' )] from DIRAC.WorkloadManagementSystem.PilotAgent.pilotTools import PilotParams, CommandBase from DIRAC.WorkloadManagementSystem.PilotAgent.pilotCommands import GetPilotVersion -class PilotTestCase( unittest.TestCase ): - """ Base class for the Agents test cases - """ - def setUp( self ): - self.pp = PilotParams() - - def tearDown( self ): - try: - os.remove('pilot.out') - os.remove( 'pilot.json' ) - os.remove( 'pilot.json-local' ) - except OSError: - pass - - -class CommandsTestCase( PilotTestCase ): - - def test_commandBase(self): - cb = CommandBase(self.pp) - returnCode, _outputData = cb.executeAndGetOutput("ls") - self.assertEqual(returnCode, 0) - - def test_GetPilotVersion( self ): - - # Now defining a local file for test, and all the necessary parameters - fp = open( 'pilot.json', 'w' ) - json.dump( {'TestSetup':{'Version':['v1r1', 'v2r2']}}, fp ) - fp.close() - self.pp.setup = 'TestSetup' - self.pp.pilotCFGFileLocation = 'file://%s' % os.getcwd() - gpv = GetPilotVersion( self.pp ) - self.assertIsNone( gpv.execute() ) - self.assertEqual( gpv.pp.releaseVersion, 'v1r1' ) - -############################################################################# -# Test Suite run -############################################################################# - -if __name__ == '__main__': - suite = unittest.defaultTestLoader.loadTestsFromTestCase( PilotTestCase ) - suite.addTest( unittest.defaultTestLoader.loadTestsFromTestCase( CommandsTestCase ) ) - testResult = unittest.TextTestRunner( verbosity = 2 ).run( suite ) - -# EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF# +def test_GetPilotVersion(): + pp = PilotParams() + # Now defining a local file for test, and all the necessary parameters + fp = open( 'pilot.json', 'w' ) + json.dump( { 'TestSetup': { 'Version': ['v1r1', 'v2r2'] } }, fp ) + fp.close() + pp.setup = 'TestSetup' + pp.pilotCFGFileLocation = 'file://%s' % os.getcwd() + gpv = GetPilotVersion( pp ) + result = gpv.execute() + assert result is None + assert gpv.pp.releaseVersion == 'v1r1' + +def test_commandBase(): + pp = PilotParams() + cb = CommandBase( pp ) + returnCode, _outputData = cb.executeAndGetOutput( "ls" ) + assert returnCode== 0 From b996650e9fd4967250ed1072010dc8ced78a8dc6 Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Thu, 25 Jun 2020 10:44:22 +0200 Subject: [PATCH 5/7] hopefully the final --no-cov --- .github/workflows/basic.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 7d70c7d623b..348b18141f8 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -13,7 +13,7 @@ jobs: matrix: command: - pytest --no-cov - - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest + - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov - pytest --no-cov Core/Security/test - DIRAC_USE_M2CRYPTO=Yes DIRAC_M2CRYPTO_SPLIT_HANDSHAKE=Yes pytest --no-cov Core/Security/test - tests/checkDocs.sh From e8d903fe192130b808944c762f8c85f490b67529 Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Thu, 25 Jun 2020 10:51:04 +0200 Subject: [PATCH 6/7] typo fixed --- WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py index dc8468c991c..aafbc2c273a 100644 --- a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py +++ b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py @@ -29,4 +29,4 @@ def test_commandBase(): pp = PilotParams() cb = CommandBase( pp ) returnCode, _outputData = cb.executeAndGetOutput( "ls" ) - assert returnCode== 0 + assert returnCode == 0 From dc3f58165e79bb844c7c83fe04f0d4d68a1fecfb Mon Sep 17 00:00:00 2001 From: Andrei Tsaregorodtsev Date: Thu, 25 Jun 2020 11:14:17 +0200 Subject: [PATCH 7/7] autopep8 --- .../PilotAgent/test/Test_Pilot.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py index aafbc2c273a..a183bf9f959 100644 --- a/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py +++ b/WorkloadManagementSystem/PilotAgent/test/Test_Pilot.py @@ -7,26 +7,28 @@ import sys if "--no-cov" in sys.argv: - del sys.argv[sys.argv.index( '--no-cov' )] + del sys.argv[sys.argv.index('--no-cov')] from DIRAC.WorkloadManagementSystem.PilotAgent.pilotTools import PilotParams, CommandBase from DIRAC.WorkloadManagementSystem.PilotAgent.pilotCommands import GetPilotVersion + def test_GetPilotVersion(): pp = PilotParams() # Now defining a local file for test, and all the necessary parameters - fp = open( 'pilot.json', 'w' ) - json.dump( { 'TestSetup': { 'Version': ['v1r1', 'v2r2'] } }, fp ) + fp = open('pilot.json', 'w') + json.dump({'TestSetup': {'Version': ['v1r1', 'v2r2']}}, fp) fp.close() pp.setup = 'TestSetup' pp.pilotCFGFileLocation = 'file://%s' % os.getcwd() - gpv = GetPilotVersion( pp ) + gpv = GetPilotVersion(pp) result = gpv.execute() assert result is None assert gpv.pp.releaseVersion == 'v1r1' + def test_commandBase(): pp = PilotParams() - cb = CommandBase( pp ) - returnCode, _outputData = cb.executeAndGetOutput( "ls" ) + cb = CommandBase(pp) + returnCode, _outputData = cb.executeAndGetOutput("ls") assert returnCode == 0