""" Unit tests for the ensemble module """ import os import unittest from binarycpython.utils.functions import ( temp_dir, Capturing, ) from binarycpython.utils.ensemble import ( binaryc_json_serializer, handle_ensemble_string_to_json ) TMP_DIR = temp_dir("tests", "test_ensemble") class test_binaryc_json_serializer(unittest.TestCase): """ Unittests for function binaryc_json_serializer """ def test_not_function(self): with Capturing() as output: self._test_not_function() def _test_not_function(self): """ Test passing an object that doesnt get turned in to a string """ stringo = "hello" output = binaryc_json_serializer(stringo) self.assertTrue(stringo == output) def test_function(self): with Capturing() as output: self._test_function() def _test_function(self): """ Test passing an object that gets turned in to a string: a function """ string_of_function = str(os.path.isfile) output = binaryc_json_serializer(os.path.isfile) self.assertTrue(string_of_function == output) class test_handle_ensemble_string_to_json(unittest.TestCase): """ Unittests for function handle_ensemble_string_to_json """ def test_1(self): with Capturing() as _: self._test_1() def _test_1(self): """ Test passing string representation of a dictionary. """ _ = str(os.path.isfile) input_string = '{"ding": 10, "list_example": [1,2,3]}' output_dict = handle_ensemble_string_to_json(input_string) self.assertTrue(isinstance(output_dict, dict)) self.assertTrue(output_dict["ding"] == 10) self.assertTrue(output_dict["list_example"] == [1, 2, 3]) if __name__ == "__main__": unittest.main()