job_controller_test.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #
  2. # Copyright 2019 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import unittest
  17. from fate_flow.utils.base_utils import jprint
  18. from fate_flow.controller.job_controller import JobController
  19. from fate_flow.utils import job_utils
  20. class TestJobController(unittest.TestCase):
  21. def test_gen_updated_parameters(self):
  22. job_id = "202110211127411105150"
  23. initiator_role = "guest"
  24. initiator_party_id = 9999
  25. input_job_parameters = {
  26. "common": {
  27. "auto_retries": 1,
  28. "auto_retry_delay": 1
  29. }
  30. }
  31. input_component_parameters = {
  32. "common": {
  33. "hetero_lr_0": {
  34. "alpha": 0.02
  35. }
  36. },
  37. "role": {
  38. "guest": {
  39. "0": {
  40. "reader_0": {
  41. "table": {"name": "breast_hetero_guest", "namespace": "unitest_experiment"}
  42. },
  43. "homo_nn_0":{
  44. "with_label": True,
  45. "output_format": "dense"
  46. },
  47. }
  48. },
  49. "host": {
  50. "1": {
  51. "dataio_0":{
  52. "with_label": True,
  53. "output_format": "dense"
  54. },
  55. "evaluation_0": {
  56. "need_run": True
  57. }
  58. }
  59. }
  60. }
  61. }
  62. updated_job_parameters, updated_component_parameters, updated_components = JobController.gen_updated_parameters(
  63. job_id=job_id,
  64. initiator_role=initiator_role,
  65. initiator_party_id=initiator_party_id,
  66. input_job_parameters=input_job_parameters,
  67. input_component_parameters=input_component_parameters)
  68. jprint(updated_job_parameters)
  69. jprint(updated_component_parameters)
  70. self.assertTrue(check(input_component_parameters, updated_component_parameters)[0])
  71. # todo: add check with origin parameters and add dsl parser check
  72. def check(inputs, result):
  73. # todo: return check keys chain
  74. if type(result) != type(inputs):
  75. return False, "type not match"
  76. elif isinstance(inputs, dict):
  77. for k, v in inputs.items():
  78. if k not in result:
  79. return False, f"no such {k} key"
  80. if isinstance(v, (dict, list)):
  81. return check(v, result[k])
  82. else:
  83. if result[k] != v:
  84. return False, f"{k} value not match"
  85. else:
  86. return True, "match"
  87. elif isinstance(inputs, list):
  88. return result == inputs
  89. else:
  90. raise Exception(f"not support type {type(inputs)}")
  91. if __name__ == '__main__':
  92. unittest.main()