param_extract_test.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import os
  18. from federatedml.util.param_extract import ParamExtract
  19. from federatedml.param import InitParam
  20. from federatedml.param.boosting_param import HeteroSecureBoostParam
  21. class TestParamExtract(unittest.TestCase):
  22. def setUp(self):
  23. self.init_param = InitParam()
  24. self.boosting_tree_param = HeteroSecureBoostParam()
  25. self.config_dict = \
  26. {"ComponentParam": {
  27. "init_param": {"init_method": "test_init", "fit_intercept": False},
  28. "tree_param": {"criterion_method": "test_decisiontree"},
  29. "task_type": "test_boostingtree",
  30. "test_variable": "test"}
  31. }
  32. def test_directly_extract(self):
  33. boosting_tree_param = HeteroSecureBoostParam()
  34. extractor = ParamExtract()
  35. boosting_tree_param = extractor.parse_param_from_config(boosting_tree_param, self.config_dict)
  36. self.assertTrue(boosting_tree_param.task_type == "test_boostingtree")
  37. def test_undefine_variable_extract(self):
  38. boosting_tree_param = HeteroSecureBoostParam()
  39. extractor = ParamExtract()
  40. boosting_tree_param = extractor.parse_param_from_config(boosting_tree_param, self.config_dict)
  41. self.assertTrue(not hasattr(boosting_tree_param, "test_variable"))
  42. def test_param_embedding(self):
  43. boosting_tree_param = HeteroSecureBoostParam()
  44. extractor = ParamExtract()
  45. boosting_tree_param = extractor.parse_param_from_config(boosting_tree_param, self.config_dict)
  46. print("boosting_tree_param.tree_param.criterion_method {}".format(
  47. boosting_tree_param.tree_param.criterion_method))
  48. self.assertTrue(boosting_tree_param.tree_param.criterion_method == "test_decisiontree")
  49. if __name__ == '__main__':
  50. unittest.main()