示例#1
0
    def test__get_field_names(self):
        from biocrnpyler import Parameter

        with self.assertRaises(AssertionError):
            Parameter._get_field_names(field_names=None,
                                       accepted_field_names=None)
        with self.assertRaises(AssertionError):
            Parameter._get_field_names(field_names={}, accepted_field_names={})

        accepted_field_names = {
            'mechanism': ['mechanism', 'mechanism_id'],
            'param_name':
            ["parameter_name", "parameter", "param", "param_name"],
            'part_id': ['part_id', 'part'],
            'param_val': ["val", "value", "param_val", "parameter_value"]
        }

        ret_dict = Parameter._get_field_names(
            field_names=[''], accepted_field_names=accepted_field_names)
        self.assertEqual(accepted_field_names.keys(), ret_dict.keys())

        field_names = ['part_id']

        with self.assertWarns(Warning):
            Parameter._get_field_names(field_names, accepted_field_names)

        accepted_field_names = {
            'dummy': ['dumb', 'dumber'],
        }

        with self.assertWarns(Warning):
            Parameter._get_field_names(field_names, accepted_field_names)
示例#2
0
    def test__get_field_names(self):
        test_accepted_field_names = {
            'mechanism': ['mechanism', 'mechanism_id']
        }
        valid_field_names = ['part_id']

        # test None as field_names
        with self.assertRaisesRegexp(ValueError,
                                     'field_names must be a list of strings'):
            Parameter._get_field_names(
                field_names=None,
                accepted_field_names=test_accepted_field_names)
        # test invalid field_names type
        with self.assertRaisesRegexp(ValueError,
                                     'field_names must be a list of strings'):
            Parameter._get_field_names(
                field_names={}, accepted_field_names=test_accepted_field_names)
        # test empty field_names list
        with self.assertRaisesRegexp(ValueError,
                                     'field_names cannot be empty list!'):
            Parameter._get_field_names(
                field_names=[], accepted_field_names=test_accepted_field_names)

        # test None as accepted_field_names
        with self.assertRaisesRegexp(
                ValueError, 'accepted_field_names must be a dictionary'):
            Parameter._get_field_names(field_names=valid_field_names,
                                       accepted_field_names=None)
        # test invalid accepted_field_names type
        with self.assertRaisesRegexp(
                ValueError, 'accepted_field_names must be a dictionary'):
            Parameter._get_field_names(field_names=valid_field_names,
                                       accepted_field_names=[])
        # test empty field_names list
        with self.assertRaisesRegexp(
                ValueError, 'accepted_field_names cannot be empty dictionary'):
            Parameter._get_field_names(field_names=valid_field_names,
                                       accepted_field_names={})

        accepted_field_names = {
            'mechanism': ['mechanism', 'mechanism_id'],
            'param_name':
            ["parameter_name", "parameter", "param", "param_name"],
            'part_id': ['part_id', 'part'],
            'param_val': ["val", "value", "param_val", "parameter_value"]
        }

        ret_dict = Parameter._get_field_names(
            field_names=[''], accepted_field_names=accepted_field_names)
        self.assertEqual(accepted_field_names.keys(), ret_dict.keys())

        with self.assertWarns(Warning):
            Parameter._get_field_names(valid_field_names, accepted_field_names)

        accepted_field_names = {
            'dummy': ['dumb', 'dumber'],
        }

        with self.assertWarns(Warning):
            Parameter._get_field_names(valid_field_names, accepted_field_names)