param_json_test.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Copyright 2019 The FATE Authors. All Rights Reserved.
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import json
  18. import os
  19. import unittest
  20. from federatedml.param.feature_binning_param import FeatureBinningParam
  21. from federatedml.util.param_extract import ParamExtract
  22. home_dir = os.path.split(os.path.realpath(__file__))[0]
  23. class TestParamExtract(unittest.TestCase):
  24. def setUp(self):
  25. self.param = FeatureBinningParam()
  26. json_config_file = home_dir + '/param_feature_binning.json'
  27. self.config_path = json_config_file
  28. with open(json_config_file, 'r', encoding='utf-8') as load_f:
  29. role_config = json.load(load_f)
  30. self.config_json = role_config
  31. # def tearDown(self):
  32. # os.system("rm -r " + self.config_path)
  33. def test_directly_extract(self):
  34. param_obj = FeatureBinningParam()
  35. extractor = ParamExtract()
  36. param_obj = extractor.parse_param_from_config(param_obj, self.config_json)
  37. self.assertTrue(param_obj.method == "quantile")
  38. self.assertTrue(param_obj.transform_param.transform_type == 'bin_num')
  39. if __name__ == '__main__':
  40. unittest.main()