Skip to content

Commit

Permalink
created unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
amaltaro committed Oct 15, 2020
1 parent bc3a701 commit 2099341
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion test/python/WMCore_t/ReqMgr_t/Utils_t/Validation_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import unittest

from WMCore.ReqMgr.Utils.Validation import validateOutputDatasets
from WMCore.ReqMgr.DataStructs.RequestError import InvalidSpecParameterValue
from WMCore.ReqMgr.Utils.Validation import validateOutputDatasets, validate_request_priority


class ValidationTests(unittest.TestCase):
Expand Down Expand Up @@ -48,6 +48,43 @@ def testValidateOutputDatasets(self):
with self.assertRaises(InvalidSpecParameterValue):
validateOutputDatasets(outputDsets, dbsUrl)

def testRequestPriorityValidation(self):
"""
Test the `validate_request_priority` function, which validates the
RequestPriority parameter
:return: nothing, raises an exception if there are problems
"""
reqArgs = {'RequestPriority': "1234"}
# test an integer casted to string
validate_request_priority(reqArgs)
# test an integer
validate_request_priority(reqArgs)
# test a float (which is properly casted to int)
reqArgs = {'RequestPriority': 1234.25}
validate_request_priority(reqArgs)

# test an integer casted to a string, in an invalid range
reqArgs = {'RequestPriority': "1e7"}
with self.assertRaises(InvalidSpecParameterValue):
validate_request_priority(reqArgs)
# test an integer in an invalid range
reqArgs = {'RequestPriority': 1e7}
with self.assertRaises(InvalidSpecParameterValue):
validate_request_priority(reqArgs)
# test an integer in an invalid range
reqArgs = {'RequestPriority': -5}
with self.assertRaises(InvalidSpecParameterValue):
validate_request_priority(reqArgs)

# test a float casted to string
reqArgs = {'RequestPriority': "1234.25"}
with self.assertRaises(InvalidSpecParameterValue):
validate_request_priority(reqArgs)
# test a weird list
reqArgs = {'RequestPriority': [1234]}
with self.assertRaises(InvalidSpecParameterValue):
validate_request_priority(reqArgs)


if __name__ == '__main__':
unittest.main()

0 comments on commit 2099341

Please sign in to comment.