예제 #1
0
    def test_toolbox_metal_parse_options(self):
        """Test parse_options in toolbox_metal.py."""
        dict_1 = {'data_a': '2mm', 'data_b': '1um'}
        dict_2 = {
            'data_a': '20mm',
            'data_b': '15um',
            'data_c': '4 miles',
            'data_d': '2 mm'
        }

        expected = [[2], [0.001], [20, 0.015, 6437376.0, 2]]

        actual = []
        actual.append(parsing.parse_options(dict_1, 'data_a'))
        actual.append(parsing.parse_options(dict_1, 'data_b'))
        actual.append(
            parsing.parse_options(dict_2, 'data_a,data_b,data_c,data_d',
                                  dict_1))

        for x in range(3):
            self.assertEqual(len(actual[x]), len(expected[x]))
            my_range = len(actual[x])
            for i in range(my_range):
                self.assertAlmostEqualRel(actual[x][i],
                                          expected[x][i],
                                          rel_tol=1e-3)
예제 #2
0
    def parse_options(self, params: dict, param_names: str) -> dict:
        """Extra utility function that can call parse_value on individual
        options. Use self.parse_value to parse only some options from a params
        dictionary.

        Arguments:
            params (dict): Input dict to pull form
            param_names (str): Keys of dictionary to parse and return as a dictionary.
                               Example value: 'x,y,z,cpw_width'

        Returns:
            dict: Dictionary of the keys contained in `param_names` with values that are parsed.
        """
        return parse_options(params, param_names, variable_dict=self.variables)