Пример #1
0
    def test_bad_chars_raises_exception(self):
        '''
        Test that names with incompatible
        characters are rejected when we use the `normalize_identifier`
        function
        '''

        # cannot have strange characters:
        with self.assertRaises(StringIdentifierException):
            o = normalize_identifier('a#b')

        # cannot start with a number
        with self.assertRaises(StringIdentifierException):
            o = normalize_identifier('9a')

        # Can't start or end with the dash or dot.
        # The question mark is just a "generic" out-of-bound character
        chars = ['-', '.', '?']
        for c in chars:
            # cannot start with this char
            test_name = c + 'abc'
            with self.assertRaises(StringIdentifierException):
                o = normalize_identifier(test_name)

            # cannot end with this char
            test_name = 'abc' + c
            with self.assertRaises(StringIdentifierException):
                o = normalize_identifier(test_name)
Пример #2
0
 def value_validator(self, val, set_value=True, allow_null=False):
     try:
         val = api_utils.normalize_identifier(val)
         if set_value:
             self.value = val
     except StringIdentifierException as ex:
         raise AttributeValueError(str(ex))
Пример #3
0
 def convert(self, input_key, user_input, op_dir, staging_dir):
     s = UnrestrictedStringListAttribute(user_input)
     try:
         s = [normalize_identifier(x) for x in s.value]
     except StringIdentifierException as ex:
         raise AttributeValueError(str(ex))
     return {input_key: self.to_string(s)}
Пример #4
0
 def convert(self, input_key, user_input, op_dir, staging_dir):
     s = UnrestrictedStringAttribute(user_input)
     try:
         s = normalize_identifier(s.value)
     except StringIdentifierException as ex:
         raise AttributeValueError(str(ex))
     return {input_key: s}
Пример #5
0
    def test_filename_normalized(self):
        '''
        File names permit leading numbers. Test that the filename normalizer
        function respects this.
        '''
        # check that the more restrictive function raises an exception
        with self.assertRaises(StringIdentifierException):
            o = normalize_identifier('5k.tsv')

        o = normalize_filename('5k.tsv')
        self.assertEqual(o, '5k.tsv')
Пример #6
0
    def __init__(self, id, attribute_dict={}):
        '''
        We require that all `Element` instances be created with an identifier.
        Equality (e.g. in set operations) is checked this identier member

        Other attributes may be added, but this is the only required member.
        '''
        # This is a unique identifer.  One could think of this in the same way
        # they would a sample "name"
        normalized_id = api_utils.normalize_identifier(id)
        self.id = normalized_id

        # we permit arbitrary attributes to be associated with `Element`s
        # They have to be formatted as a dictionary.  Typically, the associated
        # serializer will catch the problem before it reaches here.  But we also
        # guard against it here.
        if type(attribute_dict) == dict:
            self.attributes = attribute_dict
        else:
            raise ValidationError(
                'The attributes must be formatted as a dictionary.')
Пример #7
0
 def value_validator(self, val):
     try:
         val = api_utils.normalize_identifier(val)
         self.value = val
     except api_exceptions.StringIdentifierException as ex:
         raise ValidationError(str(ex))
Пример #8
0
    def test_name_with_space_normalized(self):
        o = normalize_identifier('A name')
        self.assertEqual(o, 'A_name')

        with self.assertRaises(StringIdentifierException):
            o = normalize_identifier('A name?')
Пример #9
0
 def validate_id(self, id):
     normalized_id = normalize_identifier(id)
     return normalized_id