def test_return_false_for_non_string_objects(self):
        # noinspection PyTypeChecker
        self.assertFalse(is_snake_case(None))

        # noinspection PyTypeChecker
        self.assertFalse(is_snake_case(False))

        # noinspection PyTypeChecker
        self.assertFalse(is_snake_case(0))

        # noinspection PyTypeChecker
        self.assertFalse(is_snake_case([]))

        # noinspection PyTypeChecker
        self.assertFalse(is_snake_case({'a': 1}))
예제 #2
0
def generate_aliases(strings: List[str]) -> Dict[str, str]:
    """
    generate a set of aliases from the given set of strings.



    :param strings:
    :return:
    """
    result = {}
    for option in strings:
        if string_utils.is_camel_case(option):
            # fetch the first an all the uppercase characters to generate the alias
            alias: str = option[0] + ''.join(filter(lambda x: x.isupper(), option))
        elif string_utils.is_snake_case(option, "_"):
            # TODO implement
            raise NotImplementedError()
        elif option.islower() and re.match(r"^[a-z0-9]+$", option):
            # ok maybe it's camel case of snake case but it contains only one word (e.g., run), HENCE
            # we need to handle words like "algorithm" or "run" which are special case
            # of camel case (they do not have upper letters)
            alias: str = option.lower()[0]
        else:
            raise ValueError(f"option \"{option}\" is not neither camelcase nor snakecase!")
        alias = alias.lower()
        result[option] = alias
    return result
 def test_string_cannot_contain_bad_signs(self):
     self.assertFalse(is_snake_case('1_no_snake'))
     self.assertFalse(is_snake_case('^_no_snake'))
     self.assertFalse(is_snake_case('@_no_snake'))
     self.assertFalse(is_snake_case('%_no_snake'))
     self.assertFalse(is_snake_case('no_snake#'))
     self.assertFalse(is_snake_case('no_!'))
     self.assertFalse(is_snake_case('!no_'))
     self.assertFalse(is_snake_case('.no_'))
예제 #4
0
def to_snake_case(s, separator='_'):
    if not su.is_string(s):
        return s
    if not su.is_full_string(s):
        return s
    if su.is_snake_case(s, separator=separator):
        return s
    return re.sub('[^a-z0-9]+', separator, s.strip().lower()).strip(separator)
예제 #5
0
def consistently_snake_case(row_values):
    fired = True
    snake_case_seen = False
    for value in row_values:
        if ' ' in unidecode(value).strip():
            fired = False
            break
        if string_utils.is_snake_case(
                unidecode(value).strip().lower()) == False:
            if unidecode(value).strip().isalpha() == False:
                fired = False
                break
        else:
            snake_case_seen = True

    if snake_case_seen == False:
        fired = False
    return fired
예제 #6
0
def name_rule(repo, config):
    name = repo['full_name'].replace('HISC/', '')
    repo['name_compliance'] = string_utils.is_snake_case(name)
    return repo
 def test_should_consider_custom_separator(self):
     s = 'snake-string-with-dashes'
     self.assertFalse(is_snake_case(s))
     self.assertTrue(is_snake_case(s, separator='-'))
 def test_should_accept_valid_snake_strings(self):
     self.assertTrue(is_snake_case('HELLO_WORLD'))
     self.assertTrue(is_snake_case('Hello_World'))
     self.assertTrue(is_snake_case('_hello_world'))
     self.assertTrue(is_snake_case('hello_world_'))
     self.assertTrue(is_snake_case('hello_world'))
     self.assertTrue(is_snake_case('_hello_'))
     self.assertTrue(is_snake_case('_hello__'))
     self.assertTrue(is_snake_case('__hello_'))
     self.assertTrue(is_snake_case('a_'))
     self.assertTrue(is_snake_case('_b'))
     self.assertTrue(is_snake_case('a_b_c_d_e'))
     self.assertTrue(is_snake_case('snake_case_string'))
     self.assertTrue(is_snake_case('snake_2'))
     self.assertTrue(is_snake_case('a_snake_string_4_you'))
 def test_string_cannot_contain_only_underscores(self):
     self.assertFalse(is_snake_case('_'))
     self.assertFalse(is_snake_case('__'))
     self.assertFalse(is_snake_case('___'))
     self.assertFalse(is_snake_case('____________________'))
 def test_string_cannot_be_all_uppercase(self):
     self.assertFalse(is_snake_case('HELLO'))
 def test_string_cannot_be_camel_case(self):
     self.assertFalse(is_snake_case('Banana'))
 def test_string_cannot_be_lowercase_letters_only(self):
     self.assertFalse(is_snake_case('lowercaseonly'))
 def test_string_cannot_be_blank(self):
     self.assertFalse(is_snake_case(''))
     self.assertFalse(is_snake_case(' '))
예제 #14
0
def snake_case_to_capword(base):
    if not string_utils.is_snake_case(base) or base.isupper():
        base = "".join(c.upper() if i == 0 else c for i, c in enumerate(base))
        return base

    return string_utils.snake_case_to_camel(base).title()