pbs_dshutils_tests.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # coding: utf-8
  2. # Copyright (C) 1994-2018 Altair Engineering, Inc.
  3. # For more information, contact Altair at www.altair.com.
  4. #
  5. # This file is part of the PBS Professional ("PBS Pro") software.
  6. #
  7. # Open Source License Information:
  8. #
  9. # PBS Pro is free software. You can redistribute it and/or modify it under the
  10. # terms of the GNU Affero General Public License as published by the Free
  11. # Software Foundation, either version 3 of the License, or (at your option) any
  12. # later version.
  13. #
  14. # PBS Pro is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. # FOR A PARTICULAR PURPOSE.
  17. # See the GNU Affero General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU Affero General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. #
  22. # Commercial License Information:
  23. #
  24. # For a copy of the commercial license terms and conditions,
  25. # go to: (http://www.pbspro.com/UserArea/agreement.html)
  26. # or contact the Altair Legal Department.
  27. #
  28. # Altair’s dual-license business model allows companies, individuals, and
  29. # organizations to create proprietary derivative works of PBS Pro and
  30. # distribute them - whether embedded or bundled with other software -
  31. # under a commercial license agreement.
  32. #
  33. # Use of Altair’s trademarks, including but not limited to "PBS™",
  34. # "PBS Professional®", and "PBS Pro™" and Altair’s logos is subject to Altair's
  35. # trademark licensing policies.
  36. from tests.selftest import *
  37. from ptl.utils.pbs_dshutils import PbsConfigError
  38. class TestDshUtils(TestSelf):
  39. """
  40. Test pbs distributed utilities util pbs_dshutils.py
  41. """
  42. def test_pbs_conf(self):
  43. """
  44. Test setting a pbs.conf variable and then unsetting it
  45. """
  46. var = 'PBS_COMM_THREADS'
  47. val = '16'
  48. self.du.set_pbs_config(confs={var: val})
  49. conf = self.du.parse_pbs_config()
  50. msg = 'pbs.conf variable not set'
  51. self.assertIn(var, conf, msg)
  52. self.assertEquals(conf[var], val, msg)
  53. msg = 'pbs.conf variable not unset'
  54. self.du.unset_pbs_config(confs=[var])
  55. conf = self.du.parse_pbs_config()
  56. self.assertNotIn(var, conf, msg)
  57. exception_found = False
  58. try:
  59. self.du.set_pbs_config(confs={'f': 'b'}, fout='/does/not/exist')
  60. except PbsConfigError:
  61. exception_found = True
  62. self.assertTrue(exception_found, 'PbsConfigError not thrown')
  63. def test_pbs_env(self):
  64. """
  65. Test setting a pbs_environment variable and then unsetting it
  66. """
  67. self.du.set_pbs_environment(environ={'pbs_foo': 'True'})
  68. environ = self.du.parse_pbs_environment()
  69. msg = 'pbs environment variable not set'
  70. self.assertIn('pbs_foo', environ, msg)
  71. self.assertEquals(environ['pbs_foo'], 'True', msg)
  72. msg = 'pbs environment variable not unset'
  73. self.du.unset_pbs_environment(environ=['pbs_foo'])
  74. environ = self.du.parse_pbs_environment()
  75. self.assertNotIn('pbs_foo', environ, msg)